Fix and complete unit tests

This commit is contained in:
Bubka
2020-01-10 13:43:36 +01:00
parent e5f040e066
commit 35a6b0d87c
5 changed files with 190 additions and 10 deletions

View File

@ -35,6 +35,7 @@ class UserTest extends TestCase
'name' => 'testCreate',
'email' => 'testCreate@example.org',
'password' => 'test',
'password_confirmation' => 'test',
]);
$response->assertStatus(200)
@ -44,6 +45,42 @@ class UserTest extends TestCase
}
/**
* test User creation with missing values via API
*
* @test
*/
public function testUserCreationWithMissingValues()
{
$response = $this->json('POST', '/api/register', [
'name' => '',
'email' => '',
'password' => '',
'password_confirmation' => '',
]);
$response->assertStatus(400);
}
/**
* test User creation with invalid values via API
*
* @test
*/
public function testUserCreationWithInvalidData()
{
$response = $this->json('POST', '/api/register', [
'name' => 'testInvalid',
'email' => 'email',
'password' => 'test',
'password_confirmation' => 'tset',
]);
$response->assertStatus(400);
}
/**
* test User login via API
*
@ -63,6 +100,41 @@ class UserTest extends TestCase
}
/**
* test User login with missing values via API
*
* @test
*/
public function testUserLoginWithMissingValues()
{
$response = $this->json('POST', '/api/login', [
'email' => '',
'password' => ''
]);
$response->assertStatus(400);
}
/**
* test User login with invalid credentials via API
*
* @test
*/
public function testUserLoginWithInvalidCredential()
{
$response = $this->json('POST', '/api/login', [
'email' => $this->user->email,
'password' => 'badPassword'
]);
$response->assertStatus(401)
->assertJson([
'error' => 'Unauthorised'
]);
}
/**
* test User logout via API
*