Fixed tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-04 21:14:58 +01:00
parent 066ec8e26e
commit c570759370
3 changed files with 11 additions and 13 deletions

View file

@ -130,7 +130,7 @@ class AssetModelsController extends Controller
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function update(StoreAssetModelRequest $request, $modelId = null) : RedirectResponse
public function update(StoreAssetModelRequest $request, $modelId) : RedirectResponse
{
$this->authorize('update', AssetModel::class);

View file

@ -18,12 +18,9 @@ class StoreAssetModelRequest extends ImageUploadRequest
public function prepareForValidation(): void
{
$this->category_type = Category::select('category_type')->find($this->category_id);
\Log::error('Category Type: '.$this->category_type);
$this->category_type = Category::find($this->category_id)->category_type;
$this->merge([
'model_category_type' => $this->category_type,
'category_type' => $this->category_type,
]);
}
@ -35,14 +32,14 @@ class StoreAssetModelRequest extends ImageUploadRequest
public function rules(): array
{
return array_merge(
['model_category_type' => 'required|in:asset'],
['category_type' => 'required|in:asset'],
parent::rules(),
);
}
public function messages(): array
{
$messages = ['model_category_type.in' => 'The category must be an asset category, dummy.'];
$messages = ['category_type.in' => 'The category must be an asset category, dummy.'];
return $messages;
}
}

View file

@ -16,6 +16,7 @@ class UpdateAssetModelsTest extends TestCase
'name' => 'Test Model',
'category_id' => Category::factory()->create()->id
])
->assertStatus(403)
->assertForbidden();
}
@ -28,6 +29,8 @@ class UpdateAssetModelsTest extends TestCase
'name' => 'Test Model',
'category_id' => Category::factory()->create()->id
])
->assertStatus(302)
->assertSessionHasNoErrors()
->assertRedirect(route('models.index'));
$this->assertTrue(AssetModel::where('name', 'Test Model')->exists());
@ -36,7 +39,6 @@ class UpdateAssetModelsTest extends TestCase
public function testUserCanEditAssetModels()
{
$category = Category::factory()->forAssets()->create();
\Log::error('Test Category: '.$category->category_type);
$model = AssetModel::factory()->create(['name' => 'Test Model', 'category_id' => $category->id]);
$this->assertTrue(AssetModel::where('name', 'Test Model')->exists());
@ -57,19 +59,18 @@ class UpdateAssetModelsTest extends TestCase
public function testUserCannotChangeAssetModelCategoryType()
{
$category = Category::factory()->forAssets()->create();
\Log::error('Test Update Category: '.$category->category_type);
$model = AssetModel::factory()->create(['name' => 'Test Model', 'category_id' => $category->id]);
$this->assertTrue(AssetModel::where('name', 'Test Model')->exists());
$response = $this->actingAs(User::factory()->superuser()->create())
->from(route('models.edit', ['model' => $model->id]))
->put(route('models.update', ['model' => $model]), [
'name' => 'Test Model Edited',
'category_id' => Category::factory()->forAccessories()->create()->id,
])
->assertSessionHasErrors(['category_type'])
->assertStatus(302)
->assertSessionHasErrors(['model_category_type'])
->assertRedirect(route('models.update', ['model' => $model]));
->assertRedirect(route('models.edit', ['model' => $model->id]));
$this->followRedirects($response)->assertSee(trans('general.error'));
$this->assertFalse(AssetModel::where('name', 'Test Model Edited')->exists());