2FAuth/tests/Api/v1/Controllers/Auth/PasswordControllerTest.php

81 lines
1.9 KiB
PHP
Raw Normal View History

2021-11-22 01:09:54 +01:00
<?php
namespace Tests\Api\v1\Controllers\Auth;
2021-12-02 13:15:53 +01:00
use App\Models\User;
use App\Models\Group;
2021-11-22 01:09:54 +01:00
use Tests\FeatureTestCase;
2021-12-02 13:15:53 +01:00
use App\Models\TwoFAccount;
2021-11-22 01:09:54 +01:00
class PasswordControllerTest extends FeatureTestCase
{
/**
2021-12-02 13:15:53 +01:00
* @var \App\Models\User
2021-11-22 01:09:54 +01:00
*/
protected $user;
private const PASSWORD = 'password';
private const NEW_PASSWORD = 'newPassword';
/**
* @test
*/
public function setUp(): void
{
parent::setUp();
2021-12-02 13:15:53 +01:00
$this->user = User::factory()->create();
2021-11-22 01:09:54 +01:00
}
/**
* @test
*/
public function test_update_return_success()
{
$response = $this->actingAs($this->user, 'api')
->json('PATCH', '/api/v1/user/password', [
'currentPassword' => self::PASSWORD,
'password' => self::NEW_PASSWORD,
'password_confirmation' => self::NEW_PASSWORD,
])
->assertOk()
->assertJsonStructure([
'message',
]);
}
/**
* @test
*/
public function test_update_passing_bad_current_pwd_return_bad_request()
{
$response = $this->actingAs($this->user, 'api')
->json('PATCH', '/api/v1/user/password', [
'currentPassword' => self::NEW_PASSWORD,
'password' => self::NEW_PASSWORD,
'password_confirmation' => self::NEW_PASSWORD,
])
->assertStatus(400)
->assertJsonStructure([
'message',
]);
}
/**
* @test
*/
public function test_update_passing_invalid_data_return_validation_error()
{
$response = $this->actingAs($this->user, 'api')
->json('PATCH', '/api/v1/user/password', [
'currentPassword' => self::PASSWORD,
'password' => null,
'password_confirmation' => self::NEW_PASSWORD,
])
->assertStatus(422);
}
}