mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-20 03:38:06 +02:00
Fix user controller unit tests
This commit is contained in:
parent
9632641702
commit
99a2fc8641
@ -25,11 +25,11 @@ class UserTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test User creation via API
|
* test creation of another user via API
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function testUserCreation()
|
public function testMoreThanOneUserCreation()
|
||||||
{
|
{
|
||||||
$response = $this->json('POST', '/api/register', [
|
$response = $this->json('POST', '/api/register', [
|
||||||
'name' => 'testCreate',
|
'name' => 'testCreate',
|
||||||
@ -38,10 +38,7 @@ class UserTest extends TestCase
|
|||||||
'password_confirmation' => 'test',
|
'password_confirmation' => 'test',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200)
|
$response->assertStatus(400);
|
||||||
->assertJsonStructure([
|
|
||||||
'success' => ['token', 'name']
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -88,6 +85,7 @@ class UserTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUserLogin()
|
public function testUserLogin()
|
||||||
{
|
{
|
||||||
|
|
||||||
$response = $this->json('POST', '/api/login', [
|
$response = $this->json('POST', '/api/login', [
|
||||||
'email' => $this->user->email,
|
'email' => $this->user->email,
|
||||||
'password' => 'password'
|
'password' => 'password'
|
||||||
@ -95,7 +93,7 @@ class UserTest extends TestCase
|
|||||||
|
|
||||||
$response->assertStatus(200)
|
$response->assertStatus(200)
|
||||||
->assertJsonStructure([
|
->assertJsonStructure([
|
||||||
'success' => ['token']
|
'message' => ['token']
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +128,7 @@ class UserTest extends TestCase
|
|||||||
|
|
||||||
$response->assertStatus(401)
|
$response->assertStatus(401)
|
||||||
->assertJson([
|
->assertJson([
|
||||||
'error' => 'Unauthorised'
|
'message' => 'unauthorised'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +152,7 @@ class UserTest extends TestCase
|
|||||||
$response = $this->json('POST', '/api/logout', [], $headers)
|
$response = $this->json('POST', '/api/logout', [], $headers)
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJson([
|
->assertJson([
|
||||||
'success' => 'signed out',
|
'message' => 'signed out',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,10 +164,37 @@ class UserTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetUserDetails()
|
public function testGetUserDetails()
|
||||||
{
|
{
|
||||||
$response = $this->actingAs($this->user, 'api')
|
$user = User::find(1);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user, 'api')
|
||||||
->json('GET', '/api/user')
|
->json('GET', '/api/user')
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertJsonStructure(['id', 'name', 'email']);
|
->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']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user