← back to Filemaker Mcp
scripts/smoke-invoice-b.mjs
38 lines
import { createInvoiceForOrder } from '../lib/invoice.js';
const cases = [
{ label: '32759-like — SINGLE sample (was broken → "Samples")',
order: { order_number: 999759, total_tax: 0,
customer: { first_name: 'Elizabeth', last_name: 'Comstock' },
shipping_address: { company: '', address1: '4911 Dartford Pl', city: 'Granite Bay', province_code: 'CA', zip: '95746', country_code: 'US' },
shipping_lines: [{ title: 'Free Shipping', price: '0' }],
line_items: [ { sku: 'DWWM-14847-Sample', name: 'Sand', price: '4.25', quantity: 1, variant_title: 'Sample' } ] } },
{ label: '32760-like — 3 samples (money on FIRST only)',
order: { order_number: 999760, total_tax: 0,
customer: { first_name: 'joyce', last_name: 'eaton' },
shipping_address: { company: '', address1: '2104 Monticello', city: 'Springdale', province_code: 'AR', zip: '72762', country_code: 'US' },
shipping_lines: [{ title: 'UPS Ground', price: '0' }],
line_items: [
{ sku: 'DWPN-100258-Sample', name: 'Astor Basketball', price: '4.25', quantity: 1, variant_title: 'Sample' },
{ sku: 'DWPR-427799-Sample', name: 'Vintage Lipstick', price: '4.25', quantity: 1, variant_title: 'Sample' },
{ sku: 'DWPN-100195-Sample', name: 'Barbuda Brazen', price: '4.25', quantity: 1, variant_title: 'Sample' },
] } },
];
let pass = true;
for (const { label, order } of cases) {
const r = await createInvoiceForOrder(order, 'TEST-ACCT', { commit: false });
const L = r.moneyLine;
console.log(`\n=== ${label} ===`);
console.log(` MONEY line 1 : DETAIL="${L.detail}" Q=${L.qty} NET=$${L.price} ext=$${L.ext}`);
console.log(` $0 stubs : ${r.stubRecords.length ? r.stubRecords.map(s=>`${s.sku}($${s.dollars})`).join(', ') : '(none)'}`);
console.log(` merch total : $${r.merch} invoices=${r.invoiceCount}`);
const okSku = L.detail !== 'Samples' && /^[A-Za-z]+-?\d+/.test(L.detail);
const okMoney = Math.abs(L.ext - r.merch) < 0.001; // all money on the first line
const okStubs = r.stubRecords.every(s => s.dollars === 0); // rest are $0
console.log(` ASSERT: SKU-on-line=${okSku?'PASS':'FAIL'} money-on-first=${okMoney?'PASS':'FAIL'} stubs-$0=${okStubs?'PASS':'FAIL'}`);
if (!(okSku && okMoney && okStubs)) pass = false;
}
console.log(`\n==== SMOKE TEST ${pass ? 'PASS ✅' : 'FAIL ❌'} ====`);
process.exit(pass ? 0 : 1);