Добавлен роут и логика для обновления access_token по refresh_token'у

This commit is contained in:
ErickSkrauch
2016-05-31 01:03:30 +03:00
parent cb038c897b
commit 1945a7baec
9 changed files with 258 additions and 3 deletions

View File

@ -0,0 +1,55 @@
<?php
namespace codeception\api\unit\models\authentication;
use api\components\User\RenewResult;
use api\models\authentication\RefreshTokenForm;
use Codeception\Specify;
use common\models\AccountSession;
use tests\codeception\api\unit\DbTestCase;
use tests\codeception\common\fixtures\AccountSessionFixture;
/**
* @property AccountSessionFixture $sessions
*/
class RefreshTokenFormTest extends DbTestCase {
use Specify;
public function fixtures() {
return [
'sessions' => AccountSessionFixture::class,
];
}
public function testValidateRefreshToken() {
$this->specify('error.refresh_token_not_exist if passed token not exists', function() {
/** @var RefreshTokenForm $model */
$model = new class extends RefreshTokenForm {
public function getSession() {
return null;
}
};
$model->validateRefreshToken();
expect($model->getErrors('refresh_token'))->equals(['error.refresh_token_not_exist']);
});
$this->specify('no errors if token exists', function() {
/** @var RefreshTokenForm $model */
$model = new class extends RefreshTokenForm {
public function getSession() {
return new AccountSession();
}
};
$model->validateRefreshToken();
expect($model->getErrors('refresh_token'))->isEmpty();
});
}
public function testRenew() {
$this->specify('success renew token', function() {
$model = new RefreshTokenForm();
$model->refresh_token = $this->sessions['admin']['refresh_token'];
expect($model->renew())->isInstanceOf(RenewResult::class);
});
}
}