public function updatePost(ApiTester $I) { $id = $I->haveRecord('posts', $this->getPostAttributes(['title' => 'Game of Thrones'])); $I->sendPUT($this->endpoint . "/{$id}", ['title' => 'Lord of Thrones']); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['title' => 'Lord of Thrones']); $I->seeRecord('posts', ['title' => 'Lord of Thrones']); $I->dontSeeRecord('posts', ['title' => 'Game of Thrones']); }
/** * @depends readItem */ public function update(ApiTester $I) { $I->wantTo('Update a new Contact in com_contacts using PUT'); $I->amHttpAuthenticated('admin', 'admin'); $this->name = 'new_' . $this->name; $I->sendPUT('index.php' . '?option=contact' . '&api=Hal' . '&webserviceClient=administrator' . '&webserviceVersion=1.0.0' . "&id={$this->id}" . "&name={$this->name}"); $I->seeResponseCodeIs(200); $I->sendGET('index.php' . '?option=contact' . '&api=Hal' . '&webserviceClient=administrator' . '&webserviceVersion=1.0.0' . "&id={$this->id}"); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('"name":"' . $this->name . '"'); $I->comment("The contact name has been modified to: {$this->name}"); }
public function updateDiscussion(ApiTester $I) { $I->wantTo('update a discussion via API'); $user = $I->amAuthenticated(); $discussion = Factory::create('Flarum\\Core\\Models\\Discussion', ['start_user_id' => $user->id]); $I->sendPUT($this->endpoint . '/' . $discussion->id, ['discussions' => ['title' => 'foo']]); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->expect('the discussion title was updated'); $I->seeResponseContainsJson(['title' => 'foo']); $I->expect('the discussion was updated in the database'); $id = $I->grabDataFromJsonResponse('discussions.id'); $I->seeRecord('discussions', ['id' => $id, 'title' => 'foo']); }
<?php $I = new ApiTester($scenario); $I->wantTo('update an existing asset via PUT'); $I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8'); // no whitespaces in content hash! $I->haveHttpHeader('X-Hash', '5bb14dac8d49806a4f10bc24aff299b33c1f229eed775e7784b3e7a2888b593f'); $I->haveHttpHeader('X-PublicKey', '248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6'); // no whitespaces in json $I->sendPUT('asset/4b0beb98ce160', '{"AgentID":"99999","AssetFullName":"TAPPETO T2100ee","AssetStatusID":"1","AssetUtilizationID":"1","CurrentValue":"null","DonorID":"4cf67d984d94f","EmployeeID":"4d64045c4a525","GenericAssetID":"18427","InstallationDate":"2014-7-19","InternalIventoryNumber":"1234567890","Lifetime":"14","LocationID":"4d1481c1a54c5","ManufacturerID":"4d6f38daa55e4","Metrology":"0","MetrologyDate":"2014-7-19","MetrologyDocument":"null","Model":"T2100","Notes":"null","Picture":"null","PurchaseDate":"2013-6-20","PurchasePrice":"10000","ResponsiblePers":"null","SerialNumber":"SAS2345678WA","ServiceManual":"null","SupplierID":"4ce525f47e550","UMDNS":"14141","URL_Manual":"null","WarrantyContractExp":"2014-6-30","WarrantyContractID":"1","WarrantyContractNotes":"null","by_user":"******","lastmodified":"null"}'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeInDatabase('assets', array('AgentID' => '99999', "AssetFullName" => 'TAPPETO T2100ee', "AssetID" => "4b0beb98ce160"));
public function analytics(ApiTester $I) { $checkProbabilities = function ($probabilities, $requestsConditions, $requestsRule) use($I) { $ruleIndex = 0; foreach ($I->getResponseFields()->data->variants[0]->rules as $rule) { $conditionIndex = 0; foreach ($rule->conditions as $condition) { $I->assertEquals($probabilities[$ruleIndex]['conditions'][$conditionIndex], $condition->probability, "Wrong probability for condition {$condition->field_key}:{$condition->condition}=" . var_export($condition->value, true)); $I->assertEquals(is_array($requestsConditions) ? $requestsConditions[$condition->field_key] : $requestsConditions, $condition->requests, "Wrong request amount for condition {$condition->field_key}"); $conditionIndex++; } $I->assertEquals($probabilities[$ruleIndex]['rule'], $rule->probability, "Wrong probability for rule {$rule->title}"); $I->assertEquals(is_array($requestsRule) ? $requestsRule[$ruleIndex] : $requestsRule, $rule->requests, "Wrong request amount for rule {$rule->title}"); $ruleIndex++; } }; $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $variantId1 = $I->getMongoId(); $variantId2 = $I->getMongoId(); $tableData = $I->getTableShortData(); $tableData['variants'][0]['_id'] = $variantId1; $tableData['variants'][] = ['_id' => $variantId2, 'default_decision' => 'Decline', 'rules' => [['than' => 'Approve', 'title' => 'Valid rule title', 'description' => 'Valid rule description', 'conditions' => [['field_key' => 'numeric', 'condition' => '$eq', 'value' => true], ['field_key' => 'string', 'condition' => '$eq', 'value' => 'Yes'], ['field_key' => 'bool', 'condition' => '$eq', 'value' => false]]]]]; $table = $I->createTable($tableData); $checkData = [['numeric' => 340, 'string' => 'Bad', 'bool' => true], ['numeric' => 350, 'string' => 'Yes', 'bool' => false], ['numeric' => 360, 'string' => 'Not', 'bool' => false], ['numeric' => 370, 'string' => 'Yes', 'bool' => false], ['numeric' => 380, 'string' => 'Not', 'bool' => false], ['numeric' => 390, 'string' => 'Yes', 'bool' => true], ['numeric' => 400, 'string' => 'Bad', 'bool' => true], ['numeric' => 410, 'string' => 'Not', 'bool' => true], ['numeric' => 420, 'string' => 'Yes', 'bool' => false]]; foreach ($checkData as $data) { $data['variant_id'] = $variantId1; $I->makeDecision($table->_id, $data, 'decision'); } $I->sendGET("api/v1/admin/tables/{$table->_id}/{$variantId1}/analytics"); $I->assertTableWithAnalytics(); $checkProbabilities([['rule' => round(1 / 9, 5), 'conditions' => [round(3 / 9, 5), round(4 / 9, 5), round(5 / 9, 5)]], ['rule' => 0, 'conditions' => [round(6 / 9, 5), round(3 / 9, 5), round(4 / 9, 5)]]], 9, 9); $tableData['fields'][3] = ["key" => 'last', "title" => 'last', "source" => "request", "type" => 'numeric', 'preset' => null]; $tableData['variants'][0]['rules'][0]['conditions'][] = ['field_key' => 'last', 'condition' => '$lte', 'value' => 300]; $tableData['variants'][0]['rules'][1]['conditions'][] = ['field_key' => 'last', 'condition' => '$lt', 'value' => 500]; $tableData['variants'][1]['rules'][0]['conditions'][] = ['field_key' => 'last', 'condition' => '$lt', 'value' => 500]; sleep(1); $I->sendPUT('api/v1/admin/tables/' . $table->_id, $tableData); $I->seeResponseCodeIs(200); $checkData = [['numeric' => 380, 'string' => 'Not', 'last' => 250, 'bool' => true], ['numeric' => 390, 'string' => 'Not', 'last' => 300, 'bool' => true], ['numeric' => 400, 'string' => 'Yes', 'last' => 450, 'bool' => false], ['numeric' => 410, 'string' => 'Bad', 'last' => 550, 'bool' => false], ['numeric' => 420, 'string' => 'Bad', 'last' => 650, 'bool' => true]]; foreach ($checkData as $data) { $data['variant_id'] = $variantId1; $I->makeDecision($table->_id, $data); } $I->sendGET("api/v1/admin/tables/{$table->_id}/{$variantId1}/analytics"); $I->assertTableWithAnalytics(); $checkProbabilities([['rule' => 0, 'conditions' => [round(3 / 5, 5), round(1 / 5, 5), round(2 / 5, 5), round(2 / 5, 5)]], ['rule' => round(2 / 5, 5), 'conditions' => [round(2 / 5, 5), round(2 / 5, 5), round(3 / 5, 5), round(3 / 5, 5)]]], 5, 5); $I->sendGET("api/v1/admin/tables/{$table->_id}/{$variantId2}/analytics"); $I->assertTableWithAnalytics(); $checkProbabilities([['rule' => 0, 'conditions' => [0, 0, 0, 0]]], ['last' => 0, 'bool' => 0, 'string' => 0, 'numeric' => 0], 0); $I->sendGET("api/v1/admin/tables/{$table->_id}/invalidId/analytics"); $I->seeResponseCodeIs(404); }
<?php $I = new ApiTester($scenario); $I->wantTo('update an existing request via PUT'); $I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8'); // no whitespaces in content hash! $I->haveHttpHeader('X-Hash', '517c64ce66ec1129c94024f9cccab3762776e8c4eb9642543237abebc8c0ce98'); $I->haveHttpHeader('X-PublicKey', '248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6'); // no whitespaces in json $I->sendPUT('asset/4b674c6d9e9ff/532c5b331baf3', '{"Request_date":"2014-02-14","Request_desc":"blub","Request_contact_name":"democontact","Request_note":"somenotes","Request_st_id":"1","VisiTpID":"4"}'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeInDatabase('request', array("AssetID" => "4b674c6d9e9ff", "Request_id" => "532c5b331baf3", "Request_contact_name" => "democontact"));
public function settings(ApiTester $I) { $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $I->sendPUT('api/v1/projects', ['settings' => []]); $I->assertProject(); $I->assertTrue($I->getResponseFields()->data->settings instanceof \StdClass); }
$I->seeResponseCodeIs(201); $I->seeResponseIsJson(); $I->seeResponseContains('"sport":"voleyball"'); $I->seeResponseContains('"name":"QA"'); $I->seeResponseContains('"is_capitan":"1"'); $players = $I->grabDataFromResponseByJsonPath('$.players')[0]; \PHPUnit_Framework_Assert::assertEquals(1, count($players)); $teamId = $I->grabDataFromResponseByJsonPath('$.id')[0]; $I->sendGET('/players/33?expand=teams'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('teams'); $teams = $I->grabDataFromResponseByJsonPath('$.teams')[0]; \PHPUnit_Framework_Assert::assertEquals(2, count($teams)); // Join one player to the team $I->sendPUT("/teams/{$teamId}", ['join_player' => 'w@w.w']); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $players = $I->grabDataFromResponseByJsonPath('$.players')[0]; \PHPUnit_Framework_Assert::assertEquals(2, count($players)); // Remove player from the team $I->sendPUT("/teams/{$teamId}", ['remove_player' => 'w@w.w']); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $players = $I->grabDataFromResponseByJsonPath('$.players')[0]; \PHPUnit_Framework_Assert::assertEquals(1, count($players)); // update team name $I->sendPUT("/teams/{$teamId}", ['name' => 'QA2']); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('"name":"QA2"');
<?php $I = new ApiTester($scenario); $I->wantToTest('Users'); $I->amGoingTo('modify user data (not auth)'); $I->sendPUT("/users/0"); $I->seeResponseCodeIs(401);
<?php $I = new ApiTester($scenario); $I->wantTo('List vaults.'); $I->haveAuth(); $I->sendPUT('/-/vaults/testvault1'); $I->seeResponseCodeIs(201); $I->sendPUT('/-/vaults/testvault2'); $I->seeResponseCodeIs(201); $I->sendPUT('/-/vaults/testvault3'); $I->seeResponseCodeIs(201); $I->sendGET('/-/vaults'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseJsonMatchesJsonPath('$.VaultList'); $I->seeResponseJsonMatchesJsonPath('$.VaultList[*].VaultName'); $I->seeResponseJsonMatchesJsonPath('$.VaultList[*].CreationDate'); $I->seeResponseJsonMatchesJsonPath('$.VaultList[*].LastInventoryDate'); $I->seeResponseJsonMatchesJsonPath('$.VaultList[*].NumberOfArchives'); $I->seeResponseJsonMatchesJsonPath('$.VaultList[*].SizeInBytes'); $I->seeResponseJsonMatchesJsonPath('$.VaultList[*].VaultARN'); $I->sendDELETE('/-/vaults/testvault1'); $I->seeResponseCodeIs(204); $I->sendDELETE('/-/vaults/testvault2'); $I->seeResponseCodeIs(204); $I->sendDELETE('/-/vaults/testvault3'); $I->seeResponseCodeIs(204);
<?php $user_data = ['name' => 'Player 1', 'email' => '*****@*****.**', 'password' => 'test', 'password_repeat' => 'test']; $I = new ApiTester($scenario); $I->wantTo('check players resource'); // creating new player $I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded'); $I->sendPOST('/players', $user_data); $I->seeResponseCodeIs(201); $I->seeResponseIsJson(); $I->seeResponseContains('token'); // already existing player $user_data['email'] = 'q@q.q'; $I->sendPOST('/players', $user_data); $I->seeResponseCodeIs(422); $I->seeResponseIsJson(); $I->seeResponseContains('Email \\"q@q.q\\" has already been taken.'); // check that all other routes are disabled // index $I->sendGET('/players'); $I->seeResponseCodeIs(404); $I->seeResponseContains('Page not found.'); // update $I->sendPUT('/players/33', ['name' => 'updated_name']); $I->seeResponseCodeIs(404); $I->seeResponseContains('Page not found.'); // update $I->sendDELETE('/players/33'); $I->seeResponseCodeIs(404); $I->seeResponseContains('Page not found.');
$I->amGoingTo('use an invalid coupon code'); $I->sendPOST('cart/coupon', ['code' => 'XXX']); $I->seeResponseCodeIs(HTTP_NOT_FOUND); $set_coupon = function ($coupon) use($I, $item1, $item2, $calculate_discount) { $I->sendPOST('cart/coupon', ['code' => $coupon['code']]); $I->seeCodeAndJson(HTTP_OK, $coupon); $I->sendGET('cart'); $I->seeResponseContainsJson(['total' => $calculate_discount($coupon['discount'], $item1, $item2)]); }; $I->amGoingTo('use a valid coupon code'); $set_coupon($coupons[0]); $I->amGoingTo('change the coupon'); $set_coupon($coupons[1]); $I->amGoingTo('add a new item to see the price discount'); $item3 = $gen_item(); $I->sendPUT('cart', $item3); $item3['final_price'] = $item3['price'] * $item3['qty']; $I->sendGET('cart'); $I->seeResponseContainsJson(['total' => $calculate_discount($coupons[1]['discount'], $item1, $item2, $item3)]); $I->amGoingTo('remove the wrong coupon'); $I->sendDELETE('cart/coupon?code=' . $coupons[0]['code']); $I->seeResponseCodeIs(HTTP_CONFLICT); $I->amGoingTo('remove a weird coupon'); $I->sendDELETE('cart/coupon?code=' . $faker->lexify('??????????')); $I->seeResponseCodeIs(HTTP_NOT_FOUND); $I->amGoingTo('remove the right coupon'); $I->sendDELETE('cart/coupon?code=' . $coupons[1]['code']); $I->seeResponseCodeIs(HTTP_NO_CONTENT); $I->amGoingTo('remove the right coupon again'); $I->sendDELETE('cart/coupon?code=' . $coupons[1]['code']); $I->seeResponseCodeIs(HTTP_EXPECTATION_FAILED);
public function updateMetaInvalid(ApiTester $I) { $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $I->createTable($I->getTableShortData()); $decision = $I->makeDecision($I->getResponseFields()->data->_id, ['bool' => true, 'numeric' => 123, 'string' => 'Yes']); $data = array_fill(0, 20, 'test'); $data[str_repeat('2', 101)] = 'ok'; $data['invalid#'] = 'ok'; $data['stringLength'] = str_repeat('1', 501); $data['array'] = []; $data[] = [['array']]; $I->sendPUT("api/v1/admin/decisions/{$decision->_id}/meta", ['meta' => $data]); $I->seeResponseCodeIs(422); $I->canSeeResponseJsonMatchesJsonPath('$.data.meta_keys_amount'); $I->canSeeResponseJsonMatchesJsonPath('$.data.key_20'); $I->canSeeResponseJsonMatchesJsonPath('$.data.key_21'); $I->canSeeResponseJsonMatchesJsonPath('$.data.key_22_value'); $I->canSeeResponseJsonMatchesJsonPath('$.data.key_23_value'); $I->canSeeResponseJsonMatchesJsonPath('$.data.key_24_value'); $I->sendPUT("api/v1/admin/decisions/{$decision->_id}/meta", $data); $I->seeResponseCodeIs(422); $I->canSeeResponseJsonMatchesJsonPath('$.data.meta'); $I->sendPUT("api/v1/admin/decisions/{$decision->_id}/meta", []); $I->seeResponseCodeIs(422); $I->canSeeResponseJsonMatchesJsonPath('$.data.meta'); }
<?php $I = new ApiTester($scenario); $I->wantTo('get new pid for a user'); $I->haveHttpHeader(' Content-Type', 'application/json'); $I->sendPUT('http://localhost/api/v1/action/GetPid.php'); $I->seeResponseCodeIs(403); $I->seeResponseIsJson();
\PHPUnit_Framework_Assert::assertEquals(0, count($games)); // create game $I->sendPOST('/games', ['team_id' => 26, 'datetime' => date("Y-m-d H:i:s"), 'location' => "home", 'title' => "important game"]); $I->seeResponseCodeIs(201); $I->seeResponseIsJson(); $I->seeResponseContains('important game'); $I->seeResponseContains('home'); $gameId = $I->grabDataFromResponseByJsonPath('$.id')[0]; $I->sendGET('/teams/26?expand=games'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('games'); $games = $I->grabDataFromResponseByJsonPath('$.games')[0]; \PHPUnit_Framework_Assert::assertEquals(3, count($games)); // Join one player to the game $I->sendPUT("/games/{$gameId}", ['join_player' => 33]); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); // Remove player from the game $I->sendPUT("/games/{$gameId}", ['reject_player' => 33]); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); // delete game $I->sendDELETE("/games/{$gameId}"); $I->seeResponseCodeIs(204); $I->sendGET('/teams/26?expand=games'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('games'); $games = $I->grabDataFromResponseByJsonPath('$.games')[0]; \PHPUnit_Framework_Assert::assertEquals(2, count($games));
public function canNotEditItself(ApiTester $I) { $user = $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $I->sendPUT('api/v1/projects/users', ['user_id' => $user->_id, 'role' => 'manager', 'scope' => ['tables_view', 'tables_update', 'users_manage']]); $I->seeResponseCodeIs(403); $I->loginClient($I->getCurrentClient()); $second_user = $I->createUser(true); $I->loginUser($user); $I->sendPOST('api/v1/projects/users', ['user_id' => $second_user->_id, 'role' => 'manager', 'scope' => ['tables_view', 'tables_update', 'users_manage']]); $I->seeResponseCodeIs(201); $I->loginUser($second_user); $I->sendPUT('api/v1/projects/users', ['user_id' => $user->_id, 'role' => 'manager', 'scope' => ['tables_view', 'tables_update', 'users_manage']]); $I->seeResponseCodeIs(403); $I->loginUser($user); $I->sendPOST('api/v1/projects/users/admin', ['user_id' => $second_user->_id]); $I->seeResponseCodeIs(200); $I->loginUser($second_user); $I->sendPUT('api/v1/projects/users', ['user_id' => $user->_id, 'role' => 'manager', 'scope' => ['tables_view', 'tables_update', 'users_manage']]); $I->seeResponseCodeIs(200); }
<?php use Aws\Glacier\TreeHash; $I = new ApiTester($scenario); $I->wantTo('Upload, retrieve and delete an archive.'); $I->haveAuth(); $I->sendPUT('/-/vaults/testvault'); $I->seeResponseCodeIs(201); $data = ''; $archiveSize = 1024 * 1024 + 10; for ($i = 0; $i < $archiveSize; $i++) { $data .= chr(rand(0, 255)); } $data[0] = 'A'; $data[1] = 'B'; $data[2] = 'C'; $data[3] = 'D'; $treeHash = new TreeHash(); $treeHash->update($data); $treeHash = bin2hex($treeHash->complete()); $hash = hash('sha256', $data); $I->haveHttpHeader('Content-Type', 'application/octet-stream'); $I->haveHttpHeader('x-amz-archive-description', 'test123'); $I->haveHttpHeader('x-amz-sha256-tree-hash', $treeHash); $I->haveHttpHeader('x-amz-content-sha256', $hash); $I->sendPOST('/-/vaults/testvault/archives', $data); $I->seeResponseCodeIs(201); $I->seeResponseEquals(''); $archiveID = $I->grabHttpHeader('x-amz-archive-id'); $I->haveHttpHeader('Content-Type', 'application/json'); $I->sendPOST('/-/vaults/testvault/jobs', ['Type' => 'archive-retrieval', 'ArchiveId' => $archiveID]);
<?php $I = new ApiTester($scenario); $I->wantTo('update an existing intervention via PUT'); $I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8'); // no whitespaces in content hash! $I->haveHttpHeader('X-Hash', '8fa6f078389516253c2ca6ebdf4b37209721bd64eab99242ef51a9368b957d9e'); $I->haveHttpHeader('X-PublicKey', '248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6'); // no whitespaces in json $I->sendPUT('asset/4b67517f4462a/52fddba460044/532c5b53aab95', '{"Date":"2014-01-01","EmployeeID":"4d64045c4a525","AssetID_Visit":"4b67517f4462a","AssetStatusID":1,"FaildPart":"Cable Red","FailurCategID":2,"FailureCauseID":1,"Interv_desc":"blub","Comments":"yes","RespEng":"4c8fcac9f06fa","TotalWork":1,"TotalCosts":2}'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson(array("error" => false)); $I->seeResponseContainsJson(array("message" => "Intervention updated")); $I->seeInDatabase('intervention', array("IntervID" => "532c5b53aab95", "AssetID_Visit" => "4b67517f4462a", "Date" => "2014-01-01", "EmployeeID" => "4d64045c4a525", "RespEng" => "4c8fcac9f06fa"));