'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_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); } }