mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-13 23:38:32 +02:00
Fix and complete tests
This commit is contained in:
@ -12,9 +12,6 @@ class UserControllerTest extends FeatureTestCase
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
private const NEW_USERNAME = 'Jane DOE';
|
||||
private const NEW_EMAIL = 'janedoe@example.org';
|
||||
private const PASSWORD = 'password';
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -32,11 +29,12 @@ class UserControllerTest extends FeatureTestCase
|
||||
*/
|
||||
public function test_show_existing_user_when_authenticated_returns_success()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
$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,
|
||||
]);
|
||||
}
|
||||
@ -62,83 +60,14 @@ class UserControllerTest extends FeatureTestCase
|
||||
{
|
||||
User::destroy($this->user->id);
|
||||
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
$response = $this->actingAs($this->user, 'api-guard')
|
||||
->json('GET', '/api/v1/user')
|
||||
->assertOk()
|
||||
->assertExactJson([
|
||||
'name' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_update_user_returns_success()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('PUT', '/api/v1/user', [
|
||||
'name' => self::NEW_USERNAME,
|
||||
'email' => self::NEW_EMAIL,
|
||||
'password' => self::PASSWORD,
|
||||
])
|
||||
->assertOk()
|
||||
->assertExactJson([
|
||||
'name' => self::NEW_USERNAME,
|
||||
'email' => self::NEW_EMAIL,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_update_user_in_demo_mode_returns_unchanged_user()
|
||||
{
|
||||
$settingService = resolve('App\Services\SettingService');
|
||||
$settingService->set('isDemoApp', true);
|
||||
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('PUT', '/api/v1/user', [
|
||||
'name' => self::NEW_USERNAME,
|
||||
'email' => self::NEW_EMAIL,
|
||||
'password' => self::PASSWORD,
|
||||
])
|
||||
->assertOk()
|
||||
->assertExactJson([
|
||||
'name' => $this->user->name,
|
||||
'name' => $this->user->name,
|
||||
'id' => $this->user->id,
|
||||
'email' => $this->user->email,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_update_user_passing_wrong_password_returns_bad_request()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('PUT', '/api/v1/user', [
|
||||
'name' => self::NEW_USERNAME,
|
||||
'email' => self::NEW_EMAIL,
|
||||
'password' => 'wrongPassword',
|
||||
])
|
||||
->assertStatus(400);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function test_update_user_with_invalid_data_returns_validation_error()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('PUT', '/api/v1/user', [
|
||||
'name' => '',
|
||||
'email' => '',
|
||||
'password' => self::PASSWORD,
|
||||
])
|
||||
->assertStatus(422);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user