public function deletePost(ApiTester $I) { $id = $I->haveRecord('posts', $this->getPostAttributes(['title' => 'Game of Thrones'])); $I->sendDELETE($this->endpoint . "/{$id}"); $I->seeResponseCodeIs(200); $I->dontSeeRecord('posts', ['id' => $id]); }
public function deleteUser(ApiTester $I, \Codeception\Scenario $scenario) { //$scenario->skip('ownCloud master is broken'); $I->wantTo('delete the user'); $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded'); $I->sendDELETE($this->apiUrl . '/users/' . $this->userId); $I->seeResponseCodeIs(200); $I->seeResponseIsXml(); $I->seeXmlResponseIncludes(XmlUtils::toXml(['status' => 'ok'])); }
/** * @depends update */ public function delete(ApiTester $I) { $I->wantTo('Delete a new Contact in com_contacts using DELETE'); $I->amHttpAuthenticated('admin', 'admin'); $I->sendDELETE('index.php' . '?option=contact' . '&api=Hal' . '&webserviceClient=administrator' . '&webserviceVersion=1.0.0' . "&id={$this->id}"); $I->seeResponseCodeIs(200); $I->sendGET('index.php' . '?option=contact' . '&api=Hal' . '&webserviceClient=administrator' . '&webserviceVersion=1.0.0' . "&id={$this->id}"); $I->seeResponseCodeIs(404); $I->seeResponseIsJson(); $I->seeResponseContains('"message":"Item not found with given key.","code":404,"type":"Exception"'); }
public function deleteDiscussion(ApiTester $I) { $I->wantTo('delete a discussion via API'); $user = $I->amAuthenticated(); $user->groups()->attach(4); // Make the user a moderator $discussion = Factory::create('Flarum\\Core\\Models\\Discussion', ['start_user_id' => $user->id]); $I->sendDELETE($this->endpoint . '/' . $discussion->id); $I->seeResponseCodeIs(204); $I->seeResponseEquals(''); $I->expect('the discussion was deleted in the database'); $I->dontSeeRecord('discussions', ['id' => $discussion->id]); }
public function delete(ApiTester $I) { $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $I->createTable(); $I->createTable(); $I->sendGET('api/v1/admin/tables'); $I->assertListTable(); $response = $I->getResponseFields(); $id = $response->data[0]->_id; $id2 = $response->data[1]->_id; $I->sendDELETE('api/v1/admin/tables/' . $id); $I->sendGET('api/v1/admin/tables/' . $id); $I->seeResponseCodeIs(404); $I->sendGET('api/v1/admin/tables/' . $id2); $I->assertTable(); }
<?php $I = new ApiTester($scenario); $I->wantTo('delete a device'); $user = $I->haveAnAccount(); $I->amHttpAuthenticated($user['email'], $user['password']); $piOne = $I->haveRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Awesome Pi One', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]); $I->sendDELETE('devices/1'); $I->seeResponseCodeIs(204); $I->cantSeeRecord('devices', ['ip' => '192.168.1.101']); $I->sendDELETE('devices/1000'); $I->seeResponseCodeIs(404); $I->seeResponseIsJson();
\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"'); // delete team $I->sendDELETE("/teams/{$teamId}"); $I->seeResponseCodeIs(204); $I->sendGET('/players/33?expand=teams'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('teams'); $teams = $I->grabDataFromResponseByJsonPath('$.teams[0]'); \PHPUnit_Framework_Assert::assertEquals(1, count($teams)); // check that all other routes are disabled // index $I->sendGET('/teams'); $I->seeResponseCodeIs(405);
$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', ''); $I->sendGET("/-/vaults/testvault/jobs/{$jobID}/output"); $I->seeResponseCodeIs(200); $this->assertTrue($I->grabResponse() === substr($data, 1, 1024 * 1024 - 1)); $I->haveHttpHeader('Range', 'bytes=0-1'); $I->sendGET("/-/vaults/testvault/jobs/{$jobID}/output"); $I->seeResponseCodeIs(206); $this->assertTrue($I->grabResponse() === $data[1] . $data[2]); $I->sendDELETE("/-/vaults/testvault/archives/{$archiveID}"); $I->seeResponseCodeIs(204);
<?php $scenario->group('ListModule'); $I = new ApiTester($scenario); $I->wantTo('delete a element of the users List'); $I->sendDELETE('/list/elements', ['elementId' => 5]); $I->seeResponseCodeIs(200); $I->seeResponseEquals('');
<?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.');
<?php Yii::$app->redis->executeCommand('FLUSHDB'); use Codeception\Util\Debug; $model = new \app\models\Message(); $model->author_email = '*****@*****.**'; $model->author_name = 'test'; $model->message = str_repeat('A', 140); $model->save(); $I = new ApiTester($scenario); $I->wantTo('Excluir uma mensagem'); $I->sendDELETE('messages', ['' => $model->id]); $I->seeResponseIsJson(); $I->seeResponseContainsJson([]);
<?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 $I = new ApiTester($scenario); $I->wantTo('Create a new vault.'); $I->sendPUT('/-/vaults/testvault'); $I->seeResponseCodeIs(403); $I->haveAuth(); $I->sendPUT('/-/vaults/testvault'); $I->seeResponseCodeIs(201); $I->seeResponseEquals(''); $I->haveAuth(); $I->sendDELETE('/-/vaults/testvault'); $I->seeResponseCodeIs(204); $I->seeResponseEquals('');
$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); $I->amGoingTo('verify order value without discounts'); $I->sendGET('cart'); $I->seeResponseContainsJson(['total' => $calculate_discount(0, $item1, $item2, $item3)]); //we should not test a checkout with the coupon since this would be an integration test (?), and we're already testing the order total up there anyway
$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)); // check that all other routes are disabled // index $I->sendGET('/games'); $I->seeResponseCodeIs(405); //view $I->sendGET('/games/2'); $I->seeResponseCodeIs(405);
public function deleteAdminFromTheProject(ApiTester $I) { $user = $I->createAndLoginUser(); $I->createProjectAndSetHeader(); $I->loginClient($I->getCurrentClient()); $second_user = $I->createUser(true); $third_user = $I->createUser(true); $I->loginUser($user); $I->sendPOST('api/v1/projects/users', ['user_id' => $second_user->_id, 'role' => 'admin', 'scope' => ['tables_view', 'tables_update', 'users_manage']]); $I->seeResponseCodeIs(422); $I->sendPOST('api/v1/projects/users', ['user_id' => $second_user->_id, 'role' => 'manager', 'scope' => ['tables_view', 'tables_update', 'users_manage']]); $I->seeResponseCodeIs(201); $I->sendPOST('api/v1/projects/users', ['user_id' => $third_user->_id, 'role' => 'manager', 'scope' => ['tables_view', 'tables_update', 'users_manage']]); $I->seeResponseCodeIs(201); $I->loginUser($second_user); $I->sendDELETE('api/v1/projects/users', ['user_id' => $second_user->_id]); $I->seeResponseCodeIs(422); $I->sendDELETE('api/v1/projects/users', ['user_id' => $user->_id]); $I->seeResponseCodeIs(403); $I->sendDELETE('api/v1/projects/users', ['user_id' => $third_user->_id]); $I->seeResponseCodeIs(200); $I->loginUser($user); $I->sendDELETE('api/v1/projects/users', ['user_id' => $user->_id]); $I->seeResponseCodeIs(422); $I->sendPOST('api/v1/projects/users/admin', ['user_id' => $second_user->_id]); $I->seeResponseCodeIs(200); $I->loginUser($second_user); $I->sendDELETE('api/v1/projects/users', ['user_id' => $user->_id]); $I->seeResponseCodeIs(200); }
<?php $I = new ApiTester($scenario); $I->wantTo('Test the cart behaviour with items'); $I->amGoingTo('confirm the cart is empty'); $I->sendGET('cart'); $I->seeCodeAndJson(200, ['items' => [], 'total' => floatify(0)]); /** * @var array $item1 * @var array $item2 * @var int $item_id */ require "_AddItems.php"; $I->amGoingTo('Verify order'); $I->sendGET('cart'); $I->expectTo('see items in order'); $I->seeCodeAndJson(200, ['items' => [$item1, $item2]]); $I->expectTo('see correct total'); $I->seeResponseContainsJson(['total' => floatify($item1['final_price'] + $item2['final_price'])]); $I->amGoingTo('delete an item'); $I->sendDELETE('cart/item/' . $item_id); $I->seeResponseCodeIs(204); $I->seeResponseEquals(''); $I->sendGET('cart'); $I->seeCodeAndJson(200, ['items' => [$item2], 'total' => floatify($item2['final_price'])]); $I->amGoingTo('clear the cart'); $I->sendDELETE('cart'); $I->seeResponseCodeIs(204); $I->seeResponseEquals(''); $I->sendGET('cart'); $I->seeCodeAndJson(200, ['items' => [], 'total' => floatify(0)]);
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(); }
<?php $I = new ApiTester($scenario); $I->wantTo('Get a 404 when I want to delete an asset that does not exist'); $I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8'); $I->haveHttpHeader('X-Hash', 'e651e0f6450f89d82ab0a34c1d421097a635897f5e719179e49263ff145e6ed9'); $I->haveHttpHeader('X-PublicKey', '248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6'); $I->sendDELETE('asset/xyz123456', ''); $I->seeResponseCodeIs(404);
<?php $I = new ApiTester($scenario); $I->wantTo('Delete an asset and all its request, interventions and intervention material/work'); $I->haveHttpHeader('Content-Type', 'application/json;charset=utf-8'); $I->haveHttpHeader('X-Hash', 'e651e0f6450f89d82ab0a34c1d421097a635897f5e719179e49263ff145e6ed9'); $I->haveHttpHeader('X-PublicKey', '248512b6a66f365a4e42f10ed0c854844767b8ca8eb0f74589953991e9f233b6'); $I->sendDELETE('asset/4fc629ab08525', ''); $I->seeResponseCodeIs(200); /** asset id: 4fc629ab08525 request id: 53d6410fae2a1 intervid: 53d64168daea0 time: 15 amount: 5 unitprice: 20 */ $I->dontSeeInDatabase('assets', array('AssetID' => '4fc629ab08525')); $I->dontSeeInDatabase('request', array('AssetID' => '4fc629ab08525')); $I->dontSeeInDatabase('request', array('Request_id' => '53d6410fae2a1')); $I->dontSeeInDatabase('intervention', array('AssetID_Visit' => '4b595adc32bbf')); $I->dontSeeInDatabase('intervention', array('IntervID' => '53d64168daea0')); $I->dontSeeInDatabase('intervention_work', array('IntervID' => '53d64168daea0')); $I->dontSeeInDatabase('intervention_material', array('IntervID' => '53d64168daea0'));