buncha progress

This commit is contained in:
spencerrlongg 2024-03-19 15:34:59 -05:00
parent f6ab0f8f46
commit 86ab880c90
3 changed files with 49 additions and 14 deletions

View file

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

View file

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

View file

@ -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())
->patchJson(route('api.assets.update', $asset->id), [
'archive' => null,
'depreciate' => null,
'physical' => null
$response = $this->actingAsForApi(User::factory()->editAssets()->create())
->patchJson((route('api.assets.update', $asset->id)), [
'model_id' => $model->id,
'purchase_date' => '2021-01-01',
])
->dd()
//->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);
$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), [
'name' => 'test asset',
'asset_eol_date' => '2022-01-01'
])
->assertOk()
->assertStatusMessageIs('success')
->json();
$asset->refresh();
$this->assertEquals('2022-01-01', $asset->asset_eol_date);
}
}