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>
121 lines
3.5 KiB
PHP
121 lines
3.5 KiB
PHP
<?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');
|
|
}
|
|
}
|