Initial Ladill Give extraction — online giving pages at give.ladill.com.
Donation checkout via Ladill Pay (9% fee), church/giving QR pages, SSO, and platform scan forwarding. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\GiveDonation;
|
||||
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_payments_by_payer_name(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
$qr = QrCode::query()->create([
|
||||
'user_id' => $user->id,
|
||||
'short_code' => 'till01',
|
||||
'type' => QrCode::TYPE_PAYMENT,
|
||||
'label' => 'Main till',
|
||||
'destination_url' => 'https://example.com',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
GiveDonation::query()->create([
|
||||
'qr_code_id' => $qr->id,
|
||||
'user_id' => $user->id,
|
||||
'reference' => 'pay-'.Str::uuid(),
|
||||
'amount_minor' => 5000,
|
||||
'currency' => 'GHS',
|
||||
'platform_fee_minor' => 250,
|
||||
'merchant_amount_minor' => 4750,
|
||||
'payer_name' => 'Ama Mensah',
|
||||
'status' => GiveDonation::STATUS_PAID,
|
||||
'paid_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->getJson(route('give.search', ['q' => 'Ama']));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('results.0.type', 'payment');
|
||||
$response->assertJsonPath('results.0.title', 'Ama Mensah');
|
||||
}
|
||||
|
||||
public function test_search_page_renders_for_authenticated_user(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('give.search'))
|
||||
->assertOk()
|
||||
->assertSee('Find payments', false);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user