'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.ico', false); } public function test_register_renders_local_products_in_restaurant_mode(): void { $user = $this->user(); // ensureDefault() matches owner+name 'Main register'. PosLocation::create(['owner_ref' => $user->public_id, 'name' => 'Main register', 'currency' => 'GHS', 'service_style' => 'restaurant']); 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_retail_register_reads_crm_products_and_snapshots_lines(): void { Http::fake([ 'crm.test/api/products*' => Http::response(['data' => [ ['id' => 7, 'name' => 'Mug', 'unit_price_minor' => 2500, 'currency' => 'GHS', 'active' => true], ]], 200), 'crm.test/api/customers*' => Http::response(['data' => []], 200), 'crm.test/api/*' => Http::response(['id' => 1], 201), ]); $user = $this->user(); // retail by default (no restaurant location) $this->actingAs($user)->get(route('pos.register'))->assertOk()->assertSee('Mug'); // A line built from a CRM product is stored as a snapshot — no local FK. $this->actingAs($user)->post(route('pos.register.charge'), [ 'payment_method' => 'cash', 'lines' => [['product_id' => 7, 'name' => 'Mug', 'unit_price_minor' => 2500, 'quantity' => 1]], ])->assertRedirect(); $line = PosSale::where('owner_ref', $user->public_id)->firstOrFail()->lines()->firstOrFail(); $this->assertNull($line->product_id); $this->assertSame('Mug', $line->name); $this->assertSame(2500, $line->unit_price_minor); } public function test_retail_products_page_lists_crm_products(): void { Http::fake([ 'crm.test/api/products*' => Http::response(['data' => [ ['id' => 7, 'name' => 'Mug', 'sku' => 'M1', 'unit_price_minor' => 2500, 'currency' => 'GHS', 'active' => true], ]], 200), ]); $this->actingAs($this->user())->get(route('pos.products.index'))->assertOk()->assertSee('Mug'); } 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); } }