From 76b114d820c6e4d2c6d807ac150031044328d6d5 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 10 Aug 2024 18:21:41 +0100 Subject: [PATCH] Added test Signed-off-by: snipe --- .../Feature/Reporting/ActivityReportTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/Feature/Reporting/ActivityReportTest.php diff --git a/tests/Feature/Reporting/ActivityReportTest.php b/tests/Feature/Reporting/ActivityReportTest.php new file mode 100644 index 000000000..e094f86b6 --- /dev/null +++ b/tests/Feature/Reporting/ActivityReportTest.php @@ -0,0 +1,81 @@ +actingAsForApi(User::factory()->create()) + ->getJson(route('api.activity.index')) + ->assertForbidden(); + } + + public function testRecordsAreScopedToCompanyWhenMultipleCompanySupportEnabled() + { + $this->markTestIncomplete('This test returns strange results. Need to figure out why.'); + $this->settings->enableMultipleFullCompanySupport(); + + $companyA = Company::factory()->create(); + $companyB = Company::factory()->create(); + + $superUser = User::factory()->superuser()->make(); + + $userInCompanyA = User::factory() + ->viewUsers() + ->viewAssets() + ->canViewReports() + ->create(['company_id' => $companyA->id]); + + $userInCompanyB = User::factory() + ->viewUsers() + ->viewAssets() + ->canViewReports() + ->create(['company_id' => $companyB->id]); + + Asset::factory()->count(5)->create(['company_id' => $companyA->id]); + Asset::factory()->count(4)->create(['company_id' => $companyB->id]); + Asset::factory()->count(3)->create(); + + Actionlog::factory()->userUpdated()->count(5)->create(['company_id' => $companyA->id]); + Actionlog::factory()->userUpdated()->count(4)->create(['company_id' => $companyB->id]); + Actionlog::factory()->userUpdated()->count(3)->create(['company_id' => $companyB->id]); + + // I don't love this, since it doesn't test that we're actually storing the company ID appropriately + // but it's better than what we had + $response = $this->actingAsForApi($userInCompanyA) + ->getJson(route('api.activity.index')) + ->assertOk() + ->assertJsonStructure([ + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 5)->etc()); + + + $this->actingAsForApi($userInCompanyB) + ->getJson( + route('api.activity.index')) + ->assertOk() + ->assertJsonStructure([ + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 7)->etc()); + + + + + + } + +}