mirror of
https://github.com/elyby/accounts.git
synced 2024-11-06 08:11:24 +05:30
Fix tests
This commit is contained in:
parent
5fc97fdd7a
commit
7da6a952ee
@ -5,7 +5,9 @@ namespace api\tests\unit\modules\accounts\models;
|
|||||||
|
|
||||||
use api\modules\accounts\models\DeleteAccountForm;
|
use api\modules\accounts\models\DeleteAccountForm;
|
||||||
use api\tests\unit\TestCase;
|
use api\tests\unit\TestCase;
|
||||||
|
use Codeception\Util\ReflectionHelper;
|
||||||
use common\models\Account;
|
use common\models\Account;
|
||||||
|
use common\notifications\AccountEditNotification;
|
||||||
use common\tasks\CreateWebHooksDeliveries;
|
use common\tasks\CreateWebHooksDeliveries;
|
||||||
use common\tasks\DeleteAccount;
|
use common\tasks\DeleteAccount;
|
||||||
use common\tests\fixtures\AccountFixture;
|
use common\tests\fixtures\AccountFixture;
|
||||||
@ -46,7 +48,12 @@ class DeleteAccountFormTest extends TestCase {
|
|||||||
->method('push')
|
->method('push')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
[$this->callback(function(CreateWebHooksDeliveries $task) use ($account): bool {
|
[$this->callback(function(CreateWebHooksDeliveries $task) use ($account): bool {
|
||||||
$this->assertSame($account->id, $task->payloads['id']);
|
/** @var AccountEditNotification $notification */
|
||||||
|
$notification = ReflectionHelper::readPrivateProperty($task, 'notification');
|
||||||
|
$this->assertInstanceOf(AccountEditNotification::class, $notification);
|
||||||
|
$this->assertSame($account->id, $notification->getPayloads()['id']);
|
||||||
|
$this->assertTrue($notification->getPayloads()['isDeleted']);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
})],
|
})],
|
||||||
[$this->callback(function(DeleteAccount $task) use ($account): bool {
|
[$this->callback(function(DeleteAccount $task) use ($account): bool {
|
||||||
|
@ -5,7 +5,9 @@ namespace api\tests\unit\modules\accounts\models;
|
|||||||
|
|
||||||
use api\modules\accounts\models\RestoreAccountForm;
|
use api\modules\accounts\models\RestoreAccountForm;
|
||||||
use api\tests\unit\TestCase;
|
use api\tests\unit\TestCase;
|
||||||
|
use Codeception\Util\ReflectionHelper;
|
||||||
use common\models\Account;
|
use common\models\Account;
|
||||||
|
use common\notifications\AccountEditNotification;
|
||||||
use common\tasks\CreateWebHooksDeliveries;
|
use common\tasks\CreateWebHooksDeliveries;
|
||||||
use common\tests\fixtures\AccountFixture;
|
use common\tests\fixtures\AccountFixture;
|
||||||
use Yii;
|
use Yii;
|
||||||
@ -39,7 +41,12 @@ class RestoreAccountFormTest extends TestCase {
|
|||||||
->method('push')
|
->method('push')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
[$this->callback(function(CreateWebHooksDeliveries $task) use ($account): bool {
|
[$this->callback(function(CreateWebHooksDeliveries $task) use ($account): bool {
|
||||||
$this->assertSame($account->id, $task->payloads['id']);
|
/** @var AccountEditNotification $notification */
|
||||||
|
$notification = ReflectionHelper::readPrivateProperty($task, 'notification');
|
||||||
|
$this->assertInstanceOf(AccountEditNotification::class, $notification);
|
||||||
|
$this->assertSame($account->id, $notification->getPayloads()['id']);
|
||||||
|
$this->assertFalse($notification->getPayloads()['isDeleted']);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
})],
|
})],
|
||||||
);
|
);
|
||||||
|
@ -189,7 +189,9 @@ class Account extends ActiveRecord {
|
|||||||
|
|
||||||
public function afterDelete(): void {
|
public function afterDelete(): void {
|
||||||
parent::afterDelete();
|
parent::afterDelete();
|
||||||
Yii::$app->queue->push(new CreateWebHooksDeliveries(new AccountDeletedNotification($this)));
|
if ($this->status !== self::STATUS_REGISTERED) {
|
||||||
|
Yii::$app->queue->push(new CreateWebHooksDeliveries(new AccountDeletedNotification($this)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace common\tests\unit\models;
|
namespace common\tests\unit\models;
|
||||||
|
|
||||||
|
use Codeception\Util\ReflectionHelper;
|
||||||
use common\models\Account;
|
use common\models\Account;
|
||||||
|
use common\notifications\AccountDeletedNotification;
|
||||||
|
use common\notifications\AccountEditNotification;
|
||||||
use common\tasks\CreateWebHooksDeliveries;
|
use common\tasks\CreateWebHooksDeliveries;
|
||||||
use common\tests\fixtures\MojangUsernameFixture;
|
use common\tests\fixtures\MojangUsernameFixture;
|
||||||
use common\tests\unit\TestCase;
|
use common\tests\unit\TestCase;
|
||||||
@ -129,23 +132,37 @@ class AccountTest extends TestCase {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$account = new Account();
|
$account = new Account();
|
||||||
|
$account->id = 123;
|
||||||
$account->afterSave(false, $changedAttributes);
|
$account->afterSave(false, $changedAttributes);
|
||||||
/** @var CreateWebHooksDeliveries $job */
|
/** @var CreateWebHooksDeliveries $job */
|
||||||
$job = $this->tester->grabLastQueuedJob();
|
$job = $this->tester->grabLastQueuedJob();
|
||||||
$this->assertInstanceOf(CreateWebHooksDeliveries::class, $job);
|
$this->assertInstanceOf(CreateWebHooksDeliveries::class, $job);
|
||||||
$this->assertSame('account.edit', $job->type);
|
/** @var AccountEditNotification $notification */
|
||||||
$this->assertSame($changedAttributes, $job->payloads['changedAttributes']);
|
$notification = ReflectionHelper::readPrivateProperty($job, 'notification');
|
||||||
|
$this->assertInstanceOf(AccountEditNotification::class, $notification);
|
||||||
|
$this->assertSame(123, $notification->getPayloads()['id']);
|
||||||
|
$this->assertSame($changedAttributes, $notification->getPayloads()['changedAttributes']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAfterDeletePushEvent() {
|
public function testAfterDeletePushEvent() {
|
||||||
$account = new Account();
|
$account = new Account();
|
||||||
$account->id = 1;
|
$account->id = 1;
|
||||||
|
$account->status = Account::STATUS_REGISTERED;
|
||||||
|
$account->created_at = time() - 60 * 60 * 24;
|
||||||
|
$account->deleted_at = time();
|
||||||
|
|
||||||
|
$account->afterDelete();
|
||||||
|
$this->assertNull($this->tester->grabLastQueuedJob());
|
||||||
|
|
||||||
|
$account->status = Account::STATUS_ACTIVE;
|
||||||
$account->afterDelete();
|
$account->afterDelete();
|
||||||
/** @var CreateWebHooksDeliveries $job */
|
/** @var CreateWebHooksDeliveries $job */
|
||||||
$job = $this->tester->grabLastQueuedJob();
|
$job = $this->tester->grabLastQueuedJob();
|
||||||
$this->assertInstanceOf(CreateWebHooksDeliveries::class, $job);
|
$this->assertInstanceOf(CreateWebHooksDeliveries::class, $job);
|
||||||
$this->assertSame('account.deletion', $job->type);
|
/** @var AccountDeletedNotification $notification */
|
||||||
$this->assertSame(1, $job->payloads['id']);
|
$notification = ReflectionHelper::readPrivateProperty($job, 'notification');
|
||||||
|
$this->assertInstanceOf(AccountDeletedNotification::class, $notification);
|
||||||
|
$this->assertSame(1, $notification->getPayloads()['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user