Added test for models with same name but no model number

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-08-16 23:04:11 +01:00
parent 3ae4a5caf0
commit e96b9b2f4f
2 changed files with 41 additions and 0 deletions

View file

@ -79,4 +79,25 @@ class CreateAssetModelsTest extends TestCase
}
public function testUniquenessAcrossModelNameAndModelNumberWithBlankModelNumber()
{
AssetModel::factory()->create(['name' => 'Test Model']);
$this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.models.store'), [
'name' => 'Test Model',
])
->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();
}
}

View file

@ -65,7 +65,27 @@ class CreateAssetModelsTest extends TestCase
])
->assertStatus(302)
->assertSessionHasErrors(['name','model_number'])
->assertRedirect(route('models.create'))
->assertInvalid(['name','model_number']);
$this->followRedirects($response)->assertSee(trans('general.error'));
}
public function testUniquenessAcrossModelNameAndModelNumberWithoutModelNumber()
{
AssetModel::factory()->create(['name' => 'Test Model', 'model_number'=> null]);
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('models.create'))
->post(route('models.store'), [
'name' => 'Test Model',
'model_number' => null,
'category_id' => Category::factory()->create()->id
])
->assertStatus(302)
->assertSessionHasErrors(['name','model_number'])
->assertRedirect(route('models.create'))
->assertInvalid(['name','model_number']);