mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Add validation test
This commit is contained in:
parent
9b293afaac
commit
a6bcd3c0c2
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue