Add Ladill POS v1 — register, Pay checkout, and commerce links.
Deploy Ladill Mini / deploy (push) Successful in 23s
Deploy Ladill Mini / deploy (push) Successful in 23s
Staff-facing counter register at pos.ladill.com with catalog cart, cash and MoMo/card checkout via Ladill Pay, CRM timeline/import, invoice prefill, and Merchant catalog import. 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,41 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssetLinksTest extends TestCase
|
||||
{
|
||||
public function test_assetlinks_returns_404_when_fingerprints_not_configured(): void
|
||||
{
|
||||
config(['android_app_links.sha256_cert_fingerprints' => []]);
|
||||
|
||||
$this->get('/.well-known/assetlinks.json')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_assetlinks_returns_json_when_configured(): void
|
||||
{
|
||||
config([
|
||||
'android_app_links.package_name' => 'com.ladill.mini',
|
||||
'android_app_links.sha256_cert_fingerprints' => [
|
||||
'AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->get('/.well-known/assetlinks.json')
|
||||
->assertOk()
|
||||
->assertHeader('Content-Type', 'application/json')
|
||||
->assertJson([
|
||||
[
|
||||
'relation' => ['delegate_permission/common.handle_all_urls'],
|
||||
'target' => [
|
||||
'namespace' => 'android_app',
|
||||
'package_name' => 'com.ladill.mini',
|
||||
'sha256_cert_fingerprints' => [
|
||||
'AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99',
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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,120 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\PosProduct;
|
||||
use App\Models\PosSale;
|
||||
use App\Models\User;
|
||||
use App\Services\CrossApp\CrossAppLinkService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PosCommerceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
$this->withoutVite();
|
||||
|
||||
config([
|
||||
'crm.url' => 'https://crm.test/api',
|
||||
'crm.key' => 'test-crm-key',
|
||||
]);
|
||||
}
|
||||
|
||||
private function user(): User
|
||||
{
|
||||
return User::create([
|
||||
'public_id' => 'u-'.uniqid(),
|
||||
'name' => 'Cashier',
|
||||
'email' => uniqid().'@example.com',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cash_sale_pushes_crm_timeline(): void
|
||||
{
|
||||
Http::fake([
|
||||
'crm.test/api/timeline' => Http::response(['id' => 1], 201),
|
||||
]);
|
||||
|
||||
$user = $this->user();
|
||||
|
||||
$this->actingAs($user)->post(route('pos.register.charge'), [
|
||||
'payment_method' => 'cash',
|
||||
'lines' => [
|
||||
['name' => 'Tea', 'unit_price_minor' => 1000, 'quantity' => 1],
|
||||
],
|
||||
])->assertRedirect();
|
||||
|
||||
Http::assertSent(fn ($request) => $request->url() === 'https://crm.test/api/timeline'
|
||||
&& $request['event'] === 'order.paid'
|
||||
&& $request['owner'] === $user->public_id);
|
||||
}
|
||||
|
||||
public function test_crm_product_import_creates_local_products(): void
|
||||
{
|
||||
Http::fake([
|
||||
'crm.test/api/products*' => Http::response([
|
||||
'data' => [
|
||||
[
|
||||
'name' => 'Imported Mug',
|
||||
'sku' => 'MUG-1',
|
||||
'unit_price_minor' => 2500,
|
||||
'currency' => 'GHS',
|
||||
'active' => true,
|
||||
],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$user = $this->user();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('pos.settings.import-crm'))
|
||||
->assertRedirect()
|
||||
->assertSessionHas('success');
|
||||
|
||||
$product = PosProduct::owned($user->public_id)->where('sku', 'MUG-1')->first();
|
||||
$this->assertNotNull($product);
|
||||
$this->assertSame('Imported Mug', $product->name);
|
||||
$this->assertSame(2500, $product->price_minor);
|
||||
}
|
||||
|
||||
public function test_paid_sale_links_to_invoice_prefill(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
$sale = PosSale::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'reference' => 'POS-TESTREF01',
|
||||
'status' => PosSale::STATUS_PAID,
|
||||
'payment_method' => PosSale::METHOD_CASH,
|
||||
'customer_name' => 'Ada',
|
||||
'total_minor' => 1500,
|
||||
'subtotal_minor' => 1500,
|
||||
'currency' => 'GHS',
|
||||
'paid_at' => now(),
|
||||
]);
|
||||
$sale->lines()->create([
|
||||
'name' => 'Coffee',
|
||||
'unit_price_minor' => 1500,
|
||||
'quantity' => 1,
|
||||
'line_total_minor' => 1500,
|
||||
'position' => 0,
|
||||
]);
|
||||
|
||||
$url = app(CrossAppLinkService::class)->invoiceFromSale($sale->fresh('lines'));
|
||||
|
||||
$this->assertStringContainsString('invoice.', $url);
|
||||
$this->assertStringContainsString('invoices%2Fcreate', $url);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('pos.sales.show', $sale))
|
||||
->assertOk()
|
||||
->assertSee('Create invoice');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\PosProduct;
|
||||
use App\Models\PosSale;
|
||||
use App\Models\User;
|
||||
use App\Services\Pay\PayClient;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PosRegisterTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function user(): User
|
||||
{
|
||||
return User::create([
|
||||
'public_id' => 'u-'.uniqid(),
|
||||
'name' => 'Cashier',
|
||||
'email' => uniqid().'@example.com',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
$this->withoutVite();
|
||||
|
||||
config([
|
||||
'crm.url' => 'https://crm.test/api',
|
||||
'crm.key' => 'test-crm-key',
|
||||
]);
|
||||
|
||||
Http::fake([
|
||||
'crm.test/api/customers*' => Http::response(['data' => []], 200),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_dashboard_renders_for_signed_in_user(): void
|
||||
{
|
||||
$this->actingAs($this->user())
|
||||
->get(route('pos.dashboard'))
|
||||
->assertOk()
|
||||
->assertSee('Overview')
|
||||
->assertSee('favicon.svg', false);
|
||||
}
|
||||
|
||||
public function test_register_renders_products(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
PosProduct::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'name' => 'Coffee',
|
||||
'price_minor' => 1500,
|
||||
'currency' => 'GHS',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('pos.register'))
|
||||
->assertOk()
|
||||
->assertSee('Coffee');
|
||||
}
|
||||
|
||||
public function test_cash_sale_is_recorded(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
$this->actingAs($user)->post(route('pos.register.charge'), [
|
||||
'payment_method' => 'cash',
|
||||
'lines' => [
|
||||
['name' => 'Tea', 'unit_price_minor' => 1000, 'quantity' => 2],
|
||||
],
|
||||
])->assertRedirect();
|
||||
|
||||
$sale = PosSale::where('owner_ref', $user->public_id)->first();
|
||||
$this->assertNotNull($sale);
|
||||
$this->assertSame(PosSale::STATUS_PAID, $sale->status);
|
||||
$this->assertSame(PosSale::METHOD_CASH, $sale->payment_method);
|
||||
$this->assertSame(2000, $sale->total_minor);
|
||||
}
|
||||
|
||||
public function test_pay_sale_redirects_to_checkout(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
$this->mock(PayClient::class, function ($mock) {
|
||||
$mock->shouldReceive('createCheckout')->once()->andReturn([
|
||||
'id' => 99,
|
||||
'reference' => 'LP-TESTREF',
|
||||
'checkout_url' => 'https://checkout.paystack.com/test',
|
||||
]);
|
||||
});
|
||||
|
||||
$this->actingAs($user)->post(route('pos.register.charge'), [
|
||||
'payment_method' => 'pay',
|
||||
'lines' => [
|
||||
['name' => 'Snack', 'unit_price_minor' => 500, 'quantity' => 1],
|
||||
],
|
||||
])->assertRedirect('https://checkout.paystack.com/test');
|
||||
|
||||
$sale = PosSale::where('owner_ref', $user->public_id)->first();
|
||||
$this->assertSame('LP-TESTREF', $sale->payment_reference);
|
||||
$this->assertSame(PosSale::STATUS_PENDING, $sale->status);
|
||||
}
|
||||
}
|
||||
@@ -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\MiniPayment;
|
||||
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,
|
||||
]);
|
||||
|
||||
MiniPayment::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' => MiniPayment::STATUS_PAID,
|
||||
'paid_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->getJson(route('mini.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('mini.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