feat(scanner): implement scan attempt tracking with new request and resource classes
This commit is contained in:
@@ -62,24 +62,23 @@ class ScannerTicketControllerTest extends TestCase
|
||||
$this->getJson('/api/v1/scanner/tickets')->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_scanner_can_list_only_its_scanned_tickets_using_adminapp_format(): void
|
||||
public function test_scanner_can_list_only_its_scan_attempts(): void
|
||||
{
|
||||
$older = $this->createTicket('11111111-1111-4111-8111-111111111111', [
|
||||
'used_at' => now()->subMinutes(2),
|
||||
'scanner_user_id' => $this->scanner->id,
|
||||
$olderTicket = $this->createTicket('11111111-1111-4111-8111-111111111111');
|
||||
$newerTicket = $this->createTicket('22222222-2222-4222-8222-222222222222');
|
||||
$older = $this->createScanAttempt($olderTicket->ticket, [
|
||||
'ticket_id' => $olderTicket->id,
|
||||
'created_at' => now()->subMinutes(2),
|
||||
]);
|
||||
$newer = $this->createTicket('22222222-2222-4222-8222-222222222222', [
|
||||
'used_at' => now()->subMinute(),
|
||||
'scanner_user_id' => $this->scanner->id,
|
||||
$newer = $this->createScanAttempt($newerTicket->ticket, [
|
||||
'ticket_id' => $newerTicket->id,
|
||||
'created_at' => now()->subMinute(),
|
||||
]);
|
||||
$otherScanner = User::factory()->create([
|
||||
'rol_codigo' => RoleCode::Scanner->value,
|
||||
'tenant_codigo' => $this->tenant->codigo,
|
||||
]);
|
||||
$this->createTicket('33333333-3333-4333-8333-333333333333', [
|
||||
'used_at' => now(),
|
||||
'scanner_user_id' => $otherScanner->id,
|
||||
]);
|
||||
$this->createScanAttempt('not-this-scanner', [], $otherScanner);
|
||||
|
||||
Sanctum::actingAs($this->scanner);
|
||||
|
||||
@@ -87,45 +86,35 @@ class ScannerTicketControllerTest extends TestCase
|
||||
->assertOk()
|
||||
->assertJsonCount(2, 'data')
|
||||
->assertJsonPath('data.0.id', $newer->id)
|
||||
->assertJsonPath('data.0.ticket', $newer->ticket)
|
||||
->assertJsonPath('data.0.status', Ticket::STATUS_USED)
|
||||
->assertJsonPath('data.0.data', $newer->data)
|
||||
->assertJsonPath('data.0.ticket', $newerTicket->ticket)
|
||||
->assertJsonPath('data.0.result', ScanAttemptResult::Accepted->value)
|
||||
->assertJsonPath('data.0.can_view_ticket', true)
|
||||
->assertJsonPath('data.1.id', $older->id)
|
||||
->assertJsonPath('meta.current_page', 1)
|
||||
->assertJsonPath('meta.total', 2);
|
||||
}
|
||||
|
||||
public function test_scanner_ticket_history_supports_id_search_and_pagination(): void
|
||||
public function test_scanner_attempt_history_supports_data_search_and_pagination(): void
|
||||
{
|
||||
$matching = $this->createTicket('aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa', [
|
||||
'used_at' => now(),
|
||||
'scanner_user_id' => $this->scanner->id,
|
||||
]);
|
||||
$this->createTicket('bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb', [
|
||||
'used_at' => now()->subMinute(),
|
||||
'scanner_user_id' => $this->scanner->id,
|
||||
]);
|
||||
$matching = $this->createScanAttempt('aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa');
|
||||
$this->createScanAttempt('bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb');
|
||||
|
||||
Sanctum::actingAs($this->scanner);
|
||||
|
||||
$this->getJson('/api/v1/scanner/tickets?q=aaaaaaaa&per_page=1')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.ticket', $matching->ticket)
|
||||
->assertJsonPath('data.0.data', $matching->data)
|
||||
->assertJsonPath('meta.current_page', 1)
|
||||
->assertJsonPath('meta.per_page', 1)
|
||||
->assertJsonPath('meta.total', 1);
|
||||
}
|
||||
|
||||
public function test_scanner_ticket_history_can_be_searched_by_database_id(): void
|
||||
public function test_scanner_attempt_history_can_be_searched_by_database_id(): void
|
||||
{
|
||||
$matching = $this->createTicket('cccccccc-cccc-4ccc-8ccc-cccccccccccc', [
|
||||
'used_at' => now(),
|
||||
'scanner_user_id' => $this->scanner->id,
|
||||
]);
|
||||
$this->createTicket('dddddddd-dddd-4ddd-8ddd-dddddddddddd', [
|
||||
'used_at' => now()->subMinute(),
|
||||
'scanner_user_id' => $this->scanner->id,
|
||||
]);
|
||||
$matching = $this->createScanAttempt('cccccccc-cccc-4ccc-8ccc-cccccccccccc');
|
||||
$this->createScanAttempt('dddddddd-dddd-4ddd-8ddd-dddddddddddd');
|
||||
|
||||
Sanctum::actingAs($this->scanner);
|
||||
|
||||
@@ -135,15 +124,13 @@ class ScannerTicketControllerTest extends TestCase
|
||||
->assertJsonPath('data.0.id', $matching->id);
|
||||
}
|
||||
|
||||
public function test_scanner_ticket_history_can_be_searched_by_used_date(): void
|
||||
public function test_scanner_attempt_history_can_be_searched_by_attempt_date(): void
|
||||
{
|
||||
$matching = $this->createTicket('eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee', [
|
||||
'used_at' => '2026-08-11 14:30:00',
|
||||
'scanner_user_id' => $this->scanner->id,
|
||||
$matching = $this->createScanAttempt('eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee', [
|
||||
'created_at' => '2026-08-11 14:30:00',
|
||||
]);
|
||||
$this->createTicket('ffffffff-ffff-4fff-8fff-ffffffffffff', [
|
||||
'used_at' => '2026-08-10 14:30:00',
|
||||
'scanner_user_id' => $this->scanner->id,
|
||||
$this->createScanAttempt('ffffffff-ffff-4fff-8fff-ffffffffffff', [
|
||||
'created_at' => '2026-08-10 14:30:00',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->scanner);
|
||||
@@ -370,6 +357,25 @@ class ScannerTicketControllerTest extends TestCase
|
||||
$this->assertDatabaseCount('scan_attempts', 0);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
private function createScanAttempt(
|
||||
?string $data,
|
||||
array $attributes = [],
|
||||
?User $scanner = null,
|
||||
): ScanAttempt {
|
||||
$scanAttempt = new ScanAttempt;
|
||||
$scanAttempt->forceFill(array_merge([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'scanner_user_id' => ($scanner ?? $this->scanner)->id,
|
||||
'data' => $data,
|
||||
'result' => ScanAttemptResult::Accepted,
|
||||
'resolved_at' => now(),
|
||||
], $attributes));
|
||||
$scanAttempt->save();
|
||||
|
||||
return $scanAttempt;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $attributes */
|
||||
private function createTicket(
|
||||
string $uuid,
|
||||
|
||||
Reference in New Issue
Block a user