From 7a976ac3913243c9f6b6707c88a36c6cdf05f610 Mon Sep 17 00:00:00 2001 From: Ariful Alam Date: Mon, 19 Sep 2022 22:56:08 +0600 Subject: [PATCH] Test admin profile route --- tests/Feature/Admin/ProfileTest.php | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/Feature/Admin/ProfileTest.php diff --git a/tests/Feature/Admin/ProfileTest.php b/tests/Feature/Admin/ProfileTest.php new file mode 100644 index 0000000..8dec11f --- /dev/null +++ b/tests/Feature/Admin/ProfileTest.php @@ -0,0 +1,70 @@ +routes = [ + 'me' => '/api/admin/profile', + ]; + + $this->admin = Admin::factory()->create(); + + Sanctum::actingAs($this->admin, [], 'admin'); + } + + /** + * An admin can get his profile. + * + * @return void + */ + public function testAnAdminCanGetHisProfile() + { + $response = $this + ->json('GET', $this->routes['me']) + ->assertStatus(Response::HTTP_OK) + ->assertJsonStructure([ + 'id', + 'name', + 'email', + 'avatar_url', + 'created_at', + ]) + ->assertJson([ + 'id' => $this->admin->id, + 'email' => $this->admin->email, + 'name' => $this->admin->name, + 'avatar_url' => null, + ]); + + $this->assertInstanceOf(AdminResource::class, $response->getOriginalContent()); + } +}