Files
api/services/nginx/app/tests/Unit/Orders/OrderBookingsCompletionDedupTest.php
T
Jeppe Bundgaard ebf7e820d5 Add safety seal support to orders and related logic for wash certificates
- Introduced `safety_seal` column in the `orders` table.
- Updated order creation and completion logic to handle safety seal values.
- Enhanced order and booking classes to manage safety seal attachment and retrieval.
- Added tests to validate safety seal functionality in order processing.
2026-04-14 10:51:25 +02:00

105 lines
3.3 KiB
PHP

<?php
app_require('classes/object_property.php');
app_require('objects/order_bookings_o.php');
app_require('objects/orders_o.php');
use classes\object_property;
use objects\order_bookings_o;
use objects\orders_o;
if (!class_exists('OrderBookingsCompletionOrderDouble')) {
class OrderBookingsCompletionOrderDouble extends orders_o
{
public function __construct()
{
$this->id = -1;
$this->booking_id = new object_property('orders', -1, 'booking_id', 'int', false);
$this->safety_seal = new object_property('orders', -1, 'safety_seal', 'string', false);
$this->completed_at = new object_property('orders', -1, 'completed_at', 'timestamp', false);
}
public function objectChanged(): void
{
}
}
}
if (!class_exists('OrderBookingsCompletionDouble')) {
class OrderBookingsCompletionDouble extends order_bookings_o
{
public bool $containsWashCertificate = false;
public bool $orderWasCreated = false;
public bool $orderItemsWereCreated = false;
public int $attachCalls = 0;
public int $sendCalls = 0;
public orders_o $linkedOrder;
public function __construct(orders_o $linkedOrder)
{
$this->id = -1;
$this->linkedOrder = $linkedOrder;
$this->order_id = new object_property('order_bookings', -1, 'order_id', 'int', false);
$this->items = new object_property('order_bookings', -1, 'items', 'json', false);
$this->items->set([]);
}
public function createOrderBy(int $user_id): void
{
$this->orderWasCreated = true;
$this->order_id->set(999);
}
public function createOrderItemsBy(int $user_id): void
{
$this->orderItemsWereCreated = true;
}
public function containsWashCertificateItem(): bool
{
return $this->containsWashCertificate;
}
public function getOrder(): orders_o
{
return $this->linkedOrder;
}
protected function attachWashCertificate(int $user_id, string $safety_seal = null): void
{
$this->attachCalls++;
}
public function sendWashCertificateToCustomer(): void
{
$this->sendCalls++;
}
}
}
it('does not create or email a duplicate wash certificate when a booking is already linked to a pos order', function (): void {
$order = new OrderBookingsCompletionOrderDouble();
$booking = new OrderBookingsCompletionDouble($order);
$booking->order_id->set(321);
$booking->containsWashCertificate = true;
$booking->completeBooking(77, 'LINKED-SEAL');
expect($order->getSafetySealValue())->toBe('LINKED-SEAL');
expect($booking->attachCalls)->toBe(0);
expect($booking->sendCalls)->toBe(0);
});
it('keeps standalone booking completion behavior unchanged for wash certificates', function (): void {
$order = new OrderBookingsCompletionOrderDouble();
$booking = new OrderBookingsCompletionDouble($order);
$booking->containsWashCertificate = true;
$booking->completeBooking(77, null);
expect($booking->orderWasCreated)->toBeTrue();
expect($booking->orderItemsWereCreated)->toBeTrue();
expect($booking->attachCalls)->toBe(1);
expect($booking->sendCalls)->toBe(1);
});