2016-05-11 01:55:04 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\functional;
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\_pages\AuthenticationRoute;
|
|
|
|
use api\tests\FunctionalTester;
|
2016-05-11 01:55:04 +05:30
|
|
|
|
|
|
|
class ForgotPasswordCest {
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
private AuthenticationRoute $route;
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function _before(FunctionalTester $I): void {
|
2017-01-24 02:20:13 +05:30
|
|
|
$this->route = new AuthenticationRoute($I);
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testWrongInput(FunctionalTester $I): void {
|
2017-01-24 02:20:13 +05:30
|
|
|
$I->wantTo('see reaction on invalid input');
|
|
|
|
|
|
|
|
$this->route->forgotPassword();
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
2017-01-24 02:20:13 +05:30
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'login' => 'error.login_required',
|
|
|
|
],
|
2016-05-11 01:55:04 +05:30
|
|
|
]);
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
$this->route->forgotPassword('becauseimbatman!');
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'login' => 'error.login_not_exist',
|
|
|
|
],
|
|
|
|
]);
|
2016-05-11 01:55:04 +05:30
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testForgotPasswordByEmail(FunctionalTester $I): void {
|
2017-01-24 02:20:13 +05:30
|
|
|
$I->wantTo('create new password recover request by passing email');
|
|
|
|
$this->route->forgotPassword('admin@ely.by');
|
|
|
|
$this->assertSuccessResponse($I, false);
|
|
|
|
}
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testForgotPasswordByUsername(FunctionalTester $I): void {
|
2017-01-24 02:20:13 +05:30
|
|
|
$I->wantTo('create new password recover request by passing username');
|
|
|
|
$this->route->forgotPassword('Admin');
|
|
|
|
$this->assertSuccessResponse($I, true);
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testDataForFrequencyError(FunctionalTester $I): void {
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->wantTo('get info about time to repeat recover password request');
|
2017-01-24 02:20:13 +05:30
|
|
|
$this->route->forgotPassword('Notch');
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
2016-06-17 01:06:52 +05:30
|
|
|
'login' => 'error.recently_sent_message',
|
2016-05-11 01:55:04 +05:30
|
|
|
],
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
|
|
|
}
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
/**
|
|
|
|
* @param FunctionalTester $I
|
|
|
|
*/
|
|
|
|
private function assertSuccessResponse(FunctionalTester $I, bool $expectEmailMask = false): void {
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => true,
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
|
|
|
if ($expectEmailMask) {
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.emailMask');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 01:55:04 +05:30
|
|
|
}
|