From eaaefc1f1b39731b694f68356eceec6646ef0bad Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:32:20 +0100 Subject: [PATCH] Update php tests --- .../Api/v1/Controllers/Auth/UserControllerTest.php | 13 ++++++++----- tests/Api/v1/Controllers/IconControllerTest.php | 2 +- tests/Feature/Http/Auth/LoginTest.php | 9 ++++----- tests/Feature/Http/Auth/UserControllerTest.php | 13 ++++++++----- .../Http/Auth/WebAuthnLoginControllerTest.php | 10 ++-------- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/tests/Api/v1/Controllers/Auth/UserControllerTest.php b/tests/Api/v1/Controllers/Auth/UserControllerTest.php index 39436128..b1260b30 100644 --- a/tests/Api/v1/Controllers/Auth/UserControllerTest.php +++ b/tests/Api/v1/Controllers/Auth/UserControllerTest.php @@ -43,11 +43,14 @@ class UserControllerTest extends FeatureTestCase $response = $this->actingAs($this->user, 'api-guard') ->json('GET', '/api/v1/user') ->assertOk() - ->assertExactJson([ - 'name' => $this->user->name, - 'id' => $this->user->id, - 'email' => $this->user->email, - 'is_admin' => $this->user->is_admin, + ->assertJsonFragment([ + 'name' => $this->user->name, + 'id' => $this->user->id, + 'email' => $this->user->email, + 'is_admin' => $this->user->is_admin, + ]) + ->assertJsonStructure([ + 'preferences', ]); } diff --git a/tests/Api/v1/Controllers/IconControllerTest.php b/tests/Api/v1/Controllers/IconControllerTest.php index 27fcabee..836ebd98 100644 --- a/tests/Api/v1/Controllers/IconControllerTest.php +++ b/tests/Api/v1/Controllers/IconControllerTest.php @@ -63,7 +63,7 @@ class IconControllerTest extends FeatureTestCase { $response = $this->actingAs($this->user, 'api-guard') ->json('POST', '/api/v1/icons/default', [ - 'service' => 'abode', + 'service' => 'dropbox', ]) ->assertStatus(201) ->assertJsonStructure([ diff --git a/tests/Feature/Http/Auth/LoginTest.php b/tests/Feature/Http/Auth/LoginTest.php index 5f054847..4c301246 100644 --- a/tests/Feature/Http/Auth/LoginTest.php +++ b/tests/Feature/Http/Auth/LoginTest.php @@ -91,7 +91,7 @@ class LoginTest extends FeatureTestCase * * @covers \App\Http\Middleware\SkipIfAuthenticated */ - public function test_user_login_already_authenticated_returns_success() + public function test_user_login_already_authenticated_is_rejected() { $response = $this->json('POST', '/user/login', [ 'email' => $this->user->email, @@ -103,10 +103,9 @@ class LoginTest extends FeatureTestCase 'email' => $this->user->email, 'password' => self::PASSWORD, ]) - ->assertStatus(200) - ->assertJson([ - 'message' => 'authenticated', - 'name' => $this->user->name, + ->assertStatus(400) + ->assertJsonStructure([ + 'message', ]); } diff --git a/tests/Feature/Http/Auth/UserControllerTest.php b/tests/Feature/Http/Auth/UserControllerTest.php index df88e0a4..37ca78f3 100644 --- a/tests/Feature/Http/Auth/UserControllerTest.php +++ b/tests/Feature/Http/Auth/UserControllerTest.php @@ -53,11 +53,14 @@ class UserControllerTest extends FeatureTestCase 'password' => self::PASSWORD, ]) ->assertOk() - ->assertExactJson([ + ->assertJsonFragment([ 'name' => self::NEW_USERNAME, 'id' => $this->user->id, 'email' => self::NEW_EMAIL, 'is_admin' => false, + ]) + ->assertJsonStructure([ + 'preferences', ]); $this->assertDatabaseHas('users', [ @@ -80,7 +83,7 @@ class UserControllerTest extends FeatureTestCase 'password' => self::PASSWORD, ]) ->assertOk() - ->assertExactJson([ + ->assertJsonFragment([ 'name' => self::NEW_USERNAME, 'id' => $this->user->id, 'email' => $this->user->email, @@ -107,7 +110,7 @@ class UserControllerTest extends FeatureTestCase 'password' => self::PASSWORD, ]) ->assertOk() - ->assertExactJson([ + ->assertJsonFragment([ 'name' => $this->user->name, 'id' => $this->user->id, 'email' => self::NEW_EMAIL, @@ -134,7 +137,7 @@ class UserControllerTest extends FeatureTestCase 'password' => self::PASSWORD, ]) ->assertOk() - ->assertExactJson([ + ->assertJsonFragment([ 'name' => self::NEW_USERNAME, 'id' => $this->user->id, 'email' => self::NEW_EMAIL, @@ -166,7 +169,7 @@ class UserControllerTest extends FeatureTestCase 'password' => self::PASSWORD, ]) ->assertOk() - ->assertExactJson([ + ->assertJsonFragment([ 'name' => $name, 'id' => $this->user->id, 'email' => $email, diff --git a/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php b/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php index 847b19d6..d2c5d1a6 100644 --- a/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php +++ b/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php @@ -205,7 +205,7 @@ class WebAuthnLoginControllerTest extends FeatureTestCase * * @covers \App\Http\Middleware\SkipIfAuthenticated */ - public function test_webauthn_login_already_authenticated_returns_success() + public function test_webauthn_login_already_authenticated_is_rejected() { $this->user = User::factory()->create(['email' => self::EMAIL]); @@ -238,15 +238,9 @@ class WebAuthnLoginControllerTest extends FeatureTestCase ->assertOk(); $this->json('POST', '/webauthn/login', self::ASSERTION_RESPONSE) - ->assertOk() - ->assertJsonFragment([ - 'message' => 'authenticated', - 'name' => $this->user->name, - ]) + ->assertStatus(400) ->assertJsonStructure([ 'message', - 'name', - 'preferences', ]); }