From 99741db645c22612e64c738140527f2aeaa43cc4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 24 Jul 2024 11:24:30 -0700 Subject: [PATCH 01/11] adds status labels to confirmation emails --- app/Http/Controllers/Account/AcceptanceController.php | 2 ++ app/Notifications/AcceptanceAssetAcceptedNotification.php | 2 ++ app/Notifications/AcceptanceAssetDeclinedNotification.php | 2 ++ app/Notifications/CheckoutAssetNotification.php | 1 + .../views/notifications/markdown/asset-acceptance.blade.php | 3 +++ .../views/notifications/markdown/checkout-asset.blade.php | 3 +++ 6 files changed, 13 insertions(+) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 2c9d29fc16..cabd056332 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -218,6 +218,7 @@ class AcceptanceController extends Controller 'item_tag' => $item->asset_tag, 'item_model' => $display_model, 'item_serial' => $item->serial, + 'item_status' => $item->assetstatus->name ?: '', 'eula' => $item->getEula(), 'note' => $request->input('note'), 'check_out_date' => Carbon::parse($acceptance->created_at)->format('Y-m-d'), @@ -308,6 +309,7 @@ class AcceptanceController extends Controller 'item_tag' => $item->asset_tag, 'item_model' => $display_model, 'item_serial' => $item->serial, + 'item_status' => $item->assetstatus->name ?: '', 'note' => $request->input('note'), 'declined_date' => Carbon::parse($acceptance->declined_at)->format('Y-m-d'), 'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null, diff --git a/app/Notifications/AcceptanceAssetAcceptedNotification.php b/app/Notifications/AcceptanceAssetAcceptedNotification.php index db1555b574..7798dbc0d5 100644 --- a/app/Notifications/AcceptanceAssetAcceptedNotification.php +++ b/app/Notifications/AcceptanceAssetAcceptedNotification.php @@ -24,6 +24,7 @@ class AcceptanceAssetAcceptedNotification extends Notification $this->item_tag = $params['item_tag']; $this->item_model = $params['item_model']; $this->item_serial = $params['item_serial']; + $this->item_status = $params['item_status']; $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'date', false); $this->assigned_to = $params['assigned_to']; $this->note = $params['note']; @@ -65,6 +66,7 @@ class AcceptanceAssetAcceptedNotification extends Notification 'item_tag' => $this->item_tag, 'item_model' => $this->item_model, 'item_serial' => $this->item_serial, + 'item_status' => $this->item_status, 'note' => $this->note, 'accepted_date' => $this->accepted_date, 'assigned_to' => $this->assigned_to, diff --git a/app/Notifications/AcceptanceAssetDeclinedNotification.php b/app/Notifications/AcceptanceAssetDeclinedNotification.php index abdfbbf0c0..0a9d6c211f 100644 --- a/app/Notifications/AcceptanceAssetDeclinedNotification.php +++ b/app/Notifications/AcceptanceAssetDeclinedNotification.php @@ -24,6 +24,7 @@ class AcceptanceAssetDeclinedNotification extends Notification $this->item_tag = $params['item_tag']; $this->item_model = $params['item_model']; $this->item_serial = $params['item_serial']; + $this->item_status = $params['item_status']; $this->declined_date = Helper::getFormattedDateObject($params['declined_date'], 'date', false); $this->note = $params['note']; $this->assigned_to = $params['assigned_to']; @@ -63,6 +64,7 @@ class AcceptanceAssetDeclinedNotification extends Notification 'item_tag' => $this->item_tag, 'item_model' => $this->item_model, 'item_serial' => $this->item_serial, + 'item_status' => $this->item_status, 'note' => $this->note, 'declined_date' => $this->declined_date, 'assigned_to' => $this->assigned_to, diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 1c8c901b52..7c9b6b2a8e 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -209,6 +209,7 @@ public function toGoogleChat() [ 'item' => $this->item, 'admin' => $this->admin, + 'status' => $this->item->assetstatus(), 'note' => $this->note, 'target' => $this->target, 'fields' => $fields, diff --git a/resources/views/notifications/markdown/asset-acceptance.blade.php b/resources/views/notifications/markdown/asset-acceptance.blade.php index 93292375a5..037e24c139 100644 --- a/resources/views/notifications/markdown/asset-acceptance.blade.php +++ b/resources/views/notifications/markdown/asset-acceptance.blade.php @@ -16,6 +16,9 @@ @if (isset($note)) | **{{ trans('general.notes') }}** | {{ $note }} | @endif +@if (isset($item_status)) + | **{{ trans('general.status') }}** | {{ $item_status }} | +@endif @if ((isset($item_tag)) && ($item_tag!='')) | **{{ trans('mail.asset_tag') }}** | {{ $item_tag }} | @endif diff --git a/resources/views/notifications/markdown/checkout-asset.blade.php b/resources/views/notifications/markdown/checkout-asset.blade.php index 4646cef482..b76e3e66a3 100644 --- a/resources/views/notifications/markdown/checkout-asset.blade.php +++ b/resources/views/notifications/markdown/checkout-asset.blade.php @@ -31,6 +31,9 @@ @if (isset($last_checkout)) | **{{ trans('mail.checkout_date') }}** | {{ $last_checkout }} | @endif +@if (isset($status)) + | **{{ trans('general.status') }}** | {{ $status }} | +@endif @if ((isset($expected_checkin)) && ($expected_checkin!='')) | **{{ trans('mail.expecting_checkin_date') }}** | {{ $expected_checkin }} | @endif From eb6f330e672429d9b40a168c493557048bd35aac Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 30 Jul 2024 09:38:39 -0700 Subject: [PATCH 02/11] adds status to check in and out --- app/Notifications/CheckinAssetNotification.php | 1 + app/Notifications/CheckoutAssetNotification.php | 2 +- resources/views/notifications/markdown/checkin-asset.blade.php | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 54b96777fe..50745b1b27 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -162,6 +162,7 @@ class CheckinAssetNotification extends Notification $message = (new MailMessage)->markdown('notifications.markdown.checkin-asset', [ 'item' => $this->item, + 'status' => $this->item->assetstatus->name ?: '', 'admin' => $this->admin, 'note' => $this->note, 'target' => $this->target, diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 7c9b6b2a8e..352b088dba 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -209,7 +209,7 @@ public function toGoogleChat() [ 'item' => $this->item, 'admin' => $this->admin, - 'status' => $this->item->assetstatus(), + 'status' => $this->item->assetstatus->name ?: '', 'note' => $this->note, 'target' => $this->target, 'fields' => $fields, diff --git a/resources/views/notifications/markdown/checkin-asset.blade.php b/resources/views/notifications/markdown/checkin-asset.blade.php index 74a4381707..fd9afbd286 100644 --- a/resources/views/notifications/markdown/checkin-asset.blade.php +++ b/resources/views/notifications/markdown/checkin-asset.blade.php @@ -31,6 +31,9 @@ @if (isset($last_checkout)) | **{{ trans('mail.checkout_date') }}** | {{ $last_checkout }} | @endif +@if (isset($status)) + | **{{ trans('general.status') }}** | {{ $status }} | +@endif @foreach($fields as $field) @if (($item->{ $field->db_column_name() }!='') && ($field->show_in_email) && ($field->field_encrypted=='0')) | **{{ $field->name }}** | {{ $item->{ $field->db_column_name() } }} | From b6cac4baaef3f52be8c18f6068f3f1cf70caec9d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 31 Jul 2024 12:03:36 -0700 Subject: [PATCH 03/11] corrects ? usage --- app/Http/Controllers/Account/AcceptanceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index cabd056332..207932556c 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -309,7 +309,7 @@ class AcceptanceController extends Controller 'item_tag' => $item->asset_tag, 'item_model' => $display_model, 'item_serial' => $item->serial, - 'item_status' => $item->assetstatus->name ?: '', + 'item_status' => $item->assetstatus?->name, 'note' => $request->input('note'), 'declined_date' => Carbon::parse($acceptance->declined_at)->format('Y-m-d'), 'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null, From 854903805b54fb4d0d283f7de50c908b7e71386a Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 31 Jul 2024 12:16:41 -0700 Subject: [PATCH 04/11] one more spot --- app/Http/Controllers/Account/AcceptanceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 207932556c..6d84861fb0 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -218,7 +218,7 @@ class AcceptanceController extends Controller 'item_tag' => $item->asset_tag, 'item_model' => $display_model, 'item_serial' => $item->serial, - 'item_status' => $item->assetstatus->name ?: '', + 'item_status' => $item->assetstatus?->name, 'eula' => $item->getEula(), 'note' => $request->input('note'), 'check_out_date' => Carbon::parse($acceptance->created_at)->format('Y-m-d'), From ae4f278df15b1edf366f48dde11c6436e4777bd2 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 1 Aug 2024 11:13:20 -0700 Subject: [PATCH 05/11] edited terenaries on notifs --- app/Notifications/CheckinAssetNotification.php | 2 +- app/Notifications/CheckoutAssetNotification.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 50745b1b27..77cd6d9b5a 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -162,7 +162,7 @@ class CheckinAssetNotification extends Notification $message = (new MailMessage)->markdown('notifications.markdown.checkin-asset', [ 'item' => $this->item, - 'status' => $this->item->assetstatus->name ?: '', + 'status' => $this->item->assetstatus?->name, 'admin' => $this->admin, 'note' => $this->note, 'target' => $this->target, diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 352b088dba..5ebde7e4f7 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -209,7 +209,7 @@ public function toGoogleChat() [ 'item' => $this->item, 'admin' => $this->admin, - 'status' => $this->item->assetstatus->name ?: '', + 'status' => $this->item->assetstatus?->name, 'note' => $this->note, 'target' => $this->target, 'fields' => $fields, From 8af4126de10e4298354a54b4234a64c125cf6adb Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 13 Aug 2024 10:21:33 -0700 Subject: [PATCH 06/11] removed indent from blades --- .../views/notifications/markdown/asset-acceptance.blade.php | 2 +- resources/views/notifications/markdown/checkin-asset.blade.php | 2 +- resources/views/notifications/markdown/checkout-asset.blade.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/notifications/markdown/asset-acceptance.blade.php b/resources/views/notifications/markdown/asset-acceptance.blade.php index 037e24c139..c5c2a2fa27 100644 --- a/resources/views/notifications/markdown/asset-acceptance.blade.php +++ b/resources/views/notifications/markdown/asset-acceptance.blade.php @@ -17,7 +17,7 @@ | **{{ trans('general.notes') }}** | {{ $note }} | @endif @if (isset($item_status)) - | **{{ trans('general.status') }}** | {{ $item_status }} | +| **{{ trans('general.status') }}** | {{ $item_status }} | @endif @if ((isset($item_tag)) && ($item_tag!='')) | **{{ trans('mail.asset_tag') }}** | {{ $item_tag }} | diff --git a/resources/views/notifications/markdown/checkin-asset.blade.php b/resources/views/notifications/markdown/checkin-asset.blade.php index fd9afbd286..523ba66aa1 100644 --- a/resources/views/notifications/markdown/checkin-asset.blade.php +++ b/resources/views/notifications/markdown/checkin-asset.blade.php @@ -32,7 +32,7 @@ | **{{ trans('mail.checkout_date') }}** | {{ $last_checkout }} | @endif @if (isset($status)) - | **{{ trans('general.status') }}** | {{ $status }} | +| **{{ trans('general.status') }}** | {{ $status }} | @endif @foreach($fields as $field) @if (($item->{ $field->db_column_name() }!='') && ($field->show_in_email) && ($field->field_encrypted=='0')) diff --git a/resources/views/notifications/markdown/checkout-asset.blade.php b/resources/views/notifications/markdown/checkout-asset.blade.php index b76e3e66a3..9b5fc26dc2 100644 --- a/resources/views/notifications/markdown/checkout-asset.blade.php +++ b/resources/views/notifications/markdown/checkout-asset.blade.php @@ -32,7 +32,7 @@ | **{{ trans('mail.checkout_date') }}** | {{ $last_checkout }} | @endif @if (isset($status)) - | **{{ trans('general.status') }}** | {{ $status }} | +| **{{ trans('general.status') }}** | {{ $status }} | @endif @if ((isset($expected_checkin)) && ($expected_checkin!='')) | **{{ trans('mail.expecting_checkin_date') }}** | {{ $expected_checkin }} | From 321839e074b8e67daf935721cf38b784e469f3b1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 13 Aug 2024 12:14:56 -0700 Subject: [PATCH 07/11] Fix namespace --- tests/Feature/Console/FixupAssignedToAssignedTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/Console/FixupAssignedToAssignedTypeTest.php b/tests/Feature/Console/FixupAssignedToAssignedTypeTest.php index d4420145d2..38184511f9 100644 --- a/tests/Feature/Console/FixupAssignedToAssignedTypeTest.php +++ b/tests/Feature/Console/FixupAssignedToAssignedTypeTest.php @@ -1,6 +1,6 @@ Date: Tue, 13 Aug 2024 12:16:08 -0700 Subject: [PATCH 08/11] Update tests https://masteringlaravel.io/daily/2024-02-09-watch-out-for-this-when-testing-artisan-commands --- .../FixupAssignedToAssignedTypeTest.php | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/tests/Feature/Console/FixupAssignedToAssignedTypeTest.php b/tests/Feature/Console/FixupAssignedToAssignedTypeTest.php index 38184511f9..2b5f9b415d 100644 --- a/tests/Feature/Console/FixupAssignedToAssignedTypeTest.php +++ b/tests/Feature/Console/FixupAssignedToAssignedTypeTest.php @@ -10,7 +10,6 @@ class FixupAssignedToAssignedTypeTest extends TestCase { public function testEmptyAssignedType() { - $this->markTestIncomplete(); $asset = Asset::factory()->create(); $user = User::factory()->create(); $admin = User::factory()->admin()->create(); @@ -18,15 +17,10 @@ class FixupAssignedToAssignedTypeTest extends TestCase $asset->checkOut($user, $admin); $asset->assigned_type=null; //blank out the assigned type $asset->save(); - print "Okay we set everything up~!!!\n"; - $output = $this->artisan('snipeit:assigned-to-fixup --debug')->assertExitCode(0); - print "artisan ran!\n"; - dump($output); - $asset = Asset::find($asset->id); - print "\n we refreshed the asset?"; - dump($asset); - $this->assertEquals(User::class, $asset->assigned_type); + $this->artisan('snipeit:assigned-to-fixup --debug')->assertExitCode(0); + + $this->assertEquals(User::class, $asset->fresh()->assigned_type); } public function testInvalidAssignedTo() @@ -37,21 +31,15 @@ class FixupAssignedToAssignedTypeTest extends TestCase $admin = User::factory()->admin()->create(); $asset->checkOut($user, $admin); -// $asset->checkIn($user, $admin); //no such method btw $asset->assigned_type=null; $asset->assigned_to=null; $asset->saveOrFail(); //*should* generate a 'checkin'? $asset->assigned_to=$user->id; //incorrectly mark asset as partially checked-out $asset->saveOrFail(); - print "Okay we set everything up for test TWO~!!!\n"; - $output = $this->artisan('snipeit:assigned-to-fixup --debug')->assertExitCode(0); - print "artisan ran TWO!\n"; - dump($output); - $asset = Asset::find($asset->id); - print "\n we refreshed the asset?"; - dump($asset); - $this->assertNull($asset->assigned_to); + $this->artisan('snipeit:assigned-to-fixup --debug')->assertExitCode(0); + + $this->assertNull($asset->fresh()->assigned_to); } } From 3f8ac59f4cfd812149c68aa65866891ec8b37e40 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 13 Aug 2024 15:31:16 -0700 Subject: [PATCH 09/11] Reference the entry in the components_assets table --- .../Checkins/Ui/ComponentCheckinTest.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/Feature/Checkins/Ui/ComponentCheckinTest.php b/tests/Feature/Checkins/Ui/ComponentCheckinTest.php index 1213d65252..06754d33c0 100644 --- a/tests/Feature/Checkins/Ui/ComponentCheckinTest.php +++ b/tests/Feature/Checkins/Ui/ComponentCheckinTest.php @@ -4,27 +4,35 @@ namespace Tests\Feature\Checkins\Ui; use App\Models\Component; use App\Models\User; +use Illuminate\Support\Facades\DB; use Tests\TestCase; class ComponentCheckinTest extends TestCase { public function testCheckingInComponentRequiresCorrectPermission() { + $component = Component::factory()->checkedOutToAsset()->create(); + + $componentAsset = DB::table('components_assets')->where('component_id', $component->id)->first(); + $this->actingAs(User::factory()->create()) ->post(route('components.checkin.store', [ - 'componentID' => Component::factory()->checkedOutToAsset()->create()->id, + 'componentID' => $componentAsset->id, ])) ->assertForbidden(); } - public function testComponentCheckinPagePostIsRedirectedIfRedirectSelectionIsIndex() { $component = Component::factory()->checkedOutToAsset()->create(); + $componentAsset = DB::table('components_assets')->where('component_id', $component->id)->first(); + $this->actingAs(User::factory()->admin()->create()) ->from(route('components.index')) - ->post(route('components.checkin.store', $component), [ + ->post(route('components.checkin.store', [ + 'componentID' => $componentAsset->id, + ]), [ 'redirect_option' => 'index', 'checkin_qty' => 1, ]) @@ -36,9 +44,13 @@ class ComponentCheckinTest extends TestCase { $component = Component::factory()->checkedOutToAsset()->create(); + $componentAsset = DB::table('components_assets')->where('component_id', $component->id)->first(); + $this->actingAs(User::factory()->admin()->create()) ->from(route('components.index')) - ->post(route('components.checkin.store', $component), [ + ->post(route('components.checkin.store', [ + 'componentID' => $componentAsset->id, + ]), [ 'redirect_option' => 'item', 'checkin_qty' => 1, ]) @@ -46,6 +58,4 @@ class ComponentCheckinTest extends TestCase ->assertSessionHasNoErrors() ->assertRedirect(route('components.show', ['component' => $component->id])); } - - } From 371afde52dde371ba7468377475d95b3293bfcc0 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Aug 2024 09:52:25 +0100 Subject: [PATCH 10/11] Bulk edit asset name Signed-off-by: snipe --- .../Assets/BulkAssetsController.php | 16 ++++++++++---- resources/views/hardware/bulk.blade.php | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 287bc0611b..d58edbacab 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -227,7 +227,8 @@ class BulkAssetsController extends Controller * its checkout status. */ - if (($request->filled('purchase_date')) + if (($request->filled('name')) + || ($request->filled('purchase_date')) || ($request->filled('expected_checkin')) || ($request->filled('purchase_cost')) || ($request->filled('supplier_id')) @@ -239,6 +240,7 @@ class BulkAssetsController extends Controller || ($request->filled('status_id')) || ($request->filled('model_id')) || ($request->filled('next_audit_date')) + || ($request->filled('null_name')) || ($request->filled('null_purchase_date')) || ($request->filled('null_expected_checkin_date')) || ($request->filled('null_next_audit_date')) @@ -251,13 +253,14 @@ class BulkAssetsController extends Controller $this->update_array = []; /** - * Leave out model_id and status here because we do math on that later. We have to do some extra - * validation and checks on those two. + * Leave out model_id and status here because we do math on that later. We have to do some + * extra validation and checks on those two. * * It's tempting to make these match the request check above, but some of these values require * extra work to make sure the data makes sense. */ - $this->conditionallyAddItem('purchase_date') + $this->conditionallyAddItem('name') + ->conditionallyAddItem('purchase_date') ->conditionallyAddItem('expected_checkin') ->conditionallyAddItem('order_number') ->conditionallyAddItem('requestable') @@ -271,6 +274,11 @@ class BulkAssetsController extends Controller /** * Blank out fields that were requested to be blanked out via checkbox */ + if ($request->input('null_name')=='1') { + + $this->update_array['name'] = null; + } + if ($request->input('null_purchase_date')=='1') { $this->update_array['purchase_date'] = null; } diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 371f0c2549..248b18e400 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -35,6 +35,27 @@ @endif + +
+ +
+
+ +
+ {!! $errors->first('name', '') !!} +
+
+ +
+
+ +
From 4b690e8e1f273516ef0fadd98af9f5911997eac9 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Aug 2024 10:01:56 +0100 Subject: [PATCH 11/11] Updated test to check for nulling Signed-off-by: snipe --- .../Feature/Assets/Ui/BulkEditAssetsTest.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/Feature/Assets/Ui/BulkEditAssetsTest.php b/tests/Feature/Assets/Ui/BulkEditAssetsTest.php index 76d0a9c345..44e9052482 100644 --- a/tests/Feature/Assets/Ui/BulkEditAssetsTest.php +++ b/tests/Feature/Assets/Ui/BulkEditAssetsTest.php @@ -57,6 +57,7 @@ class BulkEditAssetsTest extends TestCase $company1 = Company::factory()->create(); $company2 = Company::factory()->create(); $assets = Asset::factory()->count(10)->create([ + 'name' => 'Old Asset Name', 'purchase_date' => '2023-01-01', 'expected_checkin' => '2023-01-01', 'status_id' => $status1->id, @@ -77,6 +78,7 @@ class BulkEditAssetsTest extends TestCase // submits the ids and new values for each attribute $this->actingAs(User::factory()->editAssets()->create())->post(route('hardware/bulksave'), [ 'ids' => $id_array, + 'name' => 'New Asset Name', 'purchase_date' => '2024-01-01', 'expected_checkin' => '2024-01-01', 'status_id' => $status2->id, @@ -97,6 +99,7 @@ class BulkEditAssetsTest extends TestCase $this->assertEquals('2024-01-01', $asset->purchase_date->format('Y-m-d')); $this->assertEquals('2024-01-01', $asset->expected_checkin->format('Y-m-d')); $this->assertEquals($status2->id, $asset->status_id); + $this->assertEquals('New Asset Name', $asset->name); $this->assertEquals($model2->id, $asset->model_id); $this->assertEquals(5678.92, $asset->purchase_cost); $this->assertEquals($supplier2->id, $asset->supplier_id); @@ -109,6 +112,59 @@ class BulkEditAssetsTest extends TestCase }); } + public function testBulkEditAssetsNullsOutFieldsIfSelected() + { + // sets up all needed models and attributes on the assets + // this test does not deal with custom fields - will be dealt with in separate cases + $status1 = Statuslabel::factory()->create(); + $status2 = Statuslabel::factory()->create(); + $model1 = AssetModel::factory()->create(); + $model2 = AssetModel::factory()->create(); + $supplier1 = Supplier::factory()->create(); + $supplier2 = Supplier::factory()->create(); + $company1 = Company::factory()->create(); + $company2 = Company::factory()->create(); + $assets = Asset::factory()->count(10)->create([ + 'name' => 'Old Asset Name', + 'purchase_date' => '2023-01-01', + 'expected_checkin' => '2023-01-01', + 'status_id' => $status1->id, + 'model_id' => $model1->id, + // skipping locations on this test, it deserves it's own test + 'purchase_cost' => 1234.90, + 'supplier_id' => $supplier1->id, + 'company_id' => $company1->id, + 'order_number' => '123456', + 'warranty_months' => 24, + 'next_audit_date' => '2024-06-01', + 'requestable' => false + ]); + + // gets the ids together to submit to the endpoint + $id_array = $assets->pluck('id')->toArray(); + + // submits the ids and new values for each attribute + $this->actingAs(User::factory()->editAssets()->create())->post(route('hardware/bulksave'), [ + 'ids' => $id_array, + 'null_name' => '1', + 'null_purchase_date' => '1', + 'null_expected_checkin_date' => '1', + 'null_next_audit_date' => '1', + 'status_id' => $status2->id, + 'model_id' => $model2->id, + ]) + ->assertStatus(302) + ->assertSessionHasNoErrors(); + + // asserts that each asset has the updated values + Asset::findMany($id_array)->each(function (Asset $asset) use ($status2, $model2, $supplier2, $company2) { + $this->assertNull($asset->name); + $this->assertNull($asset->purchase_date); + $this->assertNull($asset->expected_checkin); + $this->assertNull($asset->next_audit_date); + }); + } + public function testBulkEditAssetsAcceptsAndUpdatesUnencryptedCustomFields() { $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');