Browse Source

Update php tests

Bubka 1 year ago
parent
commit
eaaefc1f1b

+ 8 - 5
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',
             ]);
     }
 

+ 1 - 1
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([

+ 4 - 5
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',
             ]);
     }
 

+ 8 - 5
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,

+ 2 - 8
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',
             ]);
     }