2FAuth/tests/Feature/Http/Auth/PasswordControllerTest.php

83 lines
2.1 KiB
PHP
Raw Normal View History

2021-11-22 01:09:54 +01:00
<?php
2022-03-31 12:09:25 +02:00
namespace Tests\Feature\Http\Auth;
2021-11-22 01:09:54 +01:00
2023-08-01 11:28:27 +02:00
use App\Http\Controllers\Auth\PasswordController;
2021-12-02 13:15:53 +01:00
use App\Models\User;
2023-08-01 11:28:27 +02:00
use PHPUnit\Framework\Attributes\CoversClass;
2021-11-22 01:09:54 +01:00
use Tests\FeatureTestCase;
2022-12-09 10:52:17 +01:00
/**
2023-08-01 11:28:27 +02:00
* PasswordControllerTest test class
2022-12-09 10:52:17 +01:00
*/
2023-08-01 11:28:27 +02:00
#[CoversClass(PasswordController::class)]
2021-11-22 01:09:54 +01:00
class PasswordControllerTest extends FeatureTestCase
{
/**
2023-03-10 16:03:42 +01:00
* @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable
2022-11-22 15:15:52 +01:00
*/
2021-11-22 01:09:54 +01:00
protected $user;
2022-11-22 15:15:52 +01:00
private const PASSWORD = 'password';
private const NEW_PASSWORD = 'newPassword';
2021-11-22 01:09:54 +01:00
/**
* @test
*/
2022-12-13 12:07:29 +01:00
public function setUp() : void
2021-11-22 01:09:54 +01:00
{
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()
{
2022-03-31 08:38:35 +02:00
$response = $this->actingAs($this->user, 'web-guard')
->json('PATCH', '/user/password', [
2022-11-22 15:15:52 +01:00
'currentPassword' => self::PASSWORD,
'password' => self::NEW_PASSWORD,
2021-11-22 01:09:54 +01:00
'password_confirmation' => self::NEW_PASSWORD,
])
->assertOk()
->assertJsonStructure([
'message',
]);
}
/**
* @test
*/
public function test_update_passing_bad_current_pwd_return_bad_request()
{
2022-03-31 08:38:35 +02:00
$response = $this->actingAs($this->user, 'web-guard')
->json('PATCH', '/user/password', [
2022-11-22 15:15:52 +01:00
'currentPassword' => self::NEW_PASSWORD,
'password' => self::NEW_PASSWORD,
2021-11-22 01:09:54 +01:00
'password_confirmation' => self::NEW_PASSWORD,
])
->assertStatus(400)
->assertJsonStructure([
'message',
]);
}
/**
* @test
*/
public function test_update_passing_invalid_data_return_validation_error()
{
2022-03-31 08:38:35 +02:00
$response = $this->actingAs($this->user, 'web-guard')
->json('PATCH', '/user/password', [
2022-11-22 15:15:52 +01:00
'currentPassword' => self::PASSWORD,
'password' => null,
2021-11-22 01:09:54 +01:00
'password_confirmation' => self::NEW_PASSWORD,
])
->assertStatus(422);
}
2022-11-22 15:15:52 +01:00
}