From 7336606475d0599b087b8a794c3c286863a13485 Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 18 Jan 2020 13:35:31 +0100 Subject: [PATCH] complete the tests for box api --- tests/ContainerTest.php | 52 +++++++++++++++++++++++++++++++++++++++++ tests/EventTest.php | 3 +++ 2 files changed, 55 insertions(+) diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index 32c6514..529bf8f 100644 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -61,4 +61,56 @@ class ContainerTest extends TestCase $this->assertEquals(2, $response[0]['itemCount']); } + public function testCreateContainer(){ + $this->post('/1/box', ['name'=>'BOX']); + $response = $this->response->getOriginalContent(); + + $this->assertResponseStatus(201); + $this->assertEquals(1, $response['cid']); + $this->assertEquals('BOX', $response['name']); + $this->assertEquals(0, $response['itemCount']); + + $boxes = Container::all(); + + $this->assertEquals(1, count($boxes)); + $this->assertEquals(1, $boxes[0]['cid']); + $this->assertEquals('BOX', $boxes[0]['name']); + $this->assertEquals(0, $boxes[0]['itemCount']); + } + + public function testUpdateContainer(){ + $box = Container::create(['name'=>'BOX 1']); + + $this->assertEquals(1, $box['cid']); + $this->assertEquals('BOX 1', $box['name']); + $this->assertEquals(0, $box['itemCount']); + + $this->put('/1/box/'.$box->cid, ['name'=>'BOX 2']); + $response = $this->response->getOriginalContent(); + + $this->assertResponseOk(); + $this->assertEquals(1, $response['cid']); + $this->assertEquals('BOX 2', $response['name']); + $this->assertEquals(0, $response['itemCount']); + + $boxes = Container::all(); + + $this->assertEquals(1, count($boxes)); + $this->assertEquals(1, $boxes[0]['cid']); + $this->assertEquals('BOX 2', $boxes[0]['name']); + $this->assertEquals(0, $boxes[0]['itemCount']); + } + + public function testDeleteContainer(){ + $box = Container::create(['name'=>'BOX 1']); + Container::create(['name'=>'BOX 2']); + + $this->assertEquals(2, count(Container::all())); + + $this->delete('/1/box/'.$box->cid); + + $this->assertResponseOk(); + $this->assertEquals(1, count(Container::all())); + } + } diff --git a/tests/EventTest.php b/tests/EventTest.php index 166cb2a..55c5259 100644 --- a/tests/EventTest.php +++ b/tests/EventTest.php @@ -49,6 +49,7 @@ class EventTest extends TestCase $this->post('/1/event', ['slug'=>'EVENT', 'name'=>'Event']); $response = $this->response->getOriginalContent(); + $this->assertResponseStatus(201); $this->assertEquals(1, $response['eid']); $this->assertEquals('EVENT', $response['slug']); $this->assertEquals('Event', $response['name']); @@ -71,6 +72,7 @@ class EventTest extends TestCase $this->put('/1/event/'.$event->eid, ['slug'=>'EVENT2', 'name'=>'Event 2']); $response = $this->response->getOriginalContent(); + $this->assertResponseOk(); $this->assertEquals(1, $response['eid']); $this->assertEquals('EVENT2', $response['slug']); $this->assertEquals('Event 2', $response['name']); @@ -95,6 +97,7 @@ class EventTest extends TestCase $this->delete('/1/event/'.$event->eid); + $this->assertResponseOk(); $this->assertEquals(1, count(Event::all())); }