Пожалуйста объясните почему после выполнения запроса /v1/auth/otp-send
тест
$this->assertSame('', $lastRecord->auth_key, 'Auth key is not cleared after otp submission');
валится с ошибкой, при этом если открыть базу, то я вижу, что все работает правильно и auth_key очищается.
Если сделать дамп $lastRecord я вижу старое значение auth_key, отличное от фактического значения в базе.
При этом если в начало теста добавить
$lastRecord = User::find()->orderBy(['id' => SORT_DESC])->limit(1)->one();
и запустить тест повторно, то я вижу, что в lastRecord будет актуальное значение из базы
<?php
namespace tests\api;
use Yii;
use Codeception\Util\Debug;
use Codeception\Util\HttpCode;
use GuzzleHttp\Client;
use common\models\User;
use common\models\UserRefreshTokens;
class UserSignupTest extends \Codeception\Test\Unit
{
/**
* @var \ApiTester
*/
protected $tester;
public function testUserSignupRoute()
{
$client = new Client(['base_uri' => Yii::$app->params['apiUrl']]);
// create user
$name = 'Test';
$email = 'test@test.ru';
$password = 'testtest';
$phone = '11111111111';
$affiliateKey = 'test';
$otp = '11111';
$response = $client->post('/v1/auth/signup', [
'form_params' => [
'name' => $name,
'email' => $email,
'password' => $password,
'passwordRepeat' => $password,
'privacyPolicy' => 1,
'phone' => $phone,
'affiliateKey' => $affiliateKey
]
]);
$this->assertSame(HttpCode::CREATED, $response->getStatusCode(), 'Wrong auth/signup request status');
$responseData = json_decode($response->getBody(), true);
// otp verification
$response = $client->post('/v1/auth/otp-send', [
'form_params' => [
'authKey' => $responseData['authKey'],
]
]);
$this->assertSame(HttpCode::OK, $response->getStatusCode(), 'Wrong auth/otp-send request status');
// checking created user data
$lastRecord = User::find()->orderBy(['id' => SORT_DESC])->limit(1)->one();
$this->assertNotNull($lastRecord, 'User not created');
$this->assertSame($name, $lastRecord->name, 'User name is wrong');
$this->assertSame($email, $lastRecord->email, 'User email is wrong');
$this->assertSame($phone, $lastRecord->phone, 'User phone is wrong');
$this->assertSame($responseData['authKey'], $lastRecord->auth_key, 'User auth key is wrong');
$this->assertSame($otp, (string)$lastRecord->otp_code, 'Wrong OTP code');
// otp submission
$response = $client->post('/v1/auth/otp-submit', [
'form_params' => [
'authKey' => $responseData['authKey'],
'otp' => $otp,
]
]);
$this->assertSame(HttpCode::OK, $response->getStatusCode(), 'Wrong auth/otp-submit request status');
$responseData = json_decode($response->getBody(), true);
// checking auth_key clearing
$lastRecord->refresh();
$this->assertSame('', $lastRecord->auth_key, 'Auth key is not cleared after otp submission');
// checking refresh token rekord
$refreshTokenRecord = UserRefreshTokens::find()->where(['user_id' => $lastRecord->id])->one();
$this->assertSame($responseData['refresh'], $refreshTokenRecord->refresh_token, 'Refresh token issue');
}
}