mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Реализована форма разблокировки аккаунта
This commit is contained in:
@@ -13,4 +13,9 @@ class InternalRoute extends BasePage {
|
||||
$this->actor->sendPOST($this->getUrl());
|
||||
}
|
||||
|
||||
public function pardon($accountId) {
|
||||
$this->route = '/internal/accounts/' . $accountId . '/ban';
|
||||
$this->actor->sendDELETE($this->getUrl());
|
||||
}
|
||||
|
||||
}
|
||||
|
47
tests/codeception/api/functional/internal/PardonCest.php
Normal file
47
tests/codeception/api/functional/internal/PardonCest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\functional\internal;
|
||||
|
||||
use common\models\OauthScope as S;
|
||||
use tests\codeception\api\_pages\InternalRoute;
|
||||
use tests\codeception\api\functional\_steps\OauthSteps;
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
|
||||
class PardonCest {
|
||||
|
||||
/**
|
||||
* @var InternalRoute
|
||||
*/
|
||||
private $route;
|
||||
|
||||
public function _before(FunctionalTester $I) {
|
||||
$this->route = new InternalRoute($I);
|
||||
}
|
||||
|
||||
public function testPardonAccount(OauthSteps $I) {
|
||||
$accessToken = $I->getAccessTokenByClientCredentialsGrant([S::ACCOUNT_BLOCK]);
|
||||
$I->amBearerAuthenticated($accessToken);
|
||||
|
||||
$this->route->pardon(10);
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testPardonNotBannedAccount(OauthSteps $I) {
|
||||
$accessToken = $I->getAccessTokenByClientCredentialsGrant([S::ACCOUNT_BLOCK]);
|
||||
$I->amBearerAuthenticated($accessToken);
|
||||
|
||||
$this->route->pardon(1);
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'account' => 'error.account_not_banned',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\unit\modules\internal\models;
|
||||
|
||||
use api\modules\internal\helpers\Error as E;
|
||||
use api\modules\internal\models\PardonForm;
|
||||
use common\models\Account;
|
||||
use tests\codeception\api\unit\TestCase;
|
||||
|
||||
class PardonFormTest extends TestCase {
|
||||
|
||||
public function testValidateAccountBanned() {
|
||||
$account = new Account();
|
||||
$account->status = Account::STATUS_BANNED;
|
||||
$form = new PardonForm($account);
|
||||
$form->validateAccountBanned();
|
||||
$this->assertEmpty($form->getErrors('account'));
|
||||
|
||||
$account = new Account();
|
||||
$account->status = Account::STATUS_ACTIVE;
|
||||
$form = new PardonForm($account);
|
||||
$form->validateAccountBanned();
|
||||
$this->assertEquals([E::ACCOUNT_NOT_BANNED], $form->getErrors('account'));
|
||||
}
|
||||
|
||||
public function testPardon() {
|
||||
/** @var Account|\PHPUnit_Framework_MockObject_MockObject $account */
|
||||
$account = $this->getMockBuilder(Account::class)
|
||||
->setMethods(['save'])
|
||||
->getMock();
|
||||
|
||||
$account->expects($this->once())
|
||||
->method('save')
|
||||
->willReturn(true);
|
||||
|
||||
$account->status = Account::STATUS_BANNED;
|
||||
$model = new PardonForm($account);
|
||||
$this->assertTrue($model->pardon());
|
||||
$this->assertEquals(Account::STATUS_ACTIVE, $account->status);
|
||||
$this->tester->canSeeAmqpMessageIsCreated('events');
|
||||
}
|
||||
|
||||
public function testCreateTask() {
|
||||
$account = new Account();
|
||||
$account->id = 3;
|
||||
|
||||
$model = new PardonForm($account);
|
||||
$model->createTask();
|
||||
$message = json_decode($this->tester->grabLastSentAmqpMessage('events')->body, true);
|
||||
$this->assertSame(3, $message['accountId']);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user