public function testCaptureFlag() { $token = $this->doLogin('*****@*****.**', '123456'); $this->tester->haveHttpHeader('Content-type', 'application/json'); $this->tester->haveHttpHeader('X-Api-token', $token); $region = rand(1, 4); $this->tester->sendPOST('/api/capture-flag', json_encode(['regionId' => $region])); $this->tester->seeResponseCodeIs(200); $this->tester->seeResponseIsJson(); $this->tester->haveHttpHeader('Content-type', 'application/json'); $this->tester->haveHttpHeader('X-Api-token', $token); $this->tester->sendGET('/api/player-status'); $this->tester->seeResponseCodeIs(200); $this->tester->seeResponseIsJson(); $data = json_decode($this->tester->grabResponse(), true); $myTeamId = $data['data']['id']; $this->tester->haveHttpHeader('Content-type', 'application/json'); $this->tester->sendGET('/api/game-status/1'); $this->tester->seeResponseCodeIs(200); $this->tester->seeResponseIsJson(); $data = json_decode($this->tester->grabResponse(), true); $data = $data['data']; $this->assertArrayHasKey('ownerRegion1', $data); $this->assertArrayHasKey('ownerRegion2', $data); $this->assertArrayHasKey('ownerRegion3', $data); $this->assertArrayHasKey('ownerRegion4', $data); // $this->assertEquals($data['ownerRegion' . $region]['id'], $myTeamId); }
public function testGetLocationsWithFilters() { $token = $this->doLogin('*****@*****.**', '123456'); $this->tester->haveHttpHeader('Content-type', 'application/json'); $this->tester->haveHttpHeader('X-Api-token', $token); $filter = ['game' => 1]; $this->tester->sendGET('/api/locations', $filter); $this->checkLocationList(); $data = json_decode($this->tester->grabResponse(), true); foreach ($data['data'] as $item) { $this->assertEquals($filter['game'], $item['game']); } }
public function checkDecisionAccess(ApiTester $I) { $user = $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $table = $I->createTable($I->getShortTableDataMatchingTypeAll()); $decisions = ['points' => 15, 'request' => ['string' => 'Invalid', 'numeric' => 1, 'bool' => false]]; $data = $I->makeDecision($table->_id, $decisions['request'], 'scoring'); $I->sendGET('api/v1/admin/decisions'); $I->assertContains($data->_id, $I->grabResponse()); $second_user = $I->createUser(true); $I->loginUser($second_user); $I->createProject(true); $I->sendGET('api/v1/admin/decisions'); $I->assertNotContains($data->_id, $I->grabResponse()); $I->loginUser($user); $I->sendPOST('api/v1/projects/users', ['user_id' => $second_user->_id, 'role' => 'manager', 'scope' => ['tables_create', 'tables_view', 'tables_update', 'decisions_view']]); $I->loginUser($second_user); $I->sendGET('api/v1/admin/decisions'); $I->assertContains($data->_id, $I->grabResponse()); }
public function testLoginUser() { $this->checkIsLogin('', false); $this->tester->haveHttpHeader('Content-type', 'application/json'); $this->tester->sendPOST('/api/login', json_encode(['email' => '*****@*****.**', 'password' => '123456'])); $this->tester->seeResponseCodeIs(200); $this->tester->seeResponseIsJson(); $this->checkGenericLoginData(); $response = json_decode($this->tester->grabResponse(), true); $token = $response['data']['token']; // Check login is true $this->checkIsLogin($token, true); // Do Logout $this->tester->haveHttpHeader('Content-type', 'application/json'); $this->tester->haveHttpHeader('X-Api-Token', $token); $this->tester->sendPOST('/api/logout'); $this->tester->seeResponseCodeIs(200); $this->tester->seeResponseIsJson(); // Check is logged out $this->checkIsLogin($token, false); }
private function checkStatList() { $this->tester->seeResponseCodeIs(200); $this->tester->seeResponseIsJson(); $data = json_decode($this->tester->grabResponse(), true); $this->tester->seeResponseJsonMatchesJsonPath('$.status'); $this->tester->seeResponseJsonMatchesJsonPath('$.data'); foreach ($data['data']['stats'] as $item) { $this->assertArrayHasKey('team', $item); $this->assertArrayHasKey('player', $item); $this->assertArrayHasKey('id', $item['player']); $this->assertArrayHasKey('alias', $item['player']); $this->assertArrayHasKey('level', $item['player']); $this->assertArrayHasKey('isLive', $item['player']); $this->assertArrayHasKey('isLive', $item); $this->assertArrayHasKey('location', $item); $this->assertArrayHasKey('player', $item['location']); $this->assertArrayHasKey('lat', $item['location']); $this->assertArrayHasKey('lng', $item['location']); $this->assertArrayHasKey('game', $item['location']); } }
$archiveID = $I->grabHttpHeader('x-amz-archive-id'); $I->haveHttpHeader('Content-Type', 'application/json'); $I->sendPOST('/-/vaults/testvault/jobs', ['Type' => 'archive-retrieval', 'ArchiveId' => $archiveID]); $I->seeResponseCodeIs(202); $jobID = $I->grabHttpHeader('x-amz-job-id'); $I->sendGET("/-/vaults/testvault/jobs/{$jobID}"); $I->seeResponseCodeIs(200); $I->seeResponseContainsJson(['StatusCode' => 'InProgress']); $I->sendPOST("/-/vaults/testvault/jobs/{$jobID}/force-complete", []); $I->seeResponseCodeIs(200); $I->sendGET("/-/vaults/testvault/jobs/{$jobID}"); $I->seeResponseCodeIs(200); $I->seeResponseContainsJson(['StatusCode' => 'Succeeded']); $I->sendGET("/-/vaults/testvault/jobs/{$jobID}/output"); $I->seeResponseCodeIs(200); $this->assertTrue($I->grabResponse() === $data); $I->haveHttpHeader('Range', 'bytes=0-1'); $I->sendGET("/-/vaults/testvault/jobs/{$jobID}/output"); $I->seeResponseCodeIs(206); $this->assertTrue($I->grabResponse() === 'AB'); $I->haveHttpHeader('Range', 'bytes=2-3'); $I->sendGET("/-/vaults/testvault/jobs/{$jobID}/output"); $I->seeResponseCodeIs(206); $this->assertTrue($I->grabResponse() === 'CD'); $I->haveHttpHeader('Content-Type', 'application/json'); $I->sendPOST('/-/vaults/testvault/jobs', ['Type' => 'archive-retrieval', 'ArchiveId' => $archiveID, 'RetrievalByteRange' => '1-1048575']); $I->seeResponseCodeIs(202); $jobID = $I->grabHttpHeader('x-amz-job-id'); $I->sendPOST("/-/vaults/testvault/jobs/{$jobID}/force-complete", []); $I->seeResponseCodeIs(200); $I->haveHttpHeader('Range', '');
<?php $I = new ApiTester($scenario); $I->wantTo('Insert items and checkout'); /** * @var array $item1 * @var array $item2 * @var int $order */ require "_AddItems.php"; $I->amGoingTo('checkout'); $I->sendPATCH('cart'); $I->seeCodeAndJson(200, ['id' => $order, 'total' => floatify($item1['final_price'] + $item2['final_price'])]); $I->amGoingTo('verify the order was really ~closed~'); $I->sendGET('cart'); $I->assertEquals(sizeof(json_decode($I->grabResponse())->items), 0, 'verify the cart is now empty');
<?php use Codeception\Util\Fixtures; /** @var Faker\Generator $faker */ $faker = Fixtures::get('faker'); $devs = Fixtures::get('devs'); $I = new ApiTester($scenario); $I->wantTo('get the user price based on the GitHub API'); $I->amGoingTo('Get a non-existent user'); $I->sendGET('dev/' . $faker->lexify('??????????')); $I->seeResponseCodeIs(404); $I->amGoingTo('Get an existent user'); $I->sendGET('dev/' . $devs[array_rand($devs)]); $I->seeResponseCodeIs(200); $dev = json_decode($I->grabResponse()); $I->assertTrue(is_numeric($dev->rate), 'rate is numeric'); $I->assertTrue(is_string($dev->username) && strlen($dev->username) != 0, 'username is present and is string');
public function consumers(ApiTester $I) { $faker = $I->getFaker(); $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $I->createConsumer(); $I->sendPOST('api/v1/projects/consumers', ['description' => $faker->text('20'), 'scope' => ['decisions_view', 'decisions_make']]); $consumer = json_decode($I->grabResponse())->data[0]; $I->assertConsumers('$.data[*]', 201); $text = $faker->text('20'); $I->sendPUT('api/v1/projects/consumers', ['description' => $text, 'scope' => ['decisions_view', 'decisions_make'], 'client_id' => $consumer->client_id]); $I->seeResponseContains($text); $I->assertConsumers(); $I->sendDELETE('api/v1/projects/consumers', ['client_id' => $consumer->client_id]); $I->cantSeeResponseContains($consumer->client_id); $I->assertConsumers(); }
public function invitation(ApiTester $I) { $faker = $I->getFaker(); $I->createAndLoginUser(); $first_project = $I->createProjectAndSetHeader(); $second_user_email = $faker->email; $I->sendPOST('api/v1/invite', ['email' => $second_user_email, 'role' => 'manager', 'scope' => ['tables_create', 'tables_view']]); $I->seeResponseCodeIs(200); $second_project = $I->createProject(true); $I->setHeader('X-Application', $second_project->_id); $I->sendPOST('api/v1/invite', ['email' => $second_user_email, 'role' => 'manager', 'scope' => ['tables_create', 'tables_view']]); $I->seeResponseCodeIs(200); $I->logout(); $I->loginClient($I->getCurrentClient()); $I->loginUser($I->createUser(true, $second_user_email)); $I->sendGET('api/v1/projects'); $I->seeResponseCodeIs(200); $I->assertContains($first_project->_id, $I->grabResponse()); $I->assertContains($second_project->_id, $I->grabResponse()); }
/** @var Faker\Generator $faker */ $faker = Fixtures::get('faker'); $orgs = Fixtures::get('orgs'); $sm_orgs = Fixtures::get('small_orgs'); $I = new ApiTester($scenario); $I->wantTo('list of developers of an organization'); $I->amGoingTo('Get a non-existent organization'); $I->sendGET('dev/organization/' . $faker->lexify('??????????')); $I->seeResponseCodeIs(404); $I->amGoingTo('Get an existent organization on different information levels'); $get_org = function ($level, $orgs) use($I) { $I->amGoingTo("Request Org {$level} information"); $query = $level ? '?level=' . $level : ''; $I->sendGET('dev/organization/' . $orgs[array_rand($orgs)] . $query); $I->seeResponseCodeIs(200); $org = json_decode($I->grabResponse(), true); $I->assertTrue(is_numeric($org['size']), 'has total of members'); $I->assertTrue(is_array($org['members']), 'has list of members'); $I->assertGreaterThanOrEqual(1, $org['size'], 'organization has at least one member'); $I->assertEquals(sizeof($org['members']), $org['size'], 'total is correctly calculated'); $I->assertTrue(is_string($org['members'][0]['username']), 'first member has "username"'); return $org; }; $org = $get_org('basic', $orgs); $I->assertEmpty($org['members'][0]['name']); $I->assertEmpty($org['members'][0]['repos']); $I->assertEmpty($org['members'][0]['rate']); $org = $get_org(null, $orgs); $I->assertTrue(is_string($org['members'][0]['name'])); $I->assertTrue(is_numeric($org['members'][0]['repos'])); $I->assertEmpty($org['members'][0]['rate']);