diff --git a/tests/Feature/Assets/Api/CheckinCheckoutCounters.php b/tests/Feature/Assets/Api/CheckinCheckoutCounters.php new file mode 100644 index 000000000000..82309586e0d8 --- /dev/null +++ b/tests/Feature/Assets/Api/CheckinCheckoutCounters.php @@ -0,0 +1,81 @@ +superuser()->create(); + + //make a user + $user = User::factory()->create(); + + //need a model for the asset + $model = AssetModel::factory()->create(); + + //need a status for the asset, too + $status = Statuslabel::factory()->readyToDeploy()->create(); + + + //make an asset using the API (this is for the API after all!) + $response = $this->actingAsForApi($admin) + ->postJson(route('api.assets.store'), [ + 'asset_tag' => 'random_string', + 'model_id' => $model->id, + 'status_id' => $status->id, + ])->assertOk() + ->assertStatusMessageIs('success') + ->json(); + \Log::error(print_r($response, true)); + + //check the counters + $asset = Asset::find($response['payload']['id']); + $this->assertEquals(0, $asset->checkin_counter); + $this->assertEquals(0, $asset->checkout_counter); + + //do a checkout + $this->actingAsForApi($admin) + ->postJson(route('api.asset.checkout', $asset), [ + 'checkout_to_type' => 'user', + 'assigned_user' => $user->id, + 'checkout_at' => '2024-04-01', + 'expected_checkin' => '2024-04-08', + 'name' => 'Changed Name', + 'note' => 'Here is a cool note!', + ]) + ->assertOk(); + + $asset->refresh(); + //check the counters. both. + $this->assertEquals(0, $asset->checkin_counter); + $this->assertEquals(1, $asset->checkout_counter); //why does _this_ fail?! + + //do a checkin + $this->actingAsForApi(User::factory()->checkinAssets()->create()) + ->postJson(route('api.asset.checkin', $asset), [ + 'name' => 'Changed Name', + 'status_id' => $status->id, + ]) + ->assertOk(); + + //check the counters, again. + $asset->refresh(); + $this->assertEquals(1, $asset->checkin_counter); //wait, _this_ fails too?! WTH? + $this->assertEquals(1, $asset->checkout_counter); //okay, _nothing_ works. Now I'm confused. + } +} diff --git a/tests/Feature/Assets/Ui/CheckinCheckoutCounters.php b/tests/Feature/Assets/Ui/CheckinCheckoutCounters.php new file mode 100644 index 000000000000..cd4faeaad972 --- /dev/null +++ b/tests/Feature/Assets/Ui/CheckinCheckoutCounters.php @@ -0,0 +1,65 @@ +admin()->create(); + $user = User::factory()->create(); + + // create an asset using the GUI + $this->actingAs($admin) + ->post(route('hardware.store'), [ + 'asset_tags' => ['1' => '1234'], + 'model_id' => AssetModel::factory()->create()->id, + 'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id, + ])->assertRedirect(); + + $asset = Asset::where('asset_tag', '1234')->sole(); + + //ensure counters are initialized properly + $this->assertEquals(0,$asset->checkout_counter); + $this->assertEquals(0,$asset->checkin_counter); + + //perform a checkout + $this->actingAs($admin) + ->post(route('hardware.checkout.store', $asset), [ + 'checkout_to_type' => 'user', + // overwrite the value from the default fields set above + 'assigned_user' => (string) $user->id, + 'name' => 'Changed Name', + 'checkout_at' => '2024-03-18', + 'expected_checkin' => '2024-03-28', + 'note' => 'An awesome note', + ])->assertRedirect()->assertSessionHasNoErrors(); + + $asset->refresh(); +// dump($asset); + $this->assertEquals(1,$asset->checkout_counter); + $this->assertEquals(0,$asset->checkin_counter); + + //perform a check-in + $this->actingAs($admin) + ->post( + route('hardware.checkin.store', [$asset]), + [ + 'name' => 'Changed Name Again', + ], + )->assertRedirect()->assertSessionHasNoErrors(); + + $asset->refresh(); +// dump($asset); + $this->assertEquals(1,$asset->checkout_counter); + $this->assertEquals(1,$asset->checkin_counter); + } +} \ No newline at end of file