mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Implemented account deletion. Not all cases covered with tests [skip ci]
This commit is contained in:
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace common\tests\unit\tasks;
|
||||
|
||||
use common\models\Account;
|
||||
use common\tasks\ClearAccountSessions;
|
||||
use common\tests\fixtures;
|
||||
use common\tests\unit\TestCase;
|
||||
@@ -23,18 +22,10 @@ class ClearAccountSessionsTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
public function testCreateFromAccount() {
|
||||
$account = new Account();
|
||||
$account->id = 123;
|
||||
$task = ClearAccountSessions::createFromAccount($account);
|
||||
$this->assertSame(123, $task->accountId);
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
/** @var \common\models\Account $bannedAccount */
|
||||
$bannedAccount = $this->tester->grabFixture('accounts', 'banned-account');
|
||||
$task = new ClearAccountSessions();
|
||||
$task->accountId = $bannedAccount->id;
|
||||
$task = new ClearAccountSessions($bannedAccount->id);
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
$this->assertEmpty($bannedAccount->sessions);
|
||||
$this->assertEmpty($bannedAccount->minecraftAccessKeys);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\tests\unit\tasks;
|
||||
|
||||
use common\models\OauthClient;
|
||||
@@ -33,22 +35,18 @@ class ClearOauthSessionsTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
$task = new ClearOauthSessions();
|
||||
$task->clientId = 'deleted-oauth-client-with-sessions';
|
||||
$task->notSince = 1519510065;
|
||||
$task = new ClearOauthSessions('deleted-oauth-client-with-sessions', 1519510065);
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
|
||||
$this->assertFalse(OauthSession::find()->andWhere(['legacy_id' => 3])->exists());
|
||||
$this->assertTrue(OauthSession::find()->andWhere(['legacy_id' => 4])->exists());
|
||||
|
||||
$task = new ClearOauthSessions();
|
||||
$task->clientId = 'deleted-oauth-client-with-sessions';
|
||||
$task = new ClearOauthSessions('deleted-oauth-client-with-sessions');
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
|
||||
$this->assertFalse(OauthSession::find()->andWhere(['legacy_id' => 4])->exists());
|
||||
|
||||
$task = new ClearOauthSessions();
|
||||
$task->clientId = 'some-not-exists-client-id';
|
||||
$task = new ClearOauthSessions('some-not-exists-client-id');
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,7 @@ class CreateWebHooksDeliveriesTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
$task = new CreateWebHooksDeliveries();
|
||||
$task->type = 'account.edit';
|
||||
$task->payloads = [
|
||||
$task = new CreateWebHooksDeliveries('account.edit', [
|
||||
'id' => 123,
|
||||
'uuid' => 'afc8dc7a-4bbf-4d3a-8699-68890088cf84',
|
||||
'username' => 'mock-username',
|
||||
@@ -68,7 +66,7 @@ class CreateWebHooksDeliveriesTest extends TestCase {
|
||||
'email' => 'old-email@ely.by',
|
||||
'status' => 0,
|
||||
],
|
||||
];
|
||||
]);
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
/** @var DeliveryWebHook[] $tasks */
|
||||
$tasks = $this->tester->grabQueueJobs();
|
||||
|
||||
90
common/tests/unit/tasks/DeleteAccountTest.php
Normal file
90
common/tests/unit/tasks/DeleteAccountTest.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\tests\unit\tasks;
|
||||
|
||||
use common\models\Account;
|
||||
use common\tasks\DeleteAccount;
|
||||
use common\tests\fixtures;
|
||||
use common\tests\unit\TestCase;
|
||||
use yii\queue\Queue;
|
||||
|
||||
/**
|
||||
* @covers \common\tasks\DeleteAccount
|
||||
*/
|
||||
class DeleteAccountTest extends TestCase {
|
||||
|
||||
public function _fixtures(): array {
|
||||
return [
|
||||
'accounts' => fixtures\AccountFixture::class,
|
||||
'authSessions' => fixtures\AccountSessionFixture::class,
|
||||
'emailActivations' => fixtures\EmailActivationFixture::class,
|
||||
'minecraftAccessKeys' => fixtures\MinecraftAccessKeyFixture::class,
|
||||
'usernamesHistory' => fixtures\UsernameHistoryFixture::class,
|
||||
'oauthClients' => fixtures\OauthClientFixture::class,
|
||||
'oauthSessions' => fixtures\OauthSessionFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
/** @var Account $account */
|
||||
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||
$account->status = Account::STATUS_DELETED;
|
||||
$account->deleted_at = time() - 60 * 60 * 24 * 7;
|
||||
$account->save();
|
||||
|
||||
$task = new DeleteAccount($account->id);
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
$this->assertEmpty($account->emailActivations);
|
||||
$this->assertEmpty($account->sessions);
|
||||
$this->assertEmpty($account->minecraftAccessKeys);
|
||||
$this->assertEmpty($account->oauthSessions);
|
||||
$this->assertEmpty($account->usernameHistory);
|
||||
$this->assertEmpty($account->oauthClients);
|
||||
$this->assertFalse($account->refresh());
|
||||
}
|
||||
|
||||
/**
|
||||
* When a user restores his account back, the task doesn't removed
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function testExecuteOnNotDeletedAccount() {
|
||||
/** @var Account $account */
|
||||
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||
// By default, this account is active
|
||||
|
||||
$task = new DeleteAccount($account->id);
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
$this->assertNotEmpty($account->emailActivations);
|
||||
$this->assertNotEmpty($account->sessions);
|
||||
$this->assertNotEmpty($account->minecraftAccessKeys);
|
||||
$this->assertNotEmpty($account->oauthSessions);
|
||||
$this->assertNotEmpty($account->usernameHistory);
|
||||
$this->assertNotEmpty($account->oauthClients);
|
||||
$this->assertTrue($account->refresh());
|
||||
}
|
||||
|
||||
/**
|
||||
* User also might delete his account, restore it and delete again.
|
||||
* For each deletion the job will be created, so assert, that job for restored deleting will not work
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function testExecuteOnDeletedAccountWhichWasRestoredAndThenDeletedAgain() {
|
||||
/** @var Account $account */
|
||||
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||
$account->status = Account::STATUS_DELETED;
|
||||
$account->deleted_at = time() - 60 * 60 * 24 * 2;
|
||||
$account->save();
|
||||
|
||||
$task = new DeleteAccount($account->id);
|
||||
$task->execute($this->createMock(Queue::class));
|
||||
$this->assertNotEmpty($account->emailActivations);
|
||||
$this->assertNotEmpty($account->sessions);
|
||||
$this->assertNotEmpty($account->minecraftAccessKeys);
|
||||
$this->assertNotEmpty($account->oauthSessions);
|
||||
$this->assertNotEmpty($account->usernameHistory);
|
||||
$this->assertNotEmpty($account->oauthClients);
|
||||
$this->assertTrue($account->refresh());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user