From 6b93f8ed5cd28b06bbeedb34379d758971891ae2 Mon Sep 17 00:00:00 2001 From: Attila Kerekes <439392+keriati@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:28:18 +0000 Subject: [PATCH] test: Add item create test (#1058) --- tests/.env.testing | 2 +- tests/Feature/ItemCreateTest.php | 41 +++++++++++++++++++++++++++++--- tests/Feature/ItemDeleteTest.php | 39 ++++++++++++++++++++++++++++++ tests/Feature/ItemExportTest.php | 3 --- 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 tests/Feature/ItemDeleteTest.php diff --git a/tests/.env.testing b/tests/.env.testing index eb15151a..50c4e8e2 100644 --- a/tests/.env.testing +++ b/tests/.env.testing @@ -1,7 +1,7 @@ APP_NAME=Heimdall APP_ENV=local APP_KEY= -APP_DEBUG=false +APP_DEBUG=true APP_URL=http://localhost LOG_CHANNEL=daily diff --git a/tests/Feature/ItemCreateTest.php b/tests/Feature/ItemCreateTest.php index 6ce3ded5..f166face 100644 --- a/tests/Feature/ItemCreateTest.php +++ b/tests/Feature/ItemCreateTest.php @@ -18,9 +18,6 @@ class ItemCreateTest extends TestCase $response->assertStatus(200); } - /** - * @return void - */ public function test_display_the_home_dashboard_tag() { $this->seed(); @@ -29,4 +26,42 @@ class ItemCreateTest extends TestCase $response->assertSee('Home dashboard'); } + + public function test_creates_a_new_item() + { + $this->seed(); + $item = [ + 'pinned' => 1, + 'appid' => 'null', + 'website' => null, + 'title' => 'Item A', + 'colour' => '#00f', + 'url' => 'http://10.0.1.1', + 'tags' => [0], + ]; + + $response = $this->post('/items', $item); + + $response->assertStatus(302); + $response->assertSee('Redirecting to'); + } + + public function test_redirects_to_dash_when_adding_a_new_item() + { + $this->seed(); + $item = [ + 'pinned' => 1, + 'appid' => 'null', + 'website' => null, + 'title' => 'Item A', + 'colour' => '#00f', + 'url' => 'http://10.0.1.1', + 'tags' => [0], + ]; + + $response = $this->post('/items', $item); + + $response->assertStatus(302); + $response->assertSee('Redirecting to http://localhost'); + } } diff --git a/tests/Feature/ItemDeleteTest.php b/tests/Feature/ItemDeleteTest.php new file mode 100644 index 00000000..13a1263b --- /dev/null +++ b/tests/Feature/ItemDeleteTest.php @@ -0,0 +1,39 @@ +seed(); + $item = Item::factory() + ->create([ + 'title' => 'Item A', + ]); + + $response = $this->post('/items/'.$item->id, ['_method' => 'DELETE']); + + $response->assertStatus(302); + } + + public function test_redirects_to_item_list_page_when_deleting_an_item() + { + $this->seed(); + $item = Item::factory() + ->create([ + 'title' => 'Item A', + ]); + + $response = $this->post('/items/'.$item->id, ['_method' => 'DELETE']); + + $response->assertStatus(302); + $response->assertSee('Redirecting to http://localhost/items'); + } +} diff --git a/tests/Feature/ItemExportTest.php b/tests/Feature/ItemExportTest.php index ea4a4aaf..c56015a0 100644 --- a/tests/Feature/ItemExportTest.php +++ b/tests/Feature/ItemExportTest.php @@ -29,7 +29,6 @@ class ItemExportTest extends TestCase "title" => "Item Title", "url" => "http://gorczany.com/nihil-rerum-distinctio-voluptate-assumenda-accusantium-exercitationem" ]; - Item::factory() ->create($exampleItem); @@ -55,7 +54,6 @@ class ItemExportTest extends TestCase ->create([ 'deleted_at' => Date::create('1970') ]); - Item::factory() ->create(); @@ -70,7 +68,6 @@ class ItemExportTest extends TestCase ->create([ 'type' => 1 ]); - Item::factory() ->create();