| 1 |
import { test, expect } from "@odoo/hoot"; |
| 2 |
import { mountWithCleanup } from "@web/../tests/web_test_helpers"; |
| 3 |
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils"; |
| 4 |
import { ControlButtons } from "@point_of_sale/app/screens/product_screen/control_buttons/control_buttons"; |
| 5 |
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions"; |
| 6 |
import { addProductLineToOrder } from "@pos_loyalty/../tests/unit/utils"; |
| 7 |
|
| 8 |
definePosModels(); |
| 9 |
|
| 10 |
test("_applyReward", async () => { |
| 11 |
const store = await setupPosEnv(); |
| 12 |
const models = store.models; |
| 13 |
const order = store.addNewOrder(); |
| 14 |
|
| 15 |
// Get card #1 - belongs to a loyalty-type program |
| 16 |
const card = models["loyalty.card"].get(1); |
| 17 |
// Get reward #2 - belongs to the same loyalty program, type = discount reward |
| 18 |
const reward = models["loyalty.reward"].get(2); |
| 19 |
|
| 20 |
await addProductLineToOrder(store, order); |
| 21 |
|
| 22 |
// Total quantity in the order |
| 23 |
const potentialQty = order.getOrderlines().reduce((acc, line) => acc + line.qty, 0); |
| 24 |
|
| 25 |
const component = await mountWithCleanup(ControlButtons, {}); |
| 26 |
|
| 27 |
const result = await component._applyReward(reward, card.id, potentialQty); |
| 28 |
|
| 29 |
expect(result).toBe(true); |
| 30 |
}); |
| 31 |
|
| 32 |
test("getPotentialRewards", async () => { |
| 33 |
const store = await setupPosEnv(); |
| 34 |
const models = store.models; |
| 35 |
const order = store.addNewOrder(); |
| 36 |
|
| 37 |
// Get loyalty program #1 - type = loyalty |
| 38 |
const loyaltyProgram = models["loyalty.program"].get(1); |
| 39 |
// Get card #1 - linked to loyalty program #1 |
| 40 |
const card = models["loyalty.card"].get(1); |
| 41 |
|
| 42 |
await addProductLineToOrder(store, order); |
| 43 |
order._code_activated_coupon_ids = [card]; |
| 44 |
|
| 45 |
const component = await mountWithCleanup(ControlButtons, {}); |
| 46 |
|
| 47 |
const rewards = component.getPotentialRewards(); |
| 48 |
const reward = rewards[0].reward; |
| 49 |
|
| 50 |
expect(reward).toEqual(models["loyalty.reward"].get(1)); |
| 51 |
expect(reward.program_id).toEqual(loyaltyProgram); |
| 52 |
}); |