Fix user controller unit tests

This commit is contained in:
Bubka 2020-01-14 11:50:20 +01:00
parent 9632641702
commit 99a2fc8641

View File

@ -25,11 +25,11 @@ public function setUp(): void
/**
* test User creation via API
* test creation of another user via API
*
* @test
*/
public function testUserCreation()
public function testMoreThanOneUserCreation()
{
$response = $this->json('POST', '/api/register', [
'name' => 'testCreate',
@ -38,10 +38,7 @@ public function testUserCreation()
'password_confirmation' => 'test',
]);
$response->assertStatus(200)
->assertJsonStructure([
'success' => ['token', 'name']
]);
$response->assertStatus(400);
}
@ -88,6 +85,7 @@ public function testUserCreationWithInvalidData()
*/
public function testUserLogin()
{
$response = $this->json('POST', '/api/login', [
'email' => $this->user->email,
'password' => 'password'
@ -95,7 +93,7 @@ public function testUserLogin()
$response->assertStatus(200)
->assertJsonStructure([
'success' => ['token']
'message' => ['token']
]);
}
@ -130,7 +128,7 @@ public function testUserLoginWithInvalidCredential()
$response->assertStatus(401)
->assertJson([
'error' => 'Unauthorised'
'message' => 'unauthorised'
]);
}
@ -154,7 +152,7 @@ public function testUserLogout()
$response = $this->json('POST', '/api/logout', [], $headers)
->assertStatus(200)
->assertJson([
'success' => 'signed out',
'message' => 'signed out',
]);
}
@ -166,10 +164,37 @@ public function testUserLogout()
*/
public function testGetUserDetails()
{
$response = $this->actingAs($this->user, 'api')
$user = User::find(1);
$response = $this->actingAs($user, 'api')
->json('GET', '/api/user')
->assertStatus(200)
->assertJsonStructure(['id', 'name', 'email']);
}
/**
* test User creation via API
*
* @test
*/
public function testUserCreation()
{
// we delete the existing user
User::destroy(1);
$response = $this->json('POST', '/api/register', [
'name' => 'newUser',
'email' => 'newUser@example.org',
'password' => 'password',
'password_confirmation' => 'password',
]);
$response->assertStatus(200)
->assertJsonStructure([
'message' => ['token', 'name']
]);
}
}