mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Set last_audit_date to valid format in StoreAssetRequest
This commit is contained in:
parent
d67b2da064
commit
66ba96d531
|
@ -4,6 +4,7 @@ namespace App\Http\Requests;
|
||||||
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
|
||||||
class StoreAssetRequest extends ImageUploadRequest
|
class StoreAssetRequest extends ImageUploadRequest
|
||||||
|
@ -31,6 +32,7 @@ class StoreAssetRequest extends ImageUploadRequest
|
||||||
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
|
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
|
||||||
'company_id' => $idForCurrentUser,
|
'company_id' => $idForCurrentUser,
|
||||||
'assigned_to' => $assigned_to ?? null,
|
'assigned_to' => $assigned_to ?? null,
|
||||||
|
'last_audit_date' => Carbon::parse($this->input('last_audit_date'))->startOfDay()->format('Y-m-d H:i:s'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,7 @@ class AssetStoreTest extends TestCase
|
||||||
$this->assertEquals('random_string', $asset->asset_tag);
|
$this->assertEquals('random_string', $asset->asset_tag);
|
||||||
$this->assertEquals($userAssigned->id, $asset->assigned_to);
|
$this->assertEquals($userAssigned->id, $asset->assigned_to);
|
||||||
$this->assertTrue($asset->company->is($company));
|
$this->assertTrue($asset->company->is($company));
|
||||||
// I don't see this on the GUI side either, but it's in the docs so I'm guessing that's a mistake? It wasn't in the controller.
|
$this->assertEquals('2023-09-03 00:00:00', $asset->last_audit_date->format('Y-m-d H:i:s'));
|
||||||
// $this->assertEquals('2023-09-03', $asset->last_audit_date);
|
|
||||||
$this->assertTrue($asset->location->is($location));
|
$this->assertTrue($asset->location->is($location));
|
||||||
$this->assertTrue($asset->model->is($model));
|
$this->assertTrue($asset->model->is($model));
|
||||||
$this->assertEquals('A New Asset', $asset->name);
|
$this->assertEquals('A New Asset', $asset->name);
|
||||||
|
@ -82,6 +81,22 @@ class AssetStoreTest extends TestCase
|
||||||
$this->assertEquals(10, $asset->warranty_months);
|
$this->assertEquals(10, $asset->warranty_months);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetsLastAuditDateToMidnightOfProvidedDate()
|
||||||
|
{
|
||||||
|
$response = $this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
|
->postJson(route('api.assets.store'), [
|
||||||
|
'last_audit_date' => '2023-09-03 12:23:45',
|
||||||
|
'asset_tag' => '1234',
|
||||||
|
'model_id' => AssetModel::factory()->create()->id,
|
||||||
|
'status_id' => Statuslabel::factory()->create()->id,
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertStatusMessageIs('success');
|
||||||
|
|
||||||
|
$asset = Asset::find($response['payload']['id']);
|
||||||
|
$this->assertEquals('00:00:00', $asset->last_audit_date->format('H:i:s'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testArchivedDepreciateAndPhysicalCanBeNull()
|
public function testArchivedDepreciateAndPhysicalCanBeNull()
|
||||||
{
|
{
|
||||||
$model = AssetModel::factory()->ipadModel()->create();
|
$model = AssetModel::factory()->ipadModel()->create();
|
||||||
|
|
Loading…
Reference in a new issue