login(); $this->patch('/api/me/details/auth', [ 'email' => 'foo@example.com', 'username' => 'john.doe', 'password' => '12345678', 'password_confirmation' => '12345678', ])->assertOk() ->assertJsonFragment(['email' => 'foo@example.com', 'username' => 'john.doe']); $this->assertTrue(password_verify('12345678', $user->fresh()->password)); }); test('test user can update only email and leave other fields unchanged', function () { $user = $this->login(); $this->patch('/api/me/details/auth', [ 'email' => 'foo@example.com', ])->assertOk() ->assertJsonFragment(['email' => 'foo@example.com']); $this->assertEquals($user->username, $user->fresh()->username); $this->assertEquals($user->password, $user->fresh()->password); }); test('test email field is required', function () { $this->login(); $this->patch('/api/me/details/auth') ->assertJsonValidationErrors('email'); }); test('test email field must be valid email', function () { $this->login(); $this->patch('/api/me/details/auth', [ 'email' => 'invalid email', ])->assertJsonValidationErrors('email'); }); test('test email field must be unique', function () { $this->login(); UserFactory::email('john.doe@test.com')->create(); $this->patch('/api/me/details/auth', [ 'email' => 'john.doe@test.com', ])->assertJsonValidationErrors('email'); }); test('test username field must be unique', function () { $this->login(); UserFactory::withCredentials('john.doe', '123123')->create(); $this->patch('/api/me/details/auth', [ 'email' => 'john.doe@test.com', 'username' => 'john.doe', ])->assertJsonValidationErrors('username'); });