most tests now passing, still one broken

This commit is contained in:
spencerrlongg 2024-03-19 19:47:26 -05:00
parent c0110e7f29
commit 1e810d2426
2 changed files with 12 additions and 13 deletions

View file

@ -629,14 +629,12 @@ class AssetsController extends Controller
// this is _always_ filled now, see UpdateAssetRequest
// i'm leaving it like this for now, but when would we ever want model_id to be `null`??
// it actually breaks at the model validation if it gets to null...
($request->validated()['model_id']) ?
($request->has('model_id')) ?
$asset->model()->associate(AssetModel::find($request->validated()['model_id'])) : null;
//($request->validated()['rtd_location_id']) ?
// $asset->location_id = $request->validated()['rtd_location_id'] : '';
//($request->validated()['company_id']) ?
// $asset->company_id = Company::getIdForCurrentUser($request->validated()['company_id']) : '';
//($request->validated()['rtd_location_id']) ?
// $asset->location_id = $request->validated()['rtd_location_id'] : null;
($request->has('company_id')) ?
$asset->company_id = Company::getIdForCurrentUser($request->validated()['company_id']) : null;
($request->has('rtd_location_id')) ?
$asset->location_id = $request->validated()['rtd_location_id'] : null;
/**
* this is here just legacy reasons. Api\AssetController

View file

@ -29,13 +29,15 @@ class AssetUpdateTest extends TestCase
->assertForbidden();
}
public function testGivenPermissionUpdateAssetIsAllower()
public function testGivenPermissionUpdateAssetIsAllowed()
{
$asset = Asset::factory()->create();
$this->actingAsForApi(User::factory()->editAssets()->create())
->patchJson(route('api.assets.update', $asset->id))
->patchJson(route('api.assets.update', $asset->id), [
'name' => 'test'
])
->assertOk();
}
@ -103,21 +105,20 @@ class AssetUpdateTest extends TestCase
public function testAssetEolDateIsCalculatedIfPurchaseDateUpdated()
{
$model = AssetModel::factory()->mbp13Model()->create();
$asset = Asset::factory()->create();
$asset = Asset::factory()->laptopMbp()->create();
$this->settings->enableAutoIncrement();
$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();
$asset->refresh();
$this->assertEquals('2024-01-01', $asset->asset_eol_date);
}