diff --git a/tests/Unit/Profile/AccountTest.php b/tests/Unit/Profile/AccountTest.php new file mode 100644 index 00000000..d68e20fd --- /dev/null +++ b/tests/Unit/Profile/AccountTest.php @@ -0,0 +1,84 @@ +user = factory(User::class)->create(); + } + + + /** + * test Get user infos via API + * + * @test + */ + public function testGetUserDetails() + { + $user = User::find(1); + + $response = $this->actingAs($user, 'api') + ->json('GET', '/api/profile/account') + ->assertStatus(200) + ->assertJsonStructure(['name', 'email']); + } + + + /** + * test User update with wrong current password via API + * + * @test + */ + public function testUserUpdateWithWrongCurrentPassword() + { + $user = User::find(1); + + $response = $this->actingAs($user, 'api') + ->json('PATCH', '/api/profile/account', [ + 'name' => 'userUpdated', + 'email' => 'userUpdated@example.org', + 'password' => 'wrongPassword', + ]); + + $response->assertStatus(400) + ->assertJsonStructure(['message']); + } + + + /** + * test User update via API + * + * @test + */ + public function testUserUpdate() + { + $user = User::find(1); + + $response = $this->actingAs($user, 'api') + ->json('PATCH', '/api/profile/account', [ + 'name' => 'userUpdated', + 'email' => 'userUpdated@example.org', + 'password' => 'password', + ]); + + $response->assertStatus(200) + ->assertJsonFragment([ + 'username' => 'userUpdated' + ]); + } + +} \ No newline at end of file diff --git a/tests/Unit/Profile/PasswordTest.php b/tests/Unit/Profile/PasswordTest.php new file mode 100644 index 00000000..f30df26a --- /dev/null +++ b/tests/Unit/Profile/PasswordTest.php @@ -0,0 +1,67 @@ +user = factory(User::class)->create(); + } + + + /** + * test User password update with wrong current password via API + * + * @test + */ + public function testPasswordUpdateWithWrongCurrentPassword() + { + $response = $this->actingAs($this->user, 'api') + ->json('PATCH', '/api/profile/password', [ + 'currentPassword' => 'wrongPassword', + 'password' => 'passwordUpdated', + 'password_confirmation' => 'passwordUpdated', + ]); + + $response->assertStatus(400) + ->assertJsonStructure(['message']); + } + + + /** + * test User password update via API + * + * @test + */ + public function testPasswordUpdate() + { + $response = $this->actingAs($this->user, 'api') + ->json('PATCH', '/api/profile/password', [ + 'currentPassword' => 'password', + 'password' => 'passwordUpdated', + 'password_confirmation' => 'passwordUpdated', + ]); + + $response->assertStatus(200) + ->assertJsonStructure(['message']); + + $this->user->refresh(); + + $this->assertTrue(Hash::check('passwordUpdated', $this->user->password)); + } + +} diff --git a/tests/Unit/SettingTest.php b/tests/Unit/Profile/SettingTest.php similarity index 92% rename from tests/Unit/SettingTest.php rename to tests/Unit/Profile/SettingTest.php index b44a33b0..c0dab335 100644 --- a/tests/Unit/SettingTest.php +++ b/tests/Unit/Profile/SettingTest.php @@ -1,6 +1,6 @@ actingAs($this->user, 'api') - ->json('POST', '/api/settings', [ + ->json('POST', '/api/profile/settings', [ 'setting_1' => 'value_1', 'setting_2' => 'value_2', ]) @@ -56,7 +56,7 @@ class SettingTest extends TestCase option(['setting_2' => 'value_2']); $response = $this->actingAs($this->user, 'api') - ->json('GET', '/api/settings') + ->json('GET', '/api/profile/settings') ->assertStatus(200) ->assertJson([ 'settings' => [ diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index c71edb64..4c5a114e 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -179,112 +179,6 @@ class UserTest extends TestCase } - /** - * test User logout via API - * - * @test - */ - public function testGetUserDetails() - { - $user = User::find(1); - - $response = $this->actingAs($user, 'api') - ->json('GET', '/api/user') - ->assertStatus(200) - ->assertJsonStructure(['name', 'email']); - } - - - /** - * test User update with wrong current password via API - * - * @test - */ - public function testUserUpdateWithWrongCurrentPassword() - { - $user = User::find(1); - - $response = $this->actingAs($user, 'api') - ->json('PATCH', '/api/user', [ - 'name' => 'userUpdated', - 'email' => 'userUpdated@example.org', - 'password' => 'wrongPassword', - ]); - - $response->assertStatus(400) - ->assertJsonStructure(['message']); - } - - - /** - * test User update via API - * - * @test - */ - public function testUserUpdate() - { - $user = User::find(1); - - $response = $this->actingAs($user, 'api') - ->json('PATCH', '/api/user', [ - 'name' => 'userUpdated', - 'email' => 'userUpdated@example.org', - 'password' => 'password', - ]); - - $response->assertStatus(200) - ->assertJsonFragment([ - 'username' => 'userUpdated' - ]); - } - - - /** - * test User password update with wrong current password via API - * - * @test - */ - public function testUserPasswordUpdateWithWrongCurrentPassword() - { - $user = User::find(1); - - $response = $this->actingAs($user, 'api') - ->json('PATCH', '/api/password', [ - 'currentPassword' => 'wrongPassword', - 'password' => 'passwordUpdated', - 'password_confirmation' => 'passwordUpdated', - ]); - - $response->assertStatus(400) - ->assertJsonStructure(['message']); - } - - - /** - * test User password update via API - * - * @test - */ - public function testUserPasswordUpdate() - { - $user = User::find(1); - - $response = $this->actingAs($user, 'api') - ->json('PATCH', '/api/password', [ - 'currentPassword' => 'password', - 'password' => 'passwordUpdated', - 'password_confirmation' => 'passwordUpdated', - ]); - - $response->assertStatus(200) - ->assertJsonStructure(['message']); - - $user->refresh(); - - $this->assertTrue(Hash::check('passwordUpdated', $user->password)); - } - - /** * test User creation via API *