Added tests

This commit is contained in:
snipe
2026-04-29 17:17:41 +01:00
parent c7c3b04c5f
commit ac4975e1d1
4 changed files with 86 additions and 17 deletions
+2 -2
View File
@@ -1857,8 +1857,8 @@
{{ trans('general.asset_maintenance_report') }}
</a>
</li>
<li {{!! (request()->is('reports/unaccepted_assets') ? ' class="active"' : '') !!}}>
<a href="{{ url('reports/unaccepted_assets') }}">
<li {{!! (request()->is('reports/unaccepted_items') ? ' class="active"' : '') !!}}>
<a href="{{ url('reports/unaccepted_items') }}">
{{ trans('general.unaccepted_asset_report') }}
</a>
</li>
@@ -97,7 +97,7 @@
<td @if(!$item->assignee || (method_exists($item->assignee, 'trashed') && $item->assignee->trashed())) style="text-decoration: line-through" @endif>
{!! $item->assignee
? optional($item->assignee->present())->nameUrl() ?? e($item->assignee->name)
: trans('admin/reports/general.deleted_user') !!}
: trans('general.deleted') !!}
</td>
{{-- Actions: send reminder / delete --}}
@@ -43,7 +43,7 @@ class AcceptanceReminderTest extends TestCase
$userWithoutPermission = User::factory()->create();
$this->actingAs($userWithoutPermission)
->post(route('reports/unaccepted_assets_sent_reminder', [
->post(route('reports/unaccepted_items_sent_reminder', [
'acceptance_id' => $checkoutAcceptance->id,
]))
->assertForbidden();
@@ -54,7 +54,7 @@ class AcceptanceReminderTest extends TestCase
public function test_reminder_not_sent_if_acceptance_does_not_exist()
{
$this->actingAs($this->admin)
->post(route('reports/unaccepted_assets_sent_reminder', [
->post(route('reports/unaccepted_items_sent_reminder', [
'acceptance_id' => 999999,
]));
@@ -66,7 +66,7 @@ class AcceptanceReminderTest extends TestCase
$checkoutAcceptanceAlreadyAccepted = CheckoutAcceptance::factory()->accepted()->create();
$this->actingAs($this->admin)
->post(route('reports/unaccepted_assets_sent_reminder', [
->post(route('reports/unaccepted_items_sent_reminder', [
'acceptance_id' => $checkoutAcceptanceAlreadyAccepted->id,
]));
@@ -100,7 +100,7 @@ class AcceptanceReminderTest extends TestCase
$checkoutAcceptance = $callback();
$this->actingAs($this->admin)
->post(route('reports/unaccepted_assets_sent_reminder', [
->post(route('reports/unaccepted_items_sent_reminder', [
'acceptance_id' => $checkoutAcceptance->id,
]))
// check we didn't crash...
@@ -124,10 +124,10 @@ class AcceptanceReminderTest extends TestCase
->create();
$this->actingAs($this->admin)
->post(route('reports/unaccepted_assets_sent_reminder', [
->post(route('reports/unaccepted_items_sent_reminder', [
'acceptance_id' => $acceptance->id,
]))
->assertRedirect(route('reports/unaccepted_assets'));
->assertRedirect(route('reports/unaccepted_items'));
Mail::assertSent(CheckoutAccessoryMail::class, 1);
@@ -153,10 +153,10 @@ class AcceptanceReminderTest extends TestCase
$this->createActionLogEntry($asset, $this->admin, $this->assignee, $acceptance);
$this->actingAs($this->admin)
->post(route('reports/unaccepted_assets_sent_reminder', [
->post(route('reports/unaccepted_items_sent_reminder', [
'acceptance_id' => $acceptance->id,
]))
->assertRedirect(route('reports/unaccepted_assets'));
->assertRedirect(route('reports/unaccepted_items'));
Mail::assertSent(CheckoutAssetMail::class, 1);
@@ -182,10 +182,10 @@ class AcceptanceReminderTest extends TestCase
$this->createActionLogEntry($consumable, $this->admin, $this->assignee, $acceptance);
$this->actingAs($this->admin)
->post(route('reports/unaccepted_assets_sent_reminder', [
->post(route('reports/unaccepted_items_sent_reminder', [
'acceptance_id' => $acceptance->id,
]))
->assertRedirect(route('reports/unaccepted_assets'));
->assertRedirect(route('reports/unaccepted_items'));
Mail::assertSent(CheckoutConsumableMail::class, 1);
@@ -211,10 +211,10 @@ class AcceptanceReminderTest extends TestCase
$this->createActionLogEntry($licenseSeat, $this->admin, $this->assignee, $acceptance);
$this->actingAs($this->admin)
->post(route('reports/unaccepted_assets_sent_reminder', [
->post(route('reports/unaccepted_items_sent_reminder', [
'acceptance_id' => $acceptance->id,
]))
->assertRedirect(route('reports/unaccepted_assets'));
->assertRedirect(route('reports/unaccepted_items'));
Mail::assertSent(CheckoutLicenseMail::class, 1);
@@ -44,14 +44,83 @@ class UnacceptedAssetReportTest extends TestCase
public function test_permission_required_to_view_unaccepted_asset_report()
{
$this->actingAs(User::factory()->create())
->get(route('reports/unaccepted_assets'))
->get(route('reports/unaccepted_items'))
->assertForbidden();
}
public function test_user_can_list_unaccepted_assets()
{
$this->actingAs(User::factory()->superuser()->create())
->get(route('reports/unaccepted_assets'))
->get(route('reports/unaccepted_items'))
->assertOk();
}
public function test_regular_user_does_not_see_actions_column_or_buttons()
{
$user = User::factory()->create();
$response = $this->actingAs($user)
->get(route('reports/unaccepted_items'));
$response->assertOk();
$response->assertDontSee('Actions');
$response->assertDontSee('Send Reminder');
$response->assertDontSee('Delete');
}
public function test_admin_sees_actions_column_and_buttons()
{
$admin = User::factory()->admin()->create();
$response = $this->actingAs($admin)
->get(route('reports/unaccepted_items'));
$response->assertOk();
$response->assertSee('Actions');
$response->assertSee('Send Reminder');
$response->assertSee('Delete');
}
public function test_superuser_sees_actions_column_and_buttons()
{
$superuser = User::factory()->superuser()->create();
$response = $this->actingAs($superuser)
->get(route('reports/unaccepted_items'));
$response->assertOk();
$response->assertSee('Actions');
$response->assertSee('Send Reminder');
$response->assertSee('Delete');
}
public function test_regular_user_cannot_perform_reminder_or_delete()
{
$user = User::factory()->create();
$acceptanceId = 1; // Use a valid acceptance ID in your test DB or factory
$this->actingAs($user)
->post(route('reports/unaccepted_items_sent_reminder'), ['acceptance_id' => $acceptanceId])
->assertForbidden();
$this->actingAs($user)
->delete(route('reports/unaccepted_items_delete', $acceptanceId))
->assertForbidden();
}
public function test_admin_can_perform_reminder_and_delete()
{
$admin = User::factory()->admin()->create();
$acceptanceId = 1; // Use a valid acceptance ID in your test DB or factory
$this->actingAs($admin)
->post(route('reports/unaccepted_items_sent_reminder'), ['acceptance_id' => $acceptanceId])
->assertStatus(302); // Or whatever is appropriate (redirect, etc)
$this->actingAs($admin)
->delete(route('reports/unaccepted_items_delete', $acceptanceId))
->assertStatus(302);
}
public function test_superuser_can_perform_reminder_and_delete()
{
$superuser = User::factory()->superuser()->create();
$acceptanceId = 1; // Use a valid acceptance ID in your test DB or factory
$this->actingAs($superuser)
->post(route('reports/unaccepted_items_sent_reminder'), ['acceptance_id' => $acceptanceId])
->assertStatus(302);
$this->actingAs($superuser)
->delete(route('reports/unaccepted_items_delete', $acceptanceId))
->assertStatus(302);
}
}