mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Добавлен Helper для AMQP, который собирает все поступающие сообщения и предоставляет методы для проверки созданных сообщений
Исправлен баг в форме ChangeUsernameForm Исправлен баг с конфигурацией тестов, который не позволял правильно проводить проверки на существование\несуществование моделей Добавлена поддержка передачи хоста Redis через env переменные в тестах
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
namespace: tests\codeception\api
|
||||
actor: Tester
|
||||
params: [env]
|
||||
paths:
|
||||
tests: .
|
||||
log: _output
|
||||
|
@ -4,6 +4,7 @@ modules:
|
||||
- Filesystem
|
||||
- Yii2
|
||||
- tests\codeception\common\_support\FixtureHelper
|
||||
- tests\codeception\common\_support\amqp\Helper
|
||||
- Redis
|
||||
- Asserts
|
||||
- REST:
|
||||
@ -11,8 +12,8 @@ modules:
|
||||
config:
|
||||
Yii2:
|
||||
configFile: '../config/api/functional.php'
|
||||
cleanup: true
|
||||
cleanup: false
|
||||
Redis:
|
||||
host: testredis
|
||||
host: "%REDIS_HOST%"
|
||||
port: 6379
|
||||
database: 0
|
||||
|
@ -3,6 +3,8 @@ modules:
|
||||
enabled:
|
||||
- Yii2:
|
||||
part: [orm, email, fixtures]
|
||||
- tests\codeception\common\_support\amqp\Helper
|
||||
config:
|
||||
Yii2:
|
||||
configFile: '../config/api/unit.php'
|
||||
cleanup: false
|
||||
|
@ -25,9 +25,15 @@ class ConfirmEmailFormTest extends TestCase {
|
||||
$this->assertInstanceOf(AccountSession::class, $result->getSession(), 'session was generated');
|
||||
$activationExists = EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists();
|
||||
$this->assertFalse($activationExists, 'email activation key is not exist');
|
||||
/** @var Account $user */
|
||||
$user = Account::findOne($fixture['account_id']);
|
||||
$this->assertEquals(Account::STATUS_ACTIVE, $user->status, 'user status changed to active');
|
||||
/** @var Account $account */
|
||||
$account = Account::findOne($fixture['account_id']);
|
||||
$this->assertEquals(Account::STATUS_ACTIVE, $account->status, 'user status changed to active');
|
||||
|
||||
$message = $this->tester->grabLastSentAmqpMessage('events');
|
||||
$body = json_decode($message->getBody(), true);
|
||||
$this->assertEquals($account->id, $body['accountId']);
|
||||
$this->assertEquals($account->username, $body['newUsername']);
|
||||
$this->assertNull($body['oldUsername']);
|
||||
}
|
||||
|
||||
private function createModel($key) {
|
||||
|
@ -18,9 +18,8 @@ class ConfirmNewEmailFormTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testChangeEmail() {
|
||||
$accountId = $this->tester->grabFixture('accounts', 'account-with-change-email-finish-state')['id'];
|
||||
/** @var Account $account */
|
||||
$account = Account::findOne($accountId);
|
||||
$account = Account::findOne($this->getAccountId());
|
||||
$newEmailConfirmationFixture = $this->tester->grabFixture('emailActivations', 'newEmailConfirmation');
|
||||
$model = new ConfirmNewEmailForm($account, [
|
||||
'key' => $newEmailConfirmationFixture['key'],
|
||||
@ -32,6 +31,23 @@ class ConfirmNewEmailFormTest extends TestCase {
|
||||
]));
|
||||
$data = unserialize($newEmailConfirmationFixture['_data']);
|
||||
$this->assertEquals($data['newEmail'], $account->email);
|
||||
$this->tester->canSeeAmqpMessageIsCreated('events');
|
||||
}
|
||||
|
||||
public function testCreateTask() {
|
||||
/** @var Account $account */
|
||||
$account = Account::findOne($this->getAccountId());
|
||||
$model = new ConfirmNewEmailForm($account);
|
||||
$model->createTask(1, 'test1@ely.by', 'test@ely.by');
|
||||
$message = $this->tester->grabLastSentAmqpMessage('events');
|
||||
$body = json_decode($message->getBody(), true);
|
||||
$this->assertEquals(1, $body['accountId']);
|
||||
$this->assertEquals('test1@ely.by', $body['newEmail']);
|
||||
$this->assertEquals('test@ely.by', $body['oldEmail']);
|
||||
}
|
||||
|
||||
private function getAccountId() {
|
||||
return $this->tester->grabFixture('accounts', 'account-with-change-email-finish-state')['id'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ class ChangeUsernameFormTest extends TestCase {
|
||||
$this->assertTrue($model->change());
|
||||
$this->assertEquals('my_new_nickname', Account::findOne($this->getAccountId())->username);
|
||||
$this->assertInstanceOf(UsernameHistory::class, UsernameHistory::findOne(['username' => 'my_new_nickname']));
|
||||
$this->tester->canSeeAmqpMessageIsCreated('events');
|
||||
}
|
||||
|
||||
public function testChangeWithoutChange() {
|
||||
@ -49,7 +50,8 @@ class ChangeUsernameFormTest extends TestCase {
|
||||
'AND',
|
||||
'username' => $username,
|
||||
['>=', 'applied_in', $callTime],
|
||||
]), 'no new UsernameHistory record, if we don\'t change nickname');
|
||||
]), 'no new UsernameHistory record, if we don\'t change username');
|
||||
$this->tester->cantSeeAmqpMessageIsCreated('events');
|
||||
}
|
||||
|
||||
public function testChangeCase() {
|
||||
@ -65,13 +67,17 @@ class ChangeUsernameFormTest extends TestCase {
|
||||
UsernameHistory::findOne(['username' => $newUsername]),
|
||||
'username should change, if we change case of some letters'
|
||||
);
|
||||
$this->tester->canSeeAmqpMessageIsCreated('events');
|
||||
}
|
||||
|
||||
public function testCreateTask() {
|
||||
$model = new ChangeUsernameForm();
|
||||
$model->createEventTask('1', 'test1', 'test');
|
||||
// TODO: у меня пока нет идей о том, чтобы это как-то успешно протестировать, увы
|
||||
// но по крайней мере можно убедиться, что оно не падает где-то на этом шаге
|
||||
$model->createEventTask(1, 'test1', 'test');
|
||||
$message = $this->tester->grabLastSentAmqpMessage('events');
|
||||
$body = json_decode($message->getBody(), true);
|
||||
$this->assertEquals(1, $body['accountId']);
|
||||
$this->assertEquals('test1', $body['newUsername']);
|
||||
$this->assertEquals('test', $body['oldUsername']);
|
||||
}
|
||||
|
||||
private function getAccountId() {
|
||||
|
Reference in New Issue
Block a user