mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Теперь при передаче запроса как json, закодированный в теле, он автоматически парсится
This commit is contained in:
@ -38,6 +38,17 @@ class AuthorizationCest {
|
||||
$this->testSuccessResponse($I);
|
||||
}
|
||||
|
||||
public function byNamePassedViaPOSTBody(FunctionalTester $I) {
|
||||
$I->wantTo('authenticate by username and password sent via post body');
|
||||
$this->route->authenticate(json_encode([
|
||||
'username' => 'admin',
|
||||
'password' => 'password_0',
|
||||
'clientToken' => Uuid::uuid4()->toString(),
|
||||
]));
|
||||
|
||||
$this->testSuccessResponse($I);
|
||||
}
|
||||
|
||||
public function byEmailWithEnabledTwoFactorAuth(FunctionalTester $I) {
|
||||
$I->wantTo('get valid error by authenticate account with enabled two factor auth');
|
||||
$this->route->authenticate([
|
||||
|
@ -98,17 +98,6 @@ class UsernamesToUuidsCest {
|
||||
]);
|
||||
}
|
||||
|
||||
public function passWrongPostBody(FunctionalTester $I) {
|
||||
$I->wantTo('get specific response when pass invalid json string');
|
||||
$this->route->uuidsByUsernames('wrong-json');
|
||||
$I->canSeeResponseCodeIs(400);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'error' => 'IllegalArgumentException',
|
||||
'errorMessage' => 'Passed array of profile names is an invalid JSON string.',
|
||||
]);
|
||||
}
|
||||
|
||||
private function validateFewValidUsernames(FunctionalTester $I) {
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
|
20
tests/codeception/api/unit/request/RequestParserTest.php
Normal file
20
tests/codeception/api/unit/request/RequestParserTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\unit\request;
|
||||
|
||||
use api\request\RequestParser;
|
||||
use tests\codeception\api\unit\TestCase;
|
||||
|
||||
class RequestParserTest extends TestCase {
|
||||
|
||||
public function testParse() {
|
||||
$parser = new RequestParser();
|
||||
$_POST = ['from' => 'post'];
|
||||
$this->assertEquals(['from' => 'post'], $parser->parse('from=post', ''));
|
||||
$this->assertEquals(['from' => 'post'], $parser->parse('', ''));
|
||||
$_POST = [];
|
||||
$this->assertEquals(['from' => 'json'], $parser->parse('{"from":"json"}', ''));
|
||||
$this->assertEquals(['from' => 'body'], $parser->parse('from=body', ''));
|
||||
$this->assertEquals(['onlykey' => ''], $parser->parse('onlykey', ''));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user