From c4adfeff195d7138d883c405adcd95a7bb603297 Mon Sep 17 00:00:00 2001 From: Hasin Hayder Date: Sat, 21 May 2022 22:05:18 +0600 Subject: [PATCH] New User Test --- tests/Feature/NewUserTest.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/Feature/NewUserTest.php b/tests/Feature/NewUserTest.php index 3a1cb67..b9ff5b1 100644 --- a/tests/Feature/NewUserTest.php +++ b/tests/Feature/NewUserTest.php @@ -82,7 +82,7 @@ class NewUserTest extends TestCase { ); } - public function test_new_user_name_update() { + public function test_new_user_name_update_with_user_token() { $response = $this->postJson('/api/login', [ 'email' => 'test@test.com', @@ -106,7 +106,31 @@ class NewUserTest extends TestCase { ); } - public function test_new_user_destroy_as_user() { + public function test_new_user_name_update_with_admin_token() { + + $response = $this->postJson('/api/login', [ + 'email' => 'admin@hydra.project', + 'password' => 'hydra' + ]); + + $data = json_decode($response->getContent()); + $this->token = $data->token; + $this->user_id = $data->id; + + $response = $this->withHeader('Authorization', 'Bearer ' . $this->token) + ->put("/api/users/{$this->user_id}", [ + 'name' => 'Mini Me', + ]); + + $response + ->assertJson( + fn (AssertableJson $json) => + $json->where('name', "Mini Me") + ->etc() + ); + } + + public function test_new_user_destroy_as_user_should_fail() { $response = $this->postJson('/api/login', [ 'email' => 'test@test.com',