| 1 |
import { expect, test } from "@odoo/hoot"; |
| 2 |
import OrderPaymentValidation from "@point_of_sale/app/utils/order_payment_validation"; |
| 3 |
import { getFilledOrder, setupPosEnv } from "../utils"; |
| 4 |
import { definePosModels } from "../data/generate_model_definitions"; |
| 5 |
|
| 6 |
definePosModels(); |
| 7 |
|
| 8 |
test("validateOrder", async () => { |
| 9 |
const store = await setupPosEnv(); |
| 10 |
const order = await getFilledOrder(store); |
| 11 |
const fastPaymentMethod = order.config.fast_payment_method_ids[0]; |
| 12 |
const validation = new OrderPaymentValidation({ |
| 13 |
pos: store, |
| 14 |
orderUuid: store.getOrder().uuid, |
| 15 |
fastPaymentMethod: fastPaymentMethod, |
| 16 |
}); |
| 17 |
await validation.validateOrder(false); |
| 18 |
expect(order.payment_ids[0].payment_method_id).toEqual(fastPaymentMethod); |
| 19 |
expect(order.state).toBe("paid"); |
| 20 |
expect(order.amount_paid).toBe(17.85); |
| 21 |
}); |
| 22 |
test("isOrderValid", async () => { |
| 23 |
const store = await setupPosEnv(); |
| 24 |
const order = store.addNewOrder(); |
| 25 |
order.setToInvoice(true); |
| 26 |
const validation = new OrderPaymentValidation({ |
| 27 |
pos: store, |
| 28 |
orderUuid: store.getOrder().uuid, |
| 29 |
}); |
| 30 |
const isOrderValid = await validation.isOrderValid(false); |
| 31 |
expect(order.lines).toHaveLength(0); |
| 32 |
expect(isOrderValid).toBe(false); // The order cannot be invoiced if the order line count is zero. |
| 33 |
}); |