mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Added tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
b57283d8d1
commit
5529669884
|
@ -53,9 +53,30 @@ class CreateAssetModelsTest extends TestCase
|
|||
])
|
||||
->json();
|
||||
|
||||
// dd($response);
|
||||
$this->assertFalse(AssetModel::where('name', 'Test AssetModel')->exists());
|
||||
|
||||
}
|
||||
|
||||
public function testUniquenessAcrossModelNameAndModelNumber()
|
||||
{
|
||||
AssetModel::factory()->create(['name' => 'Test Model', 'model_number'=>'1234']);
|
||||
|
||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||
->postJson(route('api.models.store'), [
|
||||
'name' => 'Test Model',
|
||||
'model_number' => '1234',
|
||||
])
|
||||
->assertStatus(200)
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
->assertJson([
|
||||
'messages' => [
|
||||
'name' => ['The name must be unique across models and model number. '],
|
||||
'model_number' => ['The model number must be unique across models and name. '],
|
||||
],
|
||||
])
|
||||
->json();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,4 +51,26 @@ class CreateAssetModelsTest extends TestCase
|
|||
|
||||
}
|
||||
|
||||
public function testUniquenessAcrossModelNameAndModelNumber()
|
||||
{
|
||||
|
||||
AssetModel::factory()->create(['name' => 'Test Model', 'model_number'=>'1234']);
|
||||
|
||||
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||
->from(route('models.create'))
|
||||
->post(route('models.store'), [
|
||||
'name' => 'Test Model',
|
||||
'model_number' => '1234',
|
||||
'category_id' => Category::factory()->create()->id
|
||||
])
|
||||
->assertStatus(302)
|
||||
->assertSessionHasErrors(['name','model_number'])
|
||||
->assertStatus(302)
|
||||
->assertRedirect(route('models.create'))
|
||||
->assertInvalid(['name','model_number']);
|
||||
|
||||
$this->followRedirects($response)->assertSee(trans('general.error'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue