Added tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-08-16 22:44:03 +01:00
parent b57283d8d1
commit 5529669884
2 changed files with 44 additions and 1 deletions

View file

@ -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();
}
}

View file

@ -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'));
}
}