From 2484a9db2c58141b64b8e6e5879adcfcce082141 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:01:29 +0100 Subject: [PATCH] Added tests Signed-off-by: snipe --- tests/Feature/Api/Assets/AssetIndexTest.php | 78 ++++++++++++++++++++- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 3175db6953..3aa90840eb 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -7,10 +7,10 @@ use App\Models\Company; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Tests\TestCase; - +use Carbon; class AssetIndexTest extends TestCase { - public function testAssetIndexReturnsExpectedAssets() + public function testAssetApiIndexReturnsExpectedAssets() { Asset::factory()->count(3)->create(); @@ -30,7 +30,79 @@ class AssetIndexTest extends TestCase ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); } - public function testAssetIndexAdheresToCompanyScoping() + public function testAssetApiIndexReturnsDisplayUpcomingAuditsDueToday() + { + $assets = Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); + + //dd($assets); + + $this->assertTrue(Asset::count() === 3); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.asset.to-audit', ['status' => 'due'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + + } + + public function testAssetApiIndexReturnsOverdueForAudit() + { + Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->subDays(1)->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 3); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.asset.to-audit', ['status' => 'overdue'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + } + + + public function testAssetApiIndexReturnsDueForExpectedCheckinToday() + { + Asset::factory()->count(3)->create(['expected_checkin' => Carbon::now()->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 3); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.asset.to-checkin', ['status' => 'due']) + ) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + } + + public function testAssetApiIndexReturnsOverdueForExpectedCheckin() + { + Asset::factory()->count(3)->create(['expected_checkin' => Carbon::now()->subDays(1)->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 3); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson(route('api.asset.to-checkin', ['status' => 'overdue'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + } + + public function testAssetApiIndexAdheresToCompanyScoping() { [$companyA, $companyB] = Company::factory()->count(2)->create();