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

77 lines
1.9 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
2021-12-02 13:15:53 +01:00
use App\Models\User;
2021-11-22 01:09:54 +01:00
use Tests\FeatureTestCase;
class PasswordControllerTest extends FeatureTestCase
{
/**
2021-12-02 13:15:53 +01:00
* @var \App\Models\User
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-11-22 15:15:52 +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
}