From 487d88c0128a04a8e0f15cbbc73426416b36ed7d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 4 Sep 2024 15:43:01 -0700 Subject: [PATCH 1/5] Add some ui tests for accessories --- .../Accessories/Ui/AccessoriesIndexTest.php | 16 +++++ .../Accessories/Ui/CreateAccessoriesTest.php | 65 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/Feature/Accessories/Ui/AccessoriesIndexTest.php create mode 100644 tests/Feature/Accessories/Ui/CreateAccessoriesTest.php diff --git a/tests/Feature/Accessories/Ui/AccessoriesIndexTest.php b/tests/Feature/Accessories/Ui/AccessoriesIndexTest.php new file mode 100644 index 0000000000..ea355f9a9d --- /dev/null +++ b/tests/Feature/Accessories/Ui/AccessoriesIndexTest.php @@ -0,0 +1,16 @@ +actingAs(User::factory()->create()) + ->get(route('accessories.index')) + ->assertForbidden(); + } +} diff --git a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php new file mode 100644 index 0000000000..f7c418d445 --- /dev/null +++ b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php @@ -0,0 +1,65 @@ +actingAs(User::factory()->create()) + ->get(route('accessories.create')) + ->assertForbidden(); + } + + public function testCreateAccessoryPageRenders() + { + $this->actingAs(User::factory()->createAccessories()->create()) + ->get(route('accessories.create')) + ->assertOk() + ->assertViewIs('accessories.edit'); + } + + public function testValidDataRequiredToCreateAccessory() + { + $this->markTestIncomplete(); + } + + public function testCanCreateAccessory() + { + $category = Category::factory()->create(); + $company = Company::factory()->create(); + $location = Location::factory()->create(); + $manufacturer = Manufacturer::factory()->create(); + $supplier = Supplier::factory()->create(); + + $data = [ + 'company_id' => $company->id, + 'name' => 'My Accessory Name', + 'category_id' => $category->id, + 'supplier_id' => $supplier->id, + 'manufacturer_id' => $manufacturer->id, + 'location_id' => $location->id, + 'model_number' => '12345', + 'order_number' => '9876', + 'purchase_date' => '2024-09-04', + 'purchase_cost' => '99.98', + 'qty' => '3', + 'min_amt' => '1', + 'notes' => 'Some notes here', + ]; + + $this->actingAs(User::factory()->createAccessories()->create()) + ->post(route('accessories.store'), array_merge($data, ['redirect_option' => 'index'])) + ->assertRedirect(route('accessories.index')); + + $this->assertDatabaseHas('accessories', $data); + } +} From 9f832a93c948dc62c3374224d2804a4e6c8124b9 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 4 Sep 2024 15:44:52 -0700 Subject: [PATCH 2/5] Ensure user is stored --- tests/Feature/Accessories/Ui/CreateAccessoriesTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php index f7c418d445..002f2d3ee5 100644 --- a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php +++ b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php @@ -56,10 +56,12 @@ class CreateAccessoriesTest extends TestCase 'notes' => 'Some notes here', ]; - $this->actingAs(User::factory()->createAccessories()->create()) + $user = User::factory()->createAccessories()->create(); + + $this->actingAs($user) ->post(route('accessories.store'), array_merge($data, ['redirect_option' => 'index'])) ->assertRedirect(route('accessories.index')); - $this->assertDatabaseHas('accessories', $data); + $this->assertDatabaseHas('accessories', array_merge($data, ['user_id' => $user->id])); } } From 9c6718b459ea2d10ff2f0f34a7f566068118549e Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 4 Sep 2024 15:46:35 -0700 Subject: [PATCH 3/5] Organize --- .../Accessories/Ui/CreateAccessoriesTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php index 002f2d3ee5..4c82d96039 100644 --- a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php +++ b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php @@ -41,19 +41,19 @@ class CreateAccessoriesTest extends TestCase $supplier = Supplier::factory()->create(); $data = [ - 'company_id' => $company->id, - 'name' => 'My Accessory Name', 'category_id' => $category->id, - 'supplier_id' => $supplier->id, - 'manufacturer_id' => $manufacturer->id, + 'company_id' => $company->id, 'location_id' => $location->id, - 'model_number' => '12345', - 'order_number' => '9876', - 'purchase_date' => '2024-09-04', - 'purchase_cost' => '99.98', - 'qty' => '3', + 'manufacturer_id' => $manufacturer->id, 'min_amt' => '1', + 'model_number' => '12345', + 'name' => 'My Accessory Name', 'notes' => 'Some notes here', + 'order_number' => '9876', + 'purchase_cost' => '99.98', + 'purchase_date' => '2024-09-04', + 'qty' => '3', + 'supplier_id' => $supplier->id, ]; $user = User::factory()->createAccessories()->create(); From 010f66f4c9f79eb8199a5baa15e557218398f047 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 4 Sep 2024 15:48:11 -0700 Subject: [PATCH 4/5] Add validation test --- tests/Feature/Accessories/Ui/CreateAccessoriesTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php index 4c82d96039..abb3527ea1 100644 --- a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php +++ b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php @@ -29,7 +29,15 @@ class CreateAccessoriesTest extends TestCase public function testValidDataRequiredToCreateAccessory() { - $this->markTestIncomplete(); + $this->actingAs(User::factory()->createAccessories()->create()) + ->post(route('accessories.store'), [ + // + ]) + ->assertSessionHasErrors([ + 'name', + 'qty', + 'category_id', + ]); } public function testCanCreateAccessory() From 76c9015aa9c6988127d5c749b5ffdb5ba04e7d54 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 9 Sep 2024 16:51:40 -0700 Subject: [PATCH 5/5] Add test case --- tests/Feature/Accessories/Ui/CreateAccessoriesTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php index abb3527ea1..3570ef1704 100644 --- a/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php +++ b/tests/Feature/Accessories/Ui/CreateAccessoriesTest.php @@ -27,6 +27,13 @@ class CreateAccessoriesTest extends TestCase ->assertViewIs('accessories.edit'); } + public function testRequiresPermissionToCreateAccessory() + { + $this->actingAs(User::factory()->create()) + ->post(route('accessories.store')) + ->assertForbidden(); + } + public function testValidDataRequiredToCreateAccessory() { $this->actingAs(User::factory()->createAccessories()->create())