mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-19 11:26:48 +02:00
Refactore Profile tests
This commit is contained in:
parent
7090cd8b33
commit
330fb68fc1
84
tests/Unit/Profile/AccountTest.php
Normal file
84
tests/Unit/Profile/AccountTest.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Profile;
|
||||
|
||||
use App\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AccountTest extends TestCase
|
||||
{
|
||||
/** @var \App\User */
|
||||
protected $user;
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = factory(User::class)->create();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test Get user infos via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testGetUserDetails()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('GET', '/api/profile/account')
|
||||
->assertStatus(200)
|
||||
->assertJsonStructure(['name', 'email']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User update with wrong current password via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUserUpdateWithWrongCurrentPassword()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('PATCH', '/api/profile/account', [
|
||||
'name' => 'userUpdated',
|
||||
'email' => 'userUpdated@example.org',
|
||||
'password' => 'wrongPassword',
|
||||
]);
|
||||
|
||||
$response->assertStatus(400)
|
||||
->assertJsonStructure(['message']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User update via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUserUpdate()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('PATCH', '/api/profile/account', [
|
||||
'name' => 'userUpdated',
|
||||
'email' => 'userUpdated@example.org',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'username' => 'userUpdated'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
67
tests/Unit/Profile/PasswordTest.php
Normal file
67
tests/Unit/Profile/PasswordTest.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Profile;
|
||||
|
||||
use App\User;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class PasswordTest extends TestCase
|
||||
{
|
||||
/** @var \App\User */
|
||||
protected $user;
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = factory(User::class)->create();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User password update with wrong current password via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testPasswordUpdateWithWrongCurrentPassword()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('PATCH', '/api/profile/password', [
|
||||
'currentPassword' => 'wrongPassword',
|
||||
'password' => 'passwordUpdated',
|
||||
'password_confirmation' => 'passwordUpdated',
|
||||
]);
|
||||
|
||||
$response->assertStatus(400)
|
||||
->assertJsonStructure(['message']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User password update via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testPasswordUpdate()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('PATCH', '/api/profile/password', [
|
||||
'currentPassword' => 'password',
|
||||
'password' => 'passwordUpdated',
|
||||
'password_confirmation' => 'passwordUpdated',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonStructure(['message']);
|
||||
|
||||
$this->user->refresh();
|
||||
|
||||
$this->assertTrue(Hash::check('passwordUpdated', $this->user->password));
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
namespace Tests\Unit\Profile;
|
||||
|
||||
use App\User;
|
||||
use Tests\TestCase;
|
||||
@ -30,7 +30,7 @@ class SettingTest extends TestCase
|
||||
public function testSettingsStorage()
|
||||
{
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('POST', '/api/settings', [
|
||||
->json('POST', '/api/profile/settings', [
|
||||
'setting_1' => 'value_1',
|
||||
'setting_2' => 'value_2',
|
||||
])
|
||||
@ -56,7 +56,7 @@ class SettingTest extends TestCase
|
||||
option(['setting_2' => 'value_2']);
|
||||
|
||||
$response = $this->actingAs($this->user, 'api')
|
||||
->json('GET', '/api/settings')
|
||||
->json('GET', '/api/profile/settings')
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
'settings' => [
|
@ -179,112 +179,6 @@ class UserTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User logout via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testGetUserDetails()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('GET', '/api/user')
|
||||
->assertStatus(200)
|
||||
->assertJsonStructure(['name', 'email']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User update with wrong current password via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUserUpdateWithWrongCurrentPassword()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('PATCH', '/api/user', [
|
||||
'name' => 'userUpdated',
|
||||
'email' => 'userUpdated@example.org',
|
||||
'password' => 'wrongPassword',
|
||||
]);
|
||||
|
||||
$response->assertStatus(400)
|
||||
->assertJsonStructure(['message']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User update via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUserUpdate()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('PATCH', '/api/user', [
|
||||
'name' => 'userUpdated',
|
||||
'email' => 'userUpdated@example.org',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'username' => 'userUpdated'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User password update with wrong current password via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUserPasswordUpdateWithWrongCurrentPassword()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('PATCH', '/api/password', [
|
||||
'currentPassword' => 'wrongPassword',
|
||||
'password' => 'passwordUpdated',
|
||||
'password_confirmation' => 'passwordUpdated',
|
||||
]);
|
||||
|
||||
$response->assertStatus(400)
|
||||
->assertJsonStructure(['message']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User password update via API
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testUserPasswordUpdate()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('PATCH', '/api/password', [
|
||||
'currentPassword' => 'password',
|
||||
'password' => 'passwordUpdated',
|
||||
'password_confirmation' => 'passwordUpdated',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonStructure(['message']);
|
||||
|
||||
$user->refresh();
|
||||
|
||||
$this->assertTrue(Hash::check('passwordUpdated', $user->password));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test User creation via API
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user