diff --git a/tests/Feature/Accessories/Api/StoreAccessoryTest.php b/tests/Feature/Accessories/Api/StoreAccessoryTest.php index 1c2d3d5fd..496b8e9b3 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.php index 993f44902..9c0caaf95 100644 --- a/tests/Support/CustomTestMacros.php +++ b/tests/Support/CustomTestMacros.php @@ -100,5 +100,26 @@ trait CustomTestMacros return $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; + } + ); } }