fixed eol, add calculated eol/eol explicit tests

This commit is contained in:
spencerrlongg 2023-11-29 14:57:31 -06:00
parent 9d8433bd6d
commit c3492f1699
2 changed files with 61 additions and 1 deletions

View file

@ -545,7 +545,7 @@ class AssetsController extends Controller
$asset->user_id = Auth::id();
// @todo: verify eol is working as expected - move to request? or do I want this at all?
// might just remove this and then use the method from here https://github.com/snipe/snipe-it/pull/13846
//$asset->asset_eol_date = $request->validated()['asset_eol_date'] ?? $asset->present()->eol_date();
$asset->asset_eol_date = $request->validated()['asset_eol_date'] ?? $asset->present()->eol_date();
$asset->archived = '0';
$asset->physical = '1';
$asset->depreciate = '0';

View file

@ -95,6 +95,66 @@ class AssetStoreTest extends TestCase
$this->assertEquals(10, $asset->warranty_months);
}
public function testAssetEolDateIsCalculatedIfPurchaseDateSet()
{
$model = AssetModel::factory()->mbp13Model()->create();
$status = Statuslabel::factory()->create();
$this->settings->enableAutoIncrement();
$this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.assets.store'), [
'model_id' => $model->id,
'purchase_date' => '2021-01-01',
'status_id' => $status->id,
])
->assertOk()
->assertStatusMessageIs('success');
$asset = Asset::first();
$this->assertEquals('2024-01-01', $asset->asset_eol_date);
}
public function testAssetEolDateIsNotCalculatedIfPurchaseDateNotSet()
{
$model = AssetModel::factory()->mbp13Model()->create();
$status = Statuslabel::factory()->create();
$this->settings->enableAutoIncrement();
$this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.assets.store'), [
'model_id' => $model->id,
'status_id' => $status->id,
])
->assertOk()
->assertStatusMessageIs('success');
$asset = Asset::first();
$this->assertNull($asset->asset_eol_date);
}
public function testAssetEolExplicitIsSetIfAssetEolDateIsSet()
{
$model = AssetModel::factory()->mbp13Model()->create();
$status = Statuslabel::factory()->create();
$this->settings->enableAutoIncrement();
$this->actingAsForApi(User::factory()->superuser()->create())
->postJson(route('api.assets.store'), [
'model_id' => $model->id,
'asset_eol_date' => '2025-01-01',
'status_id' => $status->id,
])
->assertOk()
->assertStatusMessageIs('success');
$asset = Asset::first();
$this->assertEquals('2025-01-01', $asset->asset_eol_date);
$this->assertTrue($asset->eol_explicit);
}
public function testAssetGetsAssetTagWithAutoIncrement()
{
$model = AssetModel::factory()->create();