Bootstrap Ladill Link from QR Plus extract template.

This commit is contained in:
isaacclad
2026-06-27 10:54:31 +00:00
commit 04e4f6ab51
243 changed files with 26587 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use Tests\TestCase;
class AfiaTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Http::preventStrayRequests();
}
private function user(): User
{
return User::create(['public_id' => (string) Str::uuid(), 'name' => 'A', 'email' => 'a+'.uniqid().'@x.com']);
}
public function test_requires_a_message(): void
{
config(['afia.api_key' => 'sk-test']);
$this->actingAs($this->user())->postJson('/afia/chat', [])->assertStatus(422);
}
public function test_returns_503_when_not_configured(): void
{
config(['afia.api_key' => '']);
$this->actingAs($this->user())->postJson('/afia/chat', ['message' => 'hi'])->assertStatus(503);
}
public function test_returns_reply_from_llm(): void
{
config(['afia.api_key' => 'sk-test', 'afia.provider' => 'openai', 'afia.model' => 'gpt-4o-mini']);
Http::fake([
'api.openai.com/*' => Http::response(['choices' => [['message' => ['content' => 'Create a Business QR under My Codes.']]]]),
]);
$this->actingAs($this->user())
->postJson('/afia/chat', ['message' => 'How do I create a business QR?'])
->assertOk()
->assertJson(['reply' => 'Create a Business QR under My Codes.']);
Http::assertSent(fn ($r) => str_contains($r->url(), 'openai.com')
&& collect($r['messages'])->first()['role'] === 'system'
&& str_contains(collect($r['messages'])->first()['content'], 'Ladill QR Plus'));
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
namespace Tests\Feature;
use App\Models\QrCode;
use App\Models\QrDocument;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class ImportQrPlusCommandTest extends TestCase
{
use RefreshDatabase;
public function test_import_links_pdf_documents_and_copies_files(): void
{
Storage::fake('qr');
$user = User::factory()->create(['public_id' => 'usr_test_pdf']);
$sourceRoot = storage_path('framework/testing/platform-qr');
$relativePath = $user->id.'/documents/test-menu.pdf';
$sourceFile = $sourceRoot.'/'.$relativePath;
if (! is_dir(dirname($sourceFile))) {
mkdir(dirname($sourceFile), 0777, true);
}
file_put_contents($sourceFile, '%PDF-1.4 test');
$payload = [
'qr_wallets' => [],
'qr_documents' => [[
'platform_id' => 42,
'owner_public_id' => $user->public_id,
'owner_email' => $user->email,
'title' => 'Menu PDF',
'disk' => 'qr',
'path' => $relativePath,
'mime_type' => 'application/pdf',
'size_bytes' => 12,
'page_count' => null,
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString(),
]],
'qr_codes' => [[
'platform_id' => 99,
'platform_qr_document_id' => 42,
'owner_public_id' => $user->public_id,
'owner_email' => $user->email,
'short_code' => 'menu-pdf',
'type' => QrCode::TYPE_DOCUMENT,
'label' => 'Menu PDF',
'destination_url' => null,
'payload' => json_encode(['content' => ['allow_download' => true], 'style' => []]),
'is_active' => true,
'scans_total' => 0,
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString(),
'destination_updated_at' => now()->toDateTimeString(),
]],
'qr_scan_events' => [],
'qr_transactions' => [],
];
$exportPath = storage_path('framework/testing/qr-plus-import.json');
file_put_contents($exportPath, json_encode($payload));
Artisan::call('qr-plus:import', [
'file' => $exportPath,
'--commit' => true,
'--storage-source' => $sourceRoot,
]);
$code = QrCode::where('short_code', 'menu-pdf')->first();
$this->assertNotNull($code);
$this->assertNotNull($code->qr_document_id);
$document = QrDocument::find($code->qr_document_id);
$this->assertNotNull($document);
$this->assertSame($relativePath, $document->path);
Storage::disk('qr')->assertExists($relativePath);
}
}
+60
View File
@@ -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);
}
}
+87
View File
@@ -0,0 +1,87 @@
<?php
namespace Tests\Feature;
use App\Models\QrSetting;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use Tests\TestCase;
class QrSettingsTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Http::preventStrayRequests();
}
private function user(): User
{
return User::create(['public_id' => (string) Str::uuid(), 'name' => 'A', 'email' => 'a+'.uniqid().'@x.com']);
}
public function test_settings_page_renders_for_authenticated_user(): void
{
$this->actingAs($this->user())
->get(route('account.settings'))
->assertOk()
->assertSee('New code defaults')
->assertSee('Notifications');
}
public function test_can_save_qr_settings(): void
{
$user = $this->user();
$this->actingAs($user)
->put(route('account.settings.update'), [
'notify_email' => 'alerts@example.com',
'product_updates' => '1',
'low_balance_alerts' => '0',
'default_type' => 'wifi',
'default_style' => [
'foreground' => '#112233',
'background' => '#ffffff',
'module_style' => 'dots',
'frame_style' => 'scan_me',
'frame_color' => '#445566',
'frame_text' => 'SCAN ME',
],
])
->assertRedirect(route('account.settings'));
$settings = QrSetting::where('user_id', $user->id)->first();
$this->assertNotNull($settings);
$this->assertSame('alerts@example.com', $settings->notify_email);
$this->assertTrue($settings->product_updates);
$this->assertFalse($settings->low_balance_alerts);
$this->assertSame('wifi', $settings->default_type);
$this->assertSame('#112233', $settings->resolvedDefaultStyle()['foreground']);
$this->assertSame('scan_me', $settings->resolvedDefaultStyle()['frame_style']);
}
public function test_create_page_uses_saved_defaults(): void
{
$user = $this->user();
QrSetting::create([
'user_id' => $user->id,
'default_type' => 'business',
'default_style' => ['foreground' => '#aabbcc', 'module_style' => 'dots'],
]);
Http::fake([
config('billing.api_url').'/balance*' => Http::response(['balance_minor' => 50000]),
]);
$this->actingAs($user)
->get(route('user.qr-codes.create'))
->assertOk()
->assertSee('#aabbcc', false)
->assertSee('"business"', false);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}