<?php

it('wires order create and update routes through the settings normalizers', function (): void {
    $routeFile = app_path('routes/ordersRoute.php');
    $content = file_get_contents($routeFile);

    expect($content)->not->toBeFalse();
    expect($content)->toContain('use classes\orders_input_normalizer;');
    expect($content)->toContain("orders_input_normalizer::normalizeCreatedAt(\$data['created_at'] ?? date('Y-m-d H:i:s'))");
    expect($content)->toContain("array_key_exists('include_in_invoice', \$data)");
    expect($content)->toContain("orders_input_normalizer::normalizeIncludeInInvoice(\$data['include_in_invoice'])");
    expect($content)->toContain("\$order->include_in_invoice->set(");
    expect($content)->toContain("\$response->error(\$e->getMessage(), 400);");
});

it('keeps line-item invoice filtering in the order net amount calculation', function (): void {
    $objectFile = app_path('objects/orders_o.php');
    $content = file_get_contents($objectFile);

    expect($content)->not->toBeFalse();
    expect($content)->toContain("'include_in_invoice' => \$this->getIncludeInInvoiceOverride()");
    expect($content)->toContain("'include_in_invoice_effective' => \$this->isIncludedInInvoicing()");
    expect($content)->toContain("if (!\$item['include_in_invoice'])");
});
