A free open source IT asset/license management system
Log requestable check on checkin/checkout
snipe7fae60d5c3f4
diff --git a/app/Models/Traits/Loggable.php b/app/Models/Traits/Loggable.phpindex ef816cb76a..f866a78812 100644--- a/app/Models/Traits/Loggable.php+++ b/app/Models/Traits/Loggable.php@@ -180,7 +180,7 @@ trait Loggable$changed = [];$array_to_flip = array_keys($fields_array);- $array_to_flip = array_merge($array_to_flip, ['name', 'status_id', 'location_id', 'expected_checkin']);+ $array_to_flip = array_merge($array_to_flip, ['name', 'status_id', 'location_id', 'expected_checkin', 'requestable']);$originalValues = array_intersect_key($originalValues, array_flip($array_to_flip));foreach ($originalValues as $key => $value) {@@ -279,7 +279,7 @@ trait Loggable$changed = [];$array_to_flip = array_keys($fields_array);- $array_to_flip = array_merge($array_to_flip, ['name', 'status_id', 'location_id', 'expected_checkin']);+ $array_to_flip = array_merge($array_to_flip, ['name', 'status_id', 'location_id', 'expected_checkin', 'requestable']);$originalValues = array_intersect_key($originalValues, array_flip($array_to_flip));diff --git a/tests/Feature/Checkins/Ui/AssetCheckinTest.php b/tests/Feature/Checkins/Ui/AssetCheckinTest.phpindex 0419ada295..2ec6958d6a 100644--- a/tests/Feature/Checkins/Ui/AssetCheckinTest.php+++ b/tests/Feature/Checkins/Ui/AssetCheckinTest.php@@ -3,6 +3,7 @@namespace Tests\Feature\Checkins\Ui;use App\Events\CheckoutableCheckedIn;+use App\Models\Actionlog;use App\Models\Asset;use App\Models\CheckoutAcceptance;use App\Models\LicenseSeat;@@ -262,6 +263,21 @@ class AssetCheckinTest extends TestCase]);$this->assertTrue((bool) $asset->fresh()->requestable);++ $log = Actionlog::query()+ ->where('item_type', Asset::class)+ ->where('item_id', $asset->id)+ ->where('action_type', 'checkin from')+ ->latest('id')+ ->first();++ $this->assertNotNull($log);+ $this->assertNotNull($log->log_meta);++ $logMeta = json_decode($log->log_meta, true);+ $this->assertArrayHasKey('requestable', $logMeta);+ $this->assertEquals(0, (int) $logMeta['requestable']['old']);+ $this->assertEquals(1, (int) $logMeta['requestable']['new']);}public function test_checkin_does_not_set_asset_to_requestable_when_status_is_not_deployable()diff --git a/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/AssetCheckoutTest.phpindex a3f0b16826..38ebf93612 100644--- a/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php@@ -4,6 +4,7 @@ namespace Tests\Feature\Checkouts\Ui;use App\Events\CheckoutableCheckedOut;use App\Models\Asset;+use App\Models\Actionlog;use App\Models\CheckoutAcceptance;use App\Models\Company;use App\Models\LicenseSeat;@@ -241,6 +242,8 @@ class AssetCheckoutTest extends TestCasepublic function test_checkout_can_set_asset_to_not_requestable(){+ Event::fakeExcept([CheckoutableCheckedOut::class]);+$asset = Asset::factory()->create(['requestable' => 1]);$targetUser = User::factory()->create();@@ -252,6 +255,21 @@ class AssetCheckoutTest extends TestCase]);$this->assertFalse((bool) $asset->fresh()->requestable);++ $log = Actionlog::query()+ ->where('item_type', Asset::class)+ ->where('item_id', $asset->id)+ ->where('action_type', 'checkout')+ ->latest('id')+ ->first();++ $this->assertNotNull($log);+ $this->assertNotNull($log->log_meta);++ $logMeta = json_decode($log->log_meta, true);+ $this->assertArrayHasKey('requestable', $logMeta);+ $this->assertEquals(1, (int) $logMeta['requestable']['old']);+ $this->assertEquals(0, (int) $logMeta['requestable']['new']);}public function test_last_checkout_uses_current_date_if_not_provided()