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]); }
private function havePost(ApiTester $I, $data = []) { $data = array_merge(['title' => 'Game of Thrones', 'body' => 'Body', 'created_at' => new DateTime(), 'updated_at' => new DateTime()], $data); return $I->haveRecord('posts', $data); }
<?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();
<?php $I = new ApiTester($scenario); $I->wantTo('list all devices'); $I->haveRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Public Pi', 'public' => 'true', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]); $piOne = $I->grabRecord('devices', ['ip' => '192.168.1.101']); $piTwo = $I->haveRecord('devices', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Private Pi', 'public' => 'false', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]); $piTwo = $I->grabRecord('devices', ['ip' => '192.168.1.102']); $piThree = $I->haveRecord('devices', ['ip' => '192.168.1.103', 'mac' => 'AA:11:BB:22:CC:33', 'name' => 'Auto Pi without group', 'public' => 'auto', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]); $piThree = $I->grabRecord('devices', ['ip' => '192.168.1.103']); $piFour = $I->haveRecord('devices', ['ip' => '192.168.1.104', 'mac' => 'DD:44:EE:55:FF:66', 'name' => 'Auto Pi with group', 'public' => 'auto', 'group' => 'my-group', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]); $piFour = $I->grabRecord('devices', ['ip' => '192.168.1.104']); $I->sendGET('devices'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.101', 'name' => 'Public Pi', 'on_home_page' => 'true', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piOne->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piOne->updated_at)->toIso8601String()]]); $I->dontSeeResponseContainsJson(['data' => ['ip' => '192.168.1.102', 'name' => 'Private Pi', 'on_home_page' => 'false', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]); $I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.103', 'name' => 'Auto Pi without group', 'on_home_page' => 'auto', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]); $I->dontSeeResponseContainsJson(['data' => ['ip' => '192.168.1.104', 'name' => 'Auto Pi with group', 'on_home_page' => 'auto', 'group' => 'my-group', 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]); $I->sendGET('devices/@my-group'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['data' => ['name' => 'Auto Pi with group']]); $I->dontSeeResponseContainsJson(['data' => ['name' => 'Auto Pi without group']]); $I->dontSeeResponseContainsJson(['data' => ['name' => 'Private Pi']]); $I->dontSeeResponseContainsJson(['data' => ['name' => 'Public Pi']]);
<?php $I = new ApiTester($scenario); $I->wantTo('poke the server with an existing device and a new IP'); $initial_created_at = \Carbon\Carbon::now()->subHour(); $initial_updated_at = \Carbon\Carbon::now()->subHour(); $I->haveRecord('devices', ['ip' => '192.168.1.123', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel', 'created_at' => $initial_created_at, 'updated_at' => $initial_updated_at]); $I->sendPOST('devices/poke', ['ip' => '192.168.1.100', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel']); $I->seeResponseCodeIs(200); $I->seeHttpHeader('Location', 'http://localhost/api/v1/devices/1'); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.100', 'name' => 'Manuel', 'on_home_page' => 'auto', 'group' => null]]); $I->seeResponseJsonMatchesXpath('//data//device_added'); $I->seeResponseJsonMatchesXpath('//data//last_contact'); $I->seeRecord('devices', ['ip' => '192.168.1.100', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel', 'public' => 'auto', 'group' => null]); $I->seeRecord('pokes', ['ip' => '192.168.1.100', 'mac' => '00:19:20:A1:B4:FC']); $device = $I->grabRecord('devices', ['mac' => '00:19:20:A1:B4:FC']); $created_at_after_poke = $I->carbonize($device->created_at); $updated_at_after_poke = $I->carbonize($device->updated_at); $I->assertTrue($updated_at_after_poke->gt($initial_updated_at), 'The updated_at timestamp after the poke is greater than the initial updated_at timestamp'); $I->assertTrue($updated_at_after_poke->gt($initial_created_at), 'The updated_at timestamp after the poke is greater than the initial created_at timestamp'); $I->assertTrue($created_at_after_poke->eq($initial_created_at), 'The created_at timestamp after the poke is equal to the initial created_at timestamp');
<?php $I = new ApiTester($scenario); $I->wantTo('update a device'); $user = $I->haveAnAccount(); $I->amHttpAuthenticated($user['email'], $user['password']); $created_at = \Carbon\Carbon::now()->subHour(); $updated_at = \Carbon\Carbon::now()->subHour(); $I->haveRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Awesome Pi One', 'created_at' => $created_at, 'updated_at' => $updated_at]); $I->sendPATCH('devices/1', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One']); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson(['ip' => '192.168.1.102', 'name' => 'Updated Awesome Pi One', 'on_home_page' => 'auto', 'group' => null]); $I->seeResponseJsonMatchesXpath('//data//device_added'); $I->seeResponseJsonMatchesXpath('//data//last_contact'); $I->canSeeRecord('devices', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One', 'public' => 'auto', 'group' => null]); $updatedDevice = $I->grabRecord('devices', ['ip' => '192.168.1.102']); $I->cantSeeRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Awesome Pi One']); $updated_created_at_timestamp = $I->carbonize($updatedDevice->created_at); $updated_updated_at_timestamp = $I->carbonize($updatedDevice->updated_at); $I->assertTrue($updated_created_at_timestamp->eq($created_at), 'Updated created_at timestamp is equal to the initial created_at timestamp'); $I->assertTrue($updated_updated_at_timestamp->gt($updated_at), 'Updated updated_at timestamp is greater than the initial updated_at timestamp'); $I->assertTrue($updated_updated_at_timestamp->gt($created_at), 'Updated updated_at timestamp is greater than the initial created_at timestamp'); $I->sendPATCH('devices/100', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One']); $I->seeResponseCodeIs(404); $I->seeResponseIsJson();