3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-03-03 07:01:26 +00:00
Files
snipe-it/tests/Feature/Assets/Ui/StoreAssetsTest.php
2025-05-14 12:31:27 -07:00

78 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature\Assets\Ui;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\User;
use Tests\TestCase;
class StoreAssetsTest extends TestCase
{
public function testPageRenders()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('hardware.create'))
->assertOk();
}
public function testAssetCanBeStoredWithSerialRequiredAndSerialProvided()
{
$user = User::factory()->superuser()->create();
$this->actingAs($user);
$model = AssetModel::factory()->create([
'require_serial' => 1,
]);
$response = $this->post(route('hardware.store'), [
'model_id' => $model->id,
'serials' => [1 => 'ABC123'],
'asset_tags' =>[1 => '1234'],
'status_id' => 1,
// other required fields...
]);
$response->assertRedirect();
$response->assertSessionHas('success-unescaped');
$this->assertNotEquals(
trans('admin/hardware/form.serial_required'),
session('error')
);
$this->assertDatabaseHas('assets', [
'model_id' => $model->id,
'serial' => 'ABC123',
'asset_tag' => '1234',
]);
}
public function testAssetCannotBeStoredIfSerialRequiredAndMissing()
{
$user = User::factory()->superuser()->create();
$this->actingAs($user);
$model = AssetModel::factory()->create([
'require_serial' => 1,
]);
$response = $this->post(route('hardware.store'), [
'model_id' => $model->id,
'serials' => [], // ← serial missing
'asset_tags' => [1 => '1234'],
'status_id' => 1,
]);
$response->assertRedirect();
$response->assertSessionHasErrors(['serials.1']);
$this->assertDatabaseMissing('assets', [
'model_id' => $model->id,
'asset_tag' => '1234',
]);
$response->assertSessionMissing('success-unescaped');
}
}