Files
ladill-pos/tests/Feature/PosHardwareTest.php
T
isaaccladandCursor cac7c60415
Deploy Ladill POS / deploy (push) Successful in 1m32s
Add receipt logo upload and redesign thermal receipt header.
Per-location logo in settings with remove/replace support; receipt template reserves space at the top when a logo is set.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-08 05:48:40 +00:00

207 lines
6.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\PosLocation;
use App\Models\PosProduct;
use App\Models\PosSale;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class PosHardwareTest 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',
]);
}
public function test_barcode_lookup_finds_local_product_in_restaurant_mode(): void
{
$user = $this->user();
PosLocation::create([
'owner_ref' => $user->public_id,
'name' => 'Main register',
'currency' => 'GHS',
'service_style' => 'restaurant',
]);
PosProduct::create([
'owner_ref' => $user->public_id,
'name' => 'Water',
'sku' => 'H2O-001',
'price_minor' => 500,
'currency' => 'GHS',
'is_active' => true,
]);
$this->actingAs($user)
->getJson(route('pos.register.lookup', ['code' => 'H2O-001']))
->assertOk()
->assertJsonPath('product.name', 'Water')
->assertJsonPath('product.price_minor', 500);
}
public function test_barcode_lookup_returns_404_for_unknown_code(): void
{
$user = $this->user();
PosLocation::create([
'owner_ref' => $user->public_id,
'name' => 'Main register',
'currency' => 'GHS',
'service_style' => 'restaurant',
]);
$this->actingAs($user)
->getJson(route('pos.register.lookup', ['code' => 'MISSING']))
->assertNotFound();
}
public function test_receipt_page_renders_thermal_layout(): void
{
$user = $this->user();
$location = PosLocation::create([
'owner_ref' => $user->public_id,
'name' => 'Main register',
'currency' => 'GHS',
'receipt_header' => 'Acme Shop',
'printer_paper_mm' => 58,
]);
$sale = PosSale::create([
'owner_ref' => $user->public_id,
'location_id' => $location->id,
'reference' => 'POS-TEST',
'currency' => 'GHS',
'status' => 'paid',
'payment_method' => 'cash',
'total_minor' => 1000,
]);
$sale->lines()->create([
'name' => 'Tea',
'unit_price_minor' => 1000,
'quantity' => 1,
'line_total_minor' => 1000,
]);
$this->actingAs($user)
->get(route('pos.sales.receipt', $sale))
->assertOk()
->assertSee('Acme Shop')
->assertSee('POS-TEST')
->assertSee('Tea')
->assertSee('Print receipt');
}
public function test_cash_sale_redirects_to_receipt_when_auto_print_enabled(): void
{
Http::fake([
'crm.test/api/customers*' => Http::response(['data' => []], 200),
]);
$user = $this->user();
PosLocation::create([
'owner_ref' => $user->public_id,
'name' => 'Main register',
'currency' => 'GHS',
'printer_auto_print' => true,
]);
$response = $this->actingAs($user)->post(route('pos.register.charge'), [
'payment_method' => 'cash',
'lines' => [
['name' => 'Snack', 'unit_price_minor' => 500, 'quantity' => 1],
],
]);
$sale = PosSale::where('owner_ref', $user->public_id)->firstOrFail();
$response->assertRedirect(route('pos.sales.receipt', ['sale' => $sale, 'autoprint' => 1]));
}
public function test_settings_accepts_receipt_logo_upload(): void
{
Storage::fake('public');
$user = $this->user();
PosLocation::create([
'owner_ref' => $user->public_id,
'name' => 'Main register',
'currency' => 'GHS',
]);
$this->actingAs($user)
->put(route('pos.settings.update'), [
'name' => 'Main register',
'currency' => 'GHS',
'service_style' => 'retail',
'printer_paper_mm' => 80,
'receipt_logo' => UploadedFile::fake()->image('logo.png', 120, 120),
])
->assertRedirect();
$location = PosLocation::where('owner_ref', $user->public_id)->firstOrFail();
$this->assertNotNull($location->receipt_logo_path);
Storage::disk('public')->assertExists($location->receipt_logo_path);
}
public function test_receipt_page_shows_uploaded_logo(): void
{
Storage::fake('public');
$user = $this->user();
$logoPath = 'pos/receipt-logos/'.$user->public_id.'/logo.png';
Storage::disk('public')->put($logoPath, UploadedFile::fake()->image('logo.png', 120, 120)->getContent());
$location = PosLocation::create([
'owner_ref' => $user->public_id,
'name' => 'Main register',
'currency' => 'GHS',
'receipt_header' => 'Acme Shop',
'receipt_logo_path' => $logoPath,
'printer_paper_mm' => 80,
]);
$sale = PosSale::create([
'owner_ref' => $user->public_id,
'location_id' => $location->id,
'reference' => 'POS-LOGO',
'currency' => 'GHS',
'status' => 'paid',
'payment_method' => 'cash',
'total_minor' => 1000,
]);
$sale->lines()->create([
'name' => 'Tea',
'unit_price_minor' => 1000,
'quantity' => 1,
'line_total_minor' => 1000,
]);
$this->actingAs($user)
->get(route('pos.sales.receipt', $sale))
->assertOk()
->assertSee('brand-logo', false)
->assertSee('Acme Shop')
->assertSee('POS-LOGO');
}
}