Skip to content

Commit 200d1d9

Browse files
committed
Split test files
1 parent a7d057e commit 200d1d9

File tree

2 files changed

+146
-15
lines changed

2 files changed

+146
-15
lines changed

discounts/javascript/discount/default/src/discount.test.liquid renamed to discounts/javascript/discount/default/src/generate_cart_run.test.liquid

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
{%- if flavor contains "vanilla-js" -%}
12
import { describe, it, expect } from "vitest";
23

34
import { generateCartRun } from "./generate_cart_run";
4-
import { generateDeliveryRun } from "./generate_delivery_run";
55
import {
66
OrderDiscountSelectionStrategy,
77
ProductDiscountSelectionStrategy,
8-
DeliveryDiscountSelectionStrategy,
98
} from "../generated/api";
109

11-
describe("discount", () => {
12-
it("cart.lines.discounts.generate.run returns a product and order discount", () => {
10+
describe("generateCartRun", () => {
11+
it("returns a product and order discount", () => {
1312
const input = {
1413
cart: {
1514
lines: [
@@ -72,42 +71,79 @@ describe("discount", () => {
7271
},
7372
});
7473
});
74+
});
75+
{%- elsif flavor contains "typescript" -%}
76+
import { describe, it, expect } from "vitest";
7577

76-
it("cart.delivery-options.generate.run returns a delivery discount", () => {
78+
import { generateCartRun } from "./generate_cart_run";
79+
import {
80+
OrderDiscountSelectionStrategy,
81+
ProductDiscountSelectionStrategy,
82+
} from "../generated/api";
83+
84+
describe("generateCartRun", () => {
85+
it("returns a product and order discount", () => {
7786
const input = {
7887
cart: {
79-
deliveryGroups: [
88+
lines: [
8089
{
81-
id: "gid://shopify/DeliveryGroup/0",
90+
id: "gid://shopify/CartLine/0",
91+
cost: {
92+
subtotalAmount: 100,
93+
},
8294
},
8395
],
8496
},
8597
};
8698

87-
const result = generateDeliveryRun(input);
99+
const result = generateCartRun(input);
88100

89-
expect(result.operations.length).toBe(1);
101+
expect(result.operations.length).toBe(2);
90102
expect(result.operations[0]).toMatchObject({
91-
deliveryDiscountsAdd: {
103+
orderDiscountsAdd: {
104+
candidates: [
105+
{
106+
message: "10% OFF ORDER",
107+
targets: [
108+
{
109+
orderSubtotal: {
110+
excludedCartLineIds: [],
111+
},
112+
},
113+
],
114+
value: {
115+
percentage: {
116+
value: 10,
117+
},
118+
},
119+
},
120+
],
121+
selectionStrategy: OrderDiscountSelectionStrategy.First,
122+
},
123+
});
124+
125+
expect(result.operations[1]).toMatchObject({
126+
productDiscountsAdd: {
92127
candidates: [
93128
{
94-
message: "FREE DELIVERY",
129+
message: "20% OFF PRODUCT",
95130
targets: [
96131
{
97-
deliveryGroup: {
98-
id: "gid://shopify/DeliveryGroup/0",
132+
cartLine: {
133+
id: "gid://shopify/CartLine/0",
99134
},
100135
},
101136
],
102137
value: {
103138
percentage: {
104-
value: 100,
139+
value: 20,
105140
},
106141
},
107142
},
108143
],
109-
selectionStrategy: DeliveryDiscountSelectionStrategy.All,
144+
selectionStrategy: ProductDiscountSelectionStrategy.First,
110145
},
111146
});
112147
});
113148
});
149+
{%- endif -%}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{%- if flavor contains "vanilla-js" -%}
2+
import { describe, it, expect } from "vitest";
3+
4+
import { generateDeliveryRun } from "./generate_delivery_run";
5+
import {
6+
DeliveryDiscountSelectionStrategy,
7+
} from "../generated/api";
8+
9+
describe("generateDeliveryRun", () => {
10+
it("returns a delivery discount", () => {
11+
const input = {
12+
cart: {
13+
deliveryGroups: [
14+
{
15+
id: "gid://shopify/DeliveryGroup/0",
16+
},
17+
],
18+
},
19+
};
20+
21+
const result = generateDeliveryRun(input);
22+
23+
expect(result.operations.length).toBe(1);
24+
expect(result.operations[0]).toMatchObject({
25+
deliveryDiscountsAdd: {
26+
candidates: [
27+
{
28+
message: "FREE DELIVERY",
29+
targets: [
30+
{
31+
deliveryGroup: {
32+
id: "gid://shopify/DeliveryGroup/0",
33+
},
34+
},
35+
],
36+
value: {
37+
percentage: {
38+
value: 100,
39+
},
40+
},
41+
},
42+
],
43+
selectionStrategy: DeliveryDiscountSelectionStrategy.All,
44+
},
45+
});
46+
});
47+
});
48+
{%- elsif flavor contains "typescript" -%}
49+
import { describe, it, expect } from "vitest";
50+
51+
import { generateDeliveryRun } from "./generate_delivery_run";
52+
import {
53+
DeliveryDiscountSelectionStrategy,
54+
} from "../generated/api";
55+
56+
describe("generateDeliveryRun", () => {
57+
it("returns a delivery discount", () => {
58+
const input = {
59+
cart: {
60+
deliveryGroups: [
61+
{
62+
id: "gid://shopify/DeliveryGroup/0",
63+
},
64+
],
65+
},
66+
};
67+
68+
const result = generateDeliveryRun(input);
69+
70+
expect(result.operations.length).toBe(1);
71+
expect(result.operations[0]).toMatchObject({
72+
deliveryDiscountsAdd: {
73+
candidates: [
74+
{
75+
message: "FREE DELIVERY",
76+
targets: [
77+
{
78+
deliveryGroup: {
79+
id: "gid://shopify/DeliveryGroup/0",
80+
},
81+
},
82+
],
83+
value: {
84+
percentage: {
85+
value: 100,
86+
},
87+
},
88+
},
89+
],
90+
selectionStrategy: DeliveryDiscountSelectionStrategy.All,
91+
},
92+
});
93+
});
94+
});
95+
{%- endif -%}

0 commit comments

Comments
 (0)