Add account-level Analytics page to QR Plus.
Deploy Ladill QR Plus / deploy (push) Successful in 39s
Deploy Ladill QR Plus / deploy (push) Successful in 39s
Aggregates scan metrics across all codes with charts, breakdowns, and a sidebar nav item. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\QrCode;
|
||||
use App\Models\QrScanEvent;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QrAnalyticsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function user(): User
|
||||
{
|
||||
return User::create(['public_id' => (string) Str::uuid(), 'name' => 'A', 'email' => 'a+'.uniqid().'@x.com']);
|
||||
}
|
||||
|
||||
public function test_analytics_page_renders_for_authenticated_user(): void
|
||||
{
|
||||
$this->actingAs($this->user())
|
||||
->get(route('qr.analytics.index'))
|
||||
->assertOk()
|
||||
->assertSee('Analytics', false)
|
||||
->assertSee('Total scans', false)
|
||||
->assertSee('Top codes', false)
|
||||
->assertSee('Recent scans', false);
|
||||
}
|
||||
|
||||
public function test_analytics_page_shows_scan_data(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
$code = QrCode::create([
|
||||
'user_id' => $user->id,
|
||||
'short_code' => 'test-code-'.uniqid(),
|
||||
'type' => 'url',
|
||||
'label' => 'Menu QR',
|
||||
'destination_url' => 'https://example.com',
|
||||
'scans_total' => 3,
|
||||
'unique_scans_total' => 2,
|
||||
]);
|
||||
|
||||
QrScanEvent::create([
|
||||
'qr_code_id' => $code->id,
|
||||
'scanned_at' => now()->subDay(),
|
||||
'device_type' => 'mobile',
|
||||
'browser' => 'Chrome',
|
||||
'is_unique' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('qr.analytics.index'))
|
||||
->assertOk()
|
||||
->assertSee('Menu QR', false)
|
||||
->assertSee('3', false)
|
||||
->assertSee('Chrome', false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user