checkout on store tests almost done

This commit is contained in:
spencerrlongg 2023-11-28 22:11:20 -06:00
parent 15d11f7f4e
commit c886fb555b
3 changed files with 60 additions and 2 deletions

View file

@ -20,9 +20,18 @@ class StoreAssetRequest extends ImageUploadRequest
public function prepareForValidation(): void public function prepareForValidation(): void
{ {
if ($this->has('assigned_user')) {
$assigned_to = $this->assigned_user;
} elseif ($this->has('assigned_location')) {
$assigned_to = $this->assigned_location;
} elseif ($this->has('assigned_asset')) {
$assigned_to = $this->assigned_asset;
}
$this->merge([ $this->merge([
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(), 'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
'company_id' => Company::getIdForCurrentUser($this->company_id), 'company_id' => Company::getIdForCurrentUser($this->company_id),
'assigned_to' => $assigned_to ?? null,
]); ]);
} }

View file

@ -109,7 +109,7 @@ class Asset extends Depreciable
'byod' => 'nullable|boolean', 'byod' => 'nullable|boolean',
'order_number' => 'nullable|string|max:191', 'order_number' => 'nullable|string|max:191',
'notes' => 'nullable|string|max:65535', 'notes' => 'nullable|string|max:65535',
'assigned_to' => 'nullable|integer|exists:users,id', 'assigned_to' => 'nullable|integer',
'requestable' => 'nullable|boolean', 'requestable' => 'nullable|boolean',
]; ];

View file

@ -253,7 +253,6 @@ class AssetStoreTest extends TestCase
$response = $this->actingAsForApi($user) $response = $this->actingAsForApi($user)
->postJson(route('api.assets.store'), [ ->postJson(route('api.assets.store'), [
'assigned_user' => $userAssigned->id, 'assigned_user' => $userAssigned->id,
'assigned_to' => $userAssigned->id, // why are both of these needed? documentation says only assigned_user
'model_id' => $model->id, 'model_id' => $model->id,
'status_id' => $status->id, 'status_id' => $status->id,
]) ])
@ -266,4 +265,54 @@ class AssetStoreTest extends TestCase
$this->assertTrue($asset->adminuser->is($user)); $this->assertTrue($asset->adminuser->is($user));
$this->assertTrue($asset->assignedTo->is($userAssigned)); $this->assertTrue($asset->assignedTo->is($userAssigned));
} }
public function testAnAssetCanBeCheckedOutToLocationOnStore()
{
$model = AssetModel::factory()->create();
$status = Statuslabel::factory()->create();
$location = Location::factory()->create();
$user = User::factory()->createAssets()->create();
$this->settings->enableAutoIncrement();
$response = $this->actingAsForApi($user)
->postJson(route('api.assets.store'), [
'assigned_location' => $location->id,
'model_id' => $model->id,
'status_id' => $status->id,
])
->assertOk()
->assertStatusMessageIs('success')
->json();
$asset = Asset::find($response['payload']['id']);
$this->assertTrue($asset->adminuser->is($user));
$this->assertTrue($asset->location->is($location));
}
public function testAnAssetCanBeCheckedOutToAssetOnStore()
{
$model = AssetModel::factory()->create();
$status = Statuslabel::factory()->create();
$asset = Asset::factory()->create();
$user = User::factory()->createAssets()->create();
$this->settings->enableAutoIncrement();
$response = $this->actingAsForApi($user)
->postJson(route('api.assets.store'), [
'assigned_asset' => $asset->id,
'model_id' => $model->id,
'status_id' => $status->id,
])
->assertOk()
->assertStatusMessageIs('success')
->json();
$apiAsset = Asset::find($response['payload']['id']);
$this->assertTrue($apiAsset->adminuser->is($user));
$this->assertTrue($apiAsset->assignedAssets()->is($asset)); //todo: figure this out
}
} }