diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 961ba7f4b3..b53fb02fde 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -65,6 +65,25 @@ class AssetIndexTest extends TestCase } + public function testAssetApiIndexReturnsDueOrOverdueForAudit() + { + Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); + Asset::factory()->count(2)->create(['next_audit_date' => Carbon::now()->subDays(1)->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 5); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.assets.list-upcoming', ['action' => 'audits', 'upcoming_status' => 'due-or-overdue'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 5)->etc()); + } + + public function testAssetApiIndexReturnsDueForExpectedCheckin() { @@ -100,6 +119,23 @@ class AssetIndexTest extends TestCase ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); } + public function testAssetApiIndexReturnsDueOrOverdueForExpectedCheckin() + { + Asset::factory()->count(3)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->subDays(1)->format('Y-m-d')]); + Asset::factory()->count(2)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 5); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson(route('api.assets.list-upcoming', ['action' => 'checkins', 'upcoming_status' => 'due-or-overdue'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 5)->etc()); + } + public function testAssetApiIndexAdheresToCompanyScoping() { [$companyA, $companyB] = Company::factory()->count(2)->create();