<?php

it('wires collected invoice customer moves through the dedicated route and permission', function (): void {
    $routeContent = file_get_contents(app_path('routes/orderInvoicesRoute.php'));
    $objectContent = file_get_contents(app_path('objects/collected_order_invoices_o.php'));

    expect($routeContent)->not->toBeFalse()
        ->and($routeContent)->toContain("\$this->post('/collected-invoices/move-to-customer'")
        ->and($routeContent)->toContain("self::requirePermission('move_collected_invoice_customer')")
        ->and($routeContent)->toContain('$collected_order_invoices->moveToCustomer')
        ->and($routeContent)->toContain("\$response->add_meta('move', \$move_result)")
        ->and($objectContent)->not->toBeFalse()
        ->and($objectContent)->toContain('public function moveToCustomer(int $target_customer_number): array')
        ->and($objectContent)->toContain('Invoice collections with an external or booked invoice cannot be moved')
        ->and($objectContent)->toContain('SELECT id FROM orders WHERE invoice_collection_id = {$invoice_collection_id}')
        ->and($objectContent)->toContain('$order->customer_id->set($target_customer_number)')
        ->and($objectContent)->toContain('$this->customer_number->set($target_customer_number)')
        ->and($objectContent)->toContain('$db->conn()->begin_transaction()');
});
