Files
api/services/nginx/app/tests/Unit/Invoicing/InvoicingOrdersCalculationsHardeningTest.php
T
Jeppe Bundgaard 6c40810caf Add unit tests for invoicing period pagination, normalization, and filtering logic
- Implemented `InvoicingPeriodPaginationTest` for testing period pagination modes, normalization of options, search functionality, and visibility filters.
- Added comprehensive tests to validate scenarios such as active period views, exact counts, and customer-card level search.
- Improved cURL timeout settings with `CURLOPT_CONNECTTIMEOUT` and `CURLOPT_TIMEOUT` adjustments.
- Introduced and documented helper classes/methods for local caching, pagination response structure, and customer name retrieval.
2026-05-12 03:37:47 +02:00

59 lines
3.1 KiB
PHP

<?php
it('guards against empty order ids in net amount calculation', function (): void {
$ordersFile = app_path('objects/orders_o.php');
$content = file_get_contents($ordersFile);
expect($content)->not->toBeFalse();
expect($content)->toContain('public function getNetAmountForOrders(array $order_ids): array');
expect($content)->toContain('if (empty($order_ids)) {');
expect($content)->toContain('return [];');
});
it('guards against empty customer arrays in date-range transaction fetches', function (): void {
$ordersFile = app_path('objects/orders_o.php');
$content = file_get_contents($ordersFile);
expect($content)->not->toBeFalse();
expect($content)->toContain('public function getTransactionsForCustomersInDateRange(array $customers, string $dateFrom, string $dateTo): array');
expect($content)->toContain('if (empty($customers)) {');
expect($content)->toContain('return [];');
});
it('uses centralized duplicate filtering for possible duplicate detection', function (): void {
$ordersFile = app_path('objects/orders_o.php');
$content = file_get_contents($ordersFile);
expect($content)->not->toBeFalse();
expect($content)->toContain('invoicing_period_utils::filterPossibleDuplicates($orders, 86400)');
});
it('provides a batched plain-row transaction query for invoicing period responses', function (): void {
$ordersFile = app_path('objects/orders_o.php');
$content = file_get_contents($ordersFile);
expect($content)->not->toBeFalse();
$content = (string)$content;
expect($content)->toContain('public function getPeriodTransactionsForCustomersInDateRange(?array $customers, string $dateFrom, string $dateTo): array')
->and($content)->toContain('COALESCE(SUM(CASE WHEN oi.include_in_invoice = 1 THEN oi.price * oi.quantity ELSE 0 END), 0) AS net_amount')
->and($content)->toContain('COALESCE(coi.booked_invoice_id, 0)')
->and($content)->toContain('COALESCE(emo.invoice_id, 0)')
->and($content)->toContain('department_flags.exclude_from_invoicing')
->and($content)->not->toContain('$order->select((int)$row[\'id\']);' . PHP_EOL . ' $transactions[$customerNumber][]');
});
it('adds guarded composite indexes for invoicing period lookups', function (): void {
$schemaFile = app_path('classes/orders_schema_bootstrap.php');
$content = file_get_contents($schemaFile);
expect($content)->not->toBeFalse();
$content = (string)$content;
expect($content)->toContain("self::ensureIndex(\$db, 'orders', 'idx_orders_period_customer_created_deleted', 'customer_id, created_at, deleted_at')")
->and($content)->toContain("self::ensureIndex(\$db, 'orders', 'idx_orders_period_created_deleted_customer', 'created_at, deleted_at, customer_id')")
->and($content)->toContain("self::ensureIndex(\$db, 'order_items', 'idx_order_items_order_deleted', 'order_id, deleted_at')")
->and($content)->toContain("self::ensureIndex(\$db, 'customer_attributes', 'idx_customer_attributes_attribute_user', 'attribute, user_id')")
->and($content)->toContain('private static function indexExists(object $db, string $table, string $index): bool');
});