Initial Ladill Transfer app — file sharing with QR links.

Scaffolded from the Ladill mini/events extraction pattern: multi-file transfers,
retention controls, public landing pages, analytics, and Gitea deploy workflow.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-08 09:25:30 +00:00
co-authored by Cursor
commit c1e3d8b3ac
281 changed files with 36051 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'));
}
}
+82
View File
@@ -0,0 +1,82 @@
<?php
namespace Tests\Feature;
use App\Models\QrCode;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class ImportEventsCommandTest extends TestCase
{
use RefreshDatabase;
public function test_import_decodes_json_payload_and_remaps_programme_links(): void
{
Storage::fake('qr');
$owner = User::factory()->create(['public_id' => 'usr_events_owner']);
$payload = [
'qr_wallets' => [],
'qr_codes' => [
[
'platform_id' => 10,
'owner_public_id' => $owner->public_id,
'owner_email' => $owner->email,
'short_code' => 'demo-programme',
'type' => QrCode::TYPE_ITINERARY,
'label' => 'Demo Programme',
'payload' => json_encode(['content' => ['title' => 'Demo Programme'], 'style' => []]),
'is_active' => true,
'scans_total' => 0,
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString(),
'destination_updated_at' => now()->toDateTimeString(),
],
[
'platform_id' => 11,
'owner_public_id' => $owner->public_id,
'owner_email' => $owner->email,
'short_code' => 'demo-event',
'type' => QrCode::TYPE_EVENT,
'label' => 'Demo Event',
'payload' => json_encode([
'content' => ['name' => 'Demo Event', 'programme_qr_id' => 10],
'style' => [],
]),
'is_active' => true,
'scans_total' => 0,
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString(),
'destination_updated_at' => now()->toDateTimeString(),
],
],
'qr_event_registrations' => [],
'qr_scan_events' => [],
'qr_transactions' => [],
];
$exportPath = storage_path('framework/testing/events-import.json');
if (! is_dir(dirname($exportPath))) {
mkdir(dirname($exportPath), 0777, true);
}
file_put_contents($exportPath, json_encode($payload));
Artisan::call('events:import', [
'file' => $exportPath,
'--commit' => true,
]);
$event = QrCode::where('short_code', 'demo-event')->first();
$programme = QrCode::where('short_code', 'demo-programme')->first();
$this->assertNotNull($event);
$this->assertNotNull($programme);
$this->assertIsArray($event->payload);
$this->assertSame('Demo Event', $event->content()['name'] ?? null);
$this->assertSame($programme->id, $event->content()['programme_qr_id'] ?? null);
}
}
+108
View File
@@ -0,0 +1,108 @@
<?php
namespace Tests\Feature;
use App\Models\QrCode;
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('favicon.ico', false)
->assertSee('New event defaults')
->assertSee('QR code defaults')
->assertSee('New registrations')
->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',
'notify_registrations' => '1',
'notify_payouts' => '0',
'event_defaults' => [
'currency' => 'USD',
'mode' => 'free',
'badge_size' => '4x6',
'brand_color' => '#aabbcc',
'organizer' => 'CAPBuSS',
'registration_open' => '1',
'badge_fields' => ['Company', 'Title'],
],
'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->assertTrue($settings->notify_registrations);
$this->assertFalse($settings->notify_payouts);
$this->assertSame('USD', $settings->resolvedEventDefaults()['currency']);
$this->assertSame('free', $settings->resolvedEventDefaults()['mode']);
$this->assertSame('CAPBuSS', $settings->resolvedEventDefaults()['organizer']);
$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' => QrCode::TYPE_EVENT,
'default_style' => ['foreground' => '#aabbcc', 'module_style' => 'dots'],
'event_defaults' => ['mode' => 'contributions', 'organizer' => 'Test Org', 'brand_color' => '#ff00aa'],
]);
Http::fake([
config('billing.api_url').'/balance*' => Http::response(['balance_minor' => 50000]),
]);
$this->actingAs($user)
->get(route('events.create'))
->assertOk()
->assertSee('favicon.ico', false)
->assertSee('#aabbcc', false)
->assertSee('Test Org', false)
->assertSee('"event"', false);
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace Tests\Feature;
use App\Models\QrCode;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Tests\TestCase;
class SearchTest 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_user_can_search_owned_event_by_label(): void
{
$user = $this->user();
QrCode::query()->create([
'user_id' => $user->id,
'short_code' => 'summit',
'type' => QrCode::TYPE_EVENT,
'label' => 'NextGen Summit',
'destination_url' => 'https://example.com',
'is_active' => true,
]);
$response = $this->actingAs($user)
->getJson(route('events.search', ['q' => 'NextGen']));
$response->assertOk();
$response->assertJsonPath('results.0.type', 'event');
$response->assertJsonPath('results.0.title', 'NextGen Summit');
}
public function test_search_page_renders_for_authenticated_user(): void
{
$user = $this->user();
$this->actingAs($user)
->get(route('events.search'))
->assertOk()
->assertSee('Find events and programmes', false);
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Tests\Feature;
use App\Models\Transfer;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Tests\TestCase;
class TransferTest extends TestCase
{
use RefreshDatabase;
public function test_authenticated_user_can_create_transfer_with_files(): void
{
Storage::fake('qr');
$user = User::create([
'public_id' => (string) Str::uuid(),
'name' => 'Test User',
'email' => 'transfer+'.uniqid().'@example.com',
]);
$response = $this->actingAs($user)->post(route('transfer.transfers.store'), [
'title' => 'Project assets',
'message' => 'Here are the files.',
'retention_days' => 14,
'files' => [
UploadedFile::fake()->create('brief.pdf', 100, 'application/pdf'),
UploadedFile::fake()->create('photo.jpg', 50, 'image/jpeg'),
],
]);
$response->assertRedirect();
$this->assertDatabaseCount('transfers', 1);
$this->assertDatabaseCount('transfer_files', 2);
$this->assertDatabaseHas('qr_codes', ['type' => 'transfer', 'label' => 'Project assets']);
$transfer = Transfer::first();
$this->assertNotNull($transfer->qr_code_id);
$this->assertSame(14, $transfer->retention_days);
}
public function test_dashboard_requires_auth(): void
{
$this->get(route('transfer.dashboard'))->assertRedirect();
}
}
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->withoutVite();
}
}
+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);
}
}
@@ -0,0 +1,57 @@
<?php
namespace Tests\Unit\Services\Qr;
use App\Models\QrCode;
use App\Models\User;
use App\Services\Qr\QrCodeManagerService;
use App\Services\Qr\QrImageGeneratorService;
use App\Services\Qr\QrPayloadValidator;
use App\Services\Qr\QrWalletBillingService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Tests\TestCase;
class PaymentQrUpdateTest extends TestCase
{
use RefreshDatabase;
public function test_payment_qr_update_persists_business_fields(): void
{
$user = User::create([
'public_id' => (string) Str::uuid(),
'name' => 'Trader',
'email' => 'trader@example.com',
]);
$qrCode = QrCode::create([
'user_id' => $user->id,
'short_code' => 'paytest01',
'type' => QrCode::TYPE_PAYMENT,
'label' => 'Till 1',
'payload' => [
'content' => [
'business_name' => 'Old Shop',
'branch_label' => 'Main',
'currency' => 'GHS',
],
'style' => [],
],
'is_active' => true,
]);
$manager = new QrCodeManagerService(
$this->createMock(QrWalletBillingService::class),
$this->createMock(QrImageGeneratorService::class),
new QrPayloadValidator(),
);
$updated = $manager->update($qrCode, [
'business_name' => 'New Shop',
'branch_label' => 'Accra Mall',
]);
$this->assertSame('New Shop', $updated->content()['business_name']);
$this->assertSame('Accra Mall', $updated->content()['branch_label']);
}
}