Skip to content

A free open source IT asset/license management system

Tests tests tests

snipeae008f03d977
diff --git a/tests/Feature/Reporting/DeleteAcceptanceAuthorizationTest.php b/tests/Feature/Reporting/DeleteAcceptanceAuthorizationTest.php
index a6c920217f..1ba9b11bb5 100644
--- a/tests/Feature/Reporting/DeleteAcceptanceAuthorizationTest.php
+++ b/tests/Feature/Reporting/DeleteAcceptanceAuthorizationTest.php
@@ -8,50 +8,68 @@ use App\Models\Company;
use App\Models\User;
use Tests\TestCase;
+/**
+ * Auth + FMCS pins for the acceptance-delete endpoint on the moved
+ * /unaccepted-acceptances surface. Gate shifted from reports.view to
+ * canCheckoutAtLeastOneItemType in v8.9 so the mutating path isn't
+ * reachable by a read-only Reports grant.
+ */
class DeleteAcceptanceAuthorizationTest extends TestCase
{
- public function test_user_without_reports_view_cannot_delete_acceptance()
+ public function test_user_without_checkout_grant_cannot_delete_acceptance()
{
$acceptance = CheckoutAcceptance::factory()->pending()->create();
$this->actingAs(User::factory()->create())
- ->delete(route('reports/unaccepted_assets_delete', $acceptance->id))
+ ->delete(route('unaccepted-acceptances.destroy', $acceptance->id))
->assertForbidden();
$this->assertNull($acceptance->fresh()->deleted_at);
}
- public function test_reports_user_can_delete_acceptance_for_their_own_company()
+ public function test_user_with_reports_view_only_cannot_delete_acceptance()
+ {
+ // reports.view no longer unlocks the acceptance mutations.
+ $acceptance = CheckoutAcceptance::factory()->pending()->create();
+
+ $this->actingAs(User::factory()->canViewReports()->create())
+ ->delete(route('unaccepted-acceptances.destroy', $acceptance->id))
+ ->assertForbidden();
+
+ $this->assertNull($acceptance->fresh()->deleted_at);
+ }
+
+ public function test_checkout_user_can_delete_acceptance_for_their_own_company()
{
$this->settings->enableMultipleFullCompanySupport();
[$companyA] = Company::factory()->count(2)->create();
$asset = Asset::factory()->create(['company_id' => $companyA->id]);
- $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();
+ $reporter = User::factory()->checkoutAccessories()->forCompany($companyA)->create();
$acceptance = CheckoutAcceptance::factory()->pending()->for($asset, 'checkoutable')->create();
$this->actingAs($reporter)
- ->delete(route('reports/unaccepted_assets_delete', $acceptance->id))
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->delete(route('unaccepted-acceptances.destroy', $acceptance->id))
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('success');
$this->assertNotNull($acceptance->fresh()->deleted_at);
}
- public function test_reports_user_cannot_delete_acceptance_belonging_to_another_company()
+ public function test_checkout_user_cannot_delete_acceptance_belonging_to_another_company()
{
$this->settings->enableMultipleFullCompanySupport();
[$companyA, $companyB] = Company::factory()->count(2)->create();
$assetB = Asset::factory()->create(['company_id' => $companyB->id]);
- $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();
+ $reporter = User::factory()->checkoutAccessories()->forCompany($companyA)->create();
$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')->create();
$this->actingAs($reporter)
- ->delete(route('reports/unaccepted_assets_delete', $acceptance->id))
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->delete(route('unaccepted-acceptances.destroy', $acceptance->id))
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('error');
$this->assertNull($acceptance->fresh()->deleted_at);
@@ -68,8 +86,8 @@ class DeleteAcceptanceAuthorizationTest extends TestCase
$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')->create();
$this->actingAs($superuser)
- ->delete(route('reports/unaccepted_assets_delete', $acceptance->id))
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->delete(route('unaccepted-acceptances.destroy', $acceptance->id))
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('success');
$this->assertNotNull($acceptance->fresh()->deleted_at);
@@ -82,14 +100,14 @@ class DeleteAcceptanceAuthorizationTest extends TestCase
[$companyA, $companyB] = Company::factory()->count(2)->create();
$assetB = Asset::factory()->create(['company_id' => $companyB->id]);
- $reporter = User::factory()->canViewReports()->withoutCompany()->create();
+ $reporter = User::factory()->checkoutAccessories()->withoutCompany()->create();
$reporter->companies()->sync([$companyA->id]);
$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')->create();
$this->actingAs($reporter)
- ->delete(route('reports/unaccepted_assets_delete', $acceptance->id))
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->delete(route('unaccepted-acceptances.destroy', $acceptance->id))
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('error');
$this->assertNull($acceptance->fresh()->deleted_at);
@@ -102,12 +120,12 @@ class DeleteAcceptanceAuthorizationTest extends TestCase
[$companyA, $companyB] = Company::factory()->count(2)->create();
$assetB = Asset::factory()->create(['company_id' => $companyB->id]);
- $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();
+ $reporter = User::factory()->checkoutAccessories()->forCompany($companyA)->create();
$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')->create();
$this->actingAs($reporter)
- ->delete(route('reports/unaccepted_assets_delete', $acceptance->id))
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->delete(route('unaccepted-acceptances.destroy', $acceptance->id))
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('success');
$this->assertNotNull($acceptance->fresh()->deleted_at);
diff --git a/tests/Feature/Reporting/SentReminderAuthorizationTest.php b/tests/Feature/Reporting/SentReminderAuthorizationTest.php
index 716c9f2cfe..024a8d8d54 100644
--- a/tests/Feature/Reporting/SentReminderAuthorizationTest.php
+++ b/tests/Feature/Reporting/SentReminderAuthorizationTest.php
@@ -10,9 +10,15 @@ use App\Models\User;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
+/**
+ * Auth + FMCS pins for the per-row reminder-send endpoint on the moved
+ * /unaccepted-acceptances surface. Gate shifted from reports.view to
+ * canCheckoutAtLeastOneItemType in v8.9 so the mutating path isn't
+ * reachable by a read-only Reports grant.
+ */
class SentReminderAuthorizationTest extends TestCase
{
- public function test_user_without_reports_view_cannot_send_reminder()
+ public function test_user_without_checkout_grant_cannot_send_reminder()
{
Mail::fake();
@@ -25,13 +31,35 @@ class SentReminderAuthorizationTest extends TestCase
->create();
$this->actingAs(User::factory()->create())
- ->post(route('reports/unaccepted_assets_sent_reminder'), ['acceptance_id' => $acceptance->id])
+ ->post(route('unaccepted-acceptances.send-reminder'), ['acceptance_id' => $acceptance->id])
->assertForbidden();
Mail::assertNothingSent();
}
- public function test_reports_user_can_send_reminder_for_their_own_company()
+ public function test_user_with_reports_view_only_cannot_send_reminder()
+ {
+ // Regression pin for the v8.9 move. reports.view alone no
+ // longer unlocks a reminder send. The actor must hold a
+ // checkout grant on at least one type.
+ Mail::fake();
+
+ $assignee = User::factory()->create(['email' => '[email protected]']);
+ $asset = Asset::factory()->create();
+ $acceptance = CheckoutAcceptance::factory()
+ ->pending()
+ ->for($asset, 'checkoutable')
+ ->for($assignee, 'assignedTo')
+ ->create();
+
+ $this->actingAs(User::factory()->canViewReports()->create())
+ ->post(route('unaccepted-acceptances.send-reminder'), ['acceptance_id' => $acceptance->id])
+ ->assertForbidden();
+
+ Mail::assertNothingSent();
+ }
+
+ public function test_checkout_user_can_send_reminder_for_their_own_company()
{
Mail::fake();
$this->settings->enableMultipleFullCompanySupport();
@@ -40,7 +68,7 @@ class SentReminderAuthorizationTest extends TestCase
$assignee = User::factory()->forCompany($companyA)->create(['email' => '[email protected]']);
$asset = Asset::factory()->create(['company_id' => $companyA->id]);
- $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();
+ $reporter = User::factory()->checkoutAccessories()->forCompany($companyA)->create();
$acceptance = CheckoutAcceptance::factory()
->pending()
->for($asset, 'checkoutable')
@@ -48,14 +76,14 @@ class SentReminderAuthorizationTest extends TestCase
->create();
$this->actingAs($reporter)
- ->post(route('reports/unaccepted_assets_sent_reminder'), ['acceptance_id' => $acceptance->id])
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->post(route('unaccepted-acceptances.send-reminder'), ['acceptance_id' => $acceptance->id])
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('success');
Mail::assertSent(CheckoutAssetMail::class);
}
- public function test_reports_user_cannot_send_reminder_for_another_company()
+ public function test_checkout_user_cannot_send_reminder_for_another_company()
{
Mail::fake();
$this->settings->enableMultipleFullCompanySupport();
@@ -64,7 +92,7 @@ class SentReminderAuthorizationTest extends TestCase
$assignee = User::factory()->create(['email' => '[email protected]']);
$assetB = Asset::factory()->create(['company_id' => $companyB->id]);
- $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();
+ $reporter = User::factory()->checkoutAccessories()->forCompany($companyA)->create();
$acceptance = CheckoutAcceptance::factory()
->pending()
->for($assetB, 'checkoutable')
@@ -72,8 +100,8 @@ class SentReminderAuthorizationTest extends TestCase
->create();
$this->actingAs($reporter)
- ->post(route('reports/unaccepted_assets_sent_reminder'), ['acceptance_id' => $acceptance->id])
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->post(route('unaccepted-acceptances.send-reminder'), ['acceptance_id' => $acceptance->id])
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('error');
Mail::assertNothingSent();
@@ -88,7 +116,7 @@ class SentReminderAuthorizationTest extends TestCase
$assignee = User::factory()->create(['email' => '[email protected]']);
$assetB = Asset::factory()->create(['company_id' => $companyB->id]);
- $reporter = User::factory()->canViewReports()->withoutCompany()->create();
+ $reporter = User::factory()->checkoutAccessories()->withoutCompany()->create();
$reporter->companies()->sync([$companyA->id]);
$acceptance = CheckoutAcceptance::factory()
@@ -98,8 +126,8 @@ class SentReminderAuthorizationTest extends TestCase
->create();
$this->actingAs($reporter)
- ->post(route('reports/unaccepted_assets_sent_reminder'), ['acceptance_id' => $acceptance->id])
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->post(route('unaccepted-acceptances.send-reminder'), ['acceptance_id' => $acceptance->id])
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('error');
Mail::assertNothingSent();
@@ -122,8 +150,8 @@ class SentReminderAuthorizationTest extends TestCase
->create();
$this->actingAs($superuser)
- ->post(route('reports/unaccepted_assets_sent_reminder'), ['acceptance_id' => $acceptance->id])
- ->assertRedirectToRoute('reports/unaccepted_assets')
+ ->post(route('unaccepted-acceptances.send-reminder'), ['acceptance_id' => $acceptance->id])
+ ->assertRedirectToRoute('unaccepted-acceptances.index')
->assertSessionHas('success');
Mail::assertSent(CheckoutAssetMail::class);