A free open source IT asset/license management system
Add validation test
Marcus Moorea6bcd3c0c2b0
diff --git a/tests/Feature/Accessories/Api/StoreAccessoryTest.php b/tests/Feature/Accessories/Api/StoreAccessoryTest.phpindex 1c2d3d5fd8..496b8e9b3a 100644--- a/tests/Feature/Accessories/Api/StoreAccessoryTest.php+++ b/tests/Feature/Accessories/Api/StoreAccessoryTest.php@@ -14,4 +14,23 @@ class StoreAccessoryTest extends TestCase implements TestsPermissionsRequirement->postJson(route('api.accessories.store'))->assertForbidden();}++ public function testValidation()+ {+ $this->actingAsForApi(User::factory()->createAccessories()->create())+ ->postJson(route('api.accessories.store'), [+ //+ ])+ ->assertStatusMessageIs('error')+ ->assertMessagesContains([+ 'category_id',+ 'name',+ 'qty',+ ]);+ }++ public function testCanStoreAccessory()+ {+ $this->markTestIncomplete();+ }}diff --git a/tests/Support/CustomTestMacros.php b/tests/Support/CustomTestMacros.phpindex 993f449021..9c0caaf959 100644--- a/tests/Support/CustomTestMacros.php+++ b/tests/Support/CustomTestMacros.php@@ -100,5 +100,26 @@ trait CustomTestMacrosreturn $this;});++ TestResponse::macro(+ 'assertMessagesContains',+ function (array|string $keys) {+ Assert::assertArrayHasKey('messages', $this, 'Response did not contain any messages');++ if (is_string($keys)) {+ $keys = [$keys];+ }++ foreach ($keys as $key) {+ Assert::assertArrayHasKey(+ $key,+ $this['messages'],+ "Response messages did not contain the key: {$key}"+ );+ }++ return $this;+ }+ );}}