Skip to content

A free open source IT asset/license management system

buncha progress

spencerrlongg86ab880c90d2
diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php
index 432495bcc7..c010dfb52e 100644
--- a/database/factories/AssetFactory.php
+++ b/database/factories/AssetFactory.php
@@ -48,6 +48,7 @@ class AssetFactory extends Factory
'assigned_type' => null,
'next_audit_date' => null,
'last_checkout' => null,
+ 'asset_eol_date' => null
];
}
@@ -352,4 +353,14 @@ class AssetFactory extends Factory
{
return $this->state(['requestable' => false]);
}
+
+ public function noPurchaseOrEolDate()
+ {
+ return $this->afterCreating(function (Asset $asset) {
+ $asset->update([
+ 'purchase_date' => null,
+ 'asset_eol_date' => null
+ ]);
+ });
+ }
}
diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php
index 631944190d..eee0da3929 100644
--- a/tests/Feature/Api/Assets/AssetStoreTest.php
+++ b/tests/Feature/Api/Assets/AssetStoreTest.php
@@ -153,7 +153,6 @@ class AssetStoreTest extends TestCase
->assertOk()
->assertStatusMessageIs('success')
->json();
- return $response;
$asset = Asset::find($response['payload']['id']);
$this->assertEquals('2024-01-01', $asset->asset_eol_date);
diff --git a/tests/Feature/Api/Assets/AssetUpdateTest.php b/tests/Feature/Api/Assets/AssetUpdateTest.php
index bd5377efdb..17bb72fa30 100644
--- a/tests/Feature/Api/Assets/AssetUpdateTest.php
+++ b/tests/Feature/Api/Assets/AssetUpdateTest.php
@@ -27,6 +27,16 @@ class AssetUpdateTest extends TestCase
->assertForbidden();
}
+ public function testGivenPermissionUpdateAssetIsAllower()
+
+ {
+ $asset = Asset::factory()->create();
+
+ $this->actingAsForApi(User::factory()->editAssets()->create())
+ ->patchJson(route('api.assets.update', $asset->id))
+ ->assertOk();
+ }
+
public function testAllAssetAttributesAreStored()
{
$asset = Asset::factory()->create();
@@ -89,29 +99,44 @@ class AssetUpdateTest extends TestCase
$this->assertEquals(10, $updatedAsset->warranty_months);
}
- public function testArchivedDepreciateAndPhysicalCanBeNull()
+ public function testAssetEolDateIsCalculatedIfPurchaseDateUpdated()
{
- $model = AssetModel::factory()->ipadModel()->create();
- $status = Statuslabel::factory()->create();
+ $model = AssetModel::factory()->mbp13Model()->create();
$asset = Asset::factory()->create();
$this->settings->enableAutoIncrement();
- $response = $this->actingAsForApi(User::factory()->superuser()->create())
+ $response = $this->actingAsForApi(User::factory()->editAssets()->create())
+ ->patchJson((route('api.assets.update', $asset->id)), [
+ 'model_id' => $model->id,
+ 'purchase_date' => '2021-01-01',
+ ])
+ //->dd()
+ ->assertOk()
+ ->assertStatusMessageIs('success')
+ ->json();
+
+ $this->assertEquals('2024-01-01', $asset->asset_eol_date);
+ }
+
+ public function testAssetEolDateIsNotCalculatedIfPurchaseDateNotSet()
+ {
+ $asset = Asset::factory()->laptopMbp()->noPurchaseOrEolDate()->create();
+
+ $this->settings->enableAutoIncrement();
+
+ $response = $this->actingAsForApi(User::factory()->editAssets()->create())
->patchJson(route('api.assets.update', $asset->id), [
- 'archive' => null,
- 'depreciate' => null,
- 'physical' => null
+ 'name' => 'test asset',
+ 'asset_eol_date' => '2022-01-01'
])
- ->dd()
->assertOk()
->assertStatusMessageIs('success')
->json();
- $asset = Asset::find($response['payload']['id']);
- $this->assertEquals(0, $asset->archived);
- $this->assertEquals(1, $asset->physical);
- $this->assertEquals(0, $asset->depreciate);
+ $asset->refresh();
+
+ $this->assertEquals('2022-01-01', $asset->asset_eol_date);
}
}
\ No newline at end of file