mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 21:54:14 -08:00
Merge pull request #14486 from marcusmoore/bug/sc-25139
Fixes `last_audit_date` not being stored via API correctly
This commit is contained in:
commit
83ef7c6fe8
|
@ -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
|
||||||
|
@ -27,6 +28,12 @@ class StoreAssetRequest extends ImageUploadRequest
|
||||||
? Company::getIdForCurrentUser($this->company_id)
|
? Company::getIdForCurrentUser($this->company_id)
|
||||||
: $this->company_id;
|
: $this->company_id;
|
||||||
|
|
||||||
|
if ($this->input('last_audit_date')) {
|
||||||
|
$this->merge([
|
||||||
|
'last_audit_date' => Carbon::parse($this->input('last_audit_date'))->startOfDay()->format('Y-m-d H:i:s'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->merge([
|
$this->merge([
|
||||||
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
|
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
|
||||||
'company_id' => $idForCurrentUser,
|
'company_id' => $idForCurrentUser,
|
||||||
|
|
|
@ -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,38 @@ 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 testLastAuditDateCanBeNull()
|
||||||
|
{
|
||||||
|
$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->assertNull($asset->last_audit_date);
|
||||||
|
}
|
||||||
|
|
||||||
public function testArchivedDepreciateAndPhysicalCanBeNull()
|
public function testArchivedDepreciateAndPhysicalCanBeNull()
|
||||||
{
|
{
|
||||||
$model = AssetModel::factory()->ipadModel()->create();
|
$model = AssetModel::factory()->ipadModel()->create();
|
||||||
|
|
Loading…
Reference in a new issue