| 1 |
import { test, describe, expect } from "@odoo/hoot"; |
| 2 |
import { setupPosEnv } from "@point_of_sale/../tests/unit/utils"; |
| 3 |
import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions"; |
| 4 |
import { addProductLineToOrder } from "@pos_loyalty/../tests/unit/utils"; |
| 5 |
import { onRpc } from "@web/../tests/web_test_helpers"; |
| 6 |
|
| 7 |
definePosModels(); |
| 8 |
|
| 9 |
describe("PosStore - loyalty essentials", () => { |
| 10 |
test("updatePrograms", async () => { |
| 11 |
const store = await setupPosEnv(); |
| 12 |
const models = store.models; |
| 13 |
const order = store.addNewOrder(); |
| 14 |
|
| 15 |
const partner = models["res.partner"].get(1); |
| 16 |
|
| 17 |
const program = models["loyalty.program"].get(5); |
| 18 |
|
| 19 |
models["loyalty.program"].getAll = () => [program]; |
| 20 |
|
| 21 |
order.setPartner(partner); |
| 22 |
order._programIsApplicable = () => true; |
| 23 |
order._code_activated_coupon_ids = []; |
| 24 |
order.uiState.couponPointChanges = {}; |
| 25 |
order.pricelist_id = { id: 1 }; |
| 26 |
|
| 27 |
const line = await addProductLineToOrder(store, order, { |
| 28 |
gift_code: "XYZ123", |
| 29 |
}); |
| 30 |
|
| 31 |
order.pointsForPrograms = () => ({ |
| 32 |
[program.id]: [{ points: 10 }], |
| 33 |
}); |
| 34 |
|
| 35 |
await store.updatePrograms(); |
| 36 |
|
| 37 |
const changes = order.uiState.couponPointChanges; |
| 38 |
const changeList = Object.values(changes); |
| 39 |
|
| 40 |
expect(changeList).toHaveLength(1); |
| 41 |
expect(changeList[0].program_id).toBe(program.id); |
| 42 |
expect(changeList[0].points).toBe(10); |
| 43 |
expect(changeList[0].code).toBe("XYZ123"); |
| 44 |
expect(changeList[0].product_id).toBe(line.product_id.id); |
| 45 |
}); |
| 46 |
|
| 47 |
test("activateCode", async () => { |
| 48 |
onRpc("loyalty.card", "get_loyalty_card_partner_by_code", () => false); |
| 49 |
const store = await setupPosEnv(); |
| 50 |
store.addNewOrder(); |
| 51 |
const result = await store.activateCode("EXPIRED"); |
| 52 |
|
| 53 |
expect(result).toBe(true); |
| 54 |
}); |
| 55 |
|
| 56 |
test("fetchLoyaltyCard", async () => { |
| 57 |
const store = await setupPosEnv(); |
| 58 |
const models = store.models; |
| 59 |
|
| 60 |
|
| 61 |
const program = models["loyalty.program"].get(2); |
| 62 |
const partner = models["res.partner"].get(1); |
| 63 |
|
| 64 |
const card = await store.fetchLoyaltyCard(program.id, partner.id); |
| 65 |
|
| 66 |
expect(card.id).toBe(2); |
| 67 |
}); |
| 68 |
}); |