-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathdiscount.test.liquid
More file actions
113 lines (105 loc) · 2.63 KB
/
discount.test.liquid
File metadata and controls
113 lines (105 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { describe, it, expect } from "vitest";
import { generateCartRun } from "./generate_cart_run";
import { generateDeliveryRun } from "./generate_delivery_run";
import {
OrderDiscountSelectionStrategy,
ProductDiscountSelectionStrategy,
DeliveryDiscountSelectionStrategy,
} from "../generated/api";
describe("discount", () => {
it("cart.lines.discounts.generate.run returns a product and order discount", () => {
const input = {
cart: {
lines: [
{
id: "gid://shopify/CartLine/0",
cost: {
subtotalAmount: 100,
},
},
],
},
};
const result = generateCartRun(input);
expect(result.operations.length).toBe(2);
expect(result.operations[0]).toMatchObject({
orderDiscountsAdd: {
candidates: [
{
message: "10% OFF ORDER",
targets: [
{
orderSubtotal: {
excludedCartLineIds: [],
},
},
],
value: {
percentage: {
value: 10,
},
},
},
],
selectionStrategy: OrderDiscountSelectionStrategy.First,
},
});
expect(result.operations[1]).toMatchObject({
productDiscountsAdd: {
candidates: [
{
message: "20% OFF PRODUCT",
targets: [
{
cartLine: {
id: "gid://shopify/CartLine/0",
},
},
],
value: {
percentage: {
value: 20,
},
},
},
],
selectionStrategy: ProductDiscountSelectionStrategy.First,
},
});
});
it("cart.delivery-options.generate.run returns a delivery discount", () => {
const input = {
cart: {
deliveryGroups: [
{
id: "gid://shopify/DeliveryGroup/0",
},
],
},
};
const result = generateDeliveryRun(input);
expect(result.operations.length).toBe(1);
expect(result.operations[0]).toMatchObject({
deliveryDiscountsAdd: {
candidates: [
{
message: "FREE DELIVERY",
targets: [
{
deliveryGroup: {
id: "gid://shopify/DeliveryGroup/0",
},
},
],
value: {
percentage: {
value: 100,
},
},
},
],
selectionStrategy: DeliveryDiscountSelectionStrategy.All,
},
});
});
});