Skip to content

Commit 23d993b

Browse files
committed
Split large test suite into smaller groups of tests.
1 parent 6838802 commit 23d993b

6 files changed

Lines changed: 1885 additions & 2354 deletions

File tree

Lines changed: 370 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,370 @@
1+
import {
2+
makePackRow,
3+
makeVariantRow,
4+
parseWorkbook,
5+
} from "../test-helpers/parse-excel";
6+
7+
describe("parse-excel letter variants", () => {
8+
it("parses canonical enum values", () => {
9+
const result = parseWorkbook({
10+
packs: [
11+
makePackRow({
12+
id: "pack-1",
13+
"postage.id": "postage-standard",
14+
"postage.size": "STANDARD",
15+
}),
16+
makePackRow({
17+
id: "pack-2",
18+
name: "Pack 2",
19+
billingId: "billing-pack-2",
20+
"postage.id": "postage-large",
21+
"postage.size": "LARGE",
22+
}),
23+
],
24+
variants: [
25+
makeVariantRow({
26+
id: "variant-1",
27+
volumeGroupId: "volume-group-1",
28+
packSpecificationIds: "pack-1,pack-2",
29+
}),
30+
],
31+
});
32+
33+
expect(result.packs.pack1.postage.id).toBe("postage-standard");
34+
expect(result.packs.pack1.postage.size).toBe("STANDARD");
35+
expect(result.packs.pack2.postage.id).toBe("postage-large");
36+
expect(result.packs.pack2.postage.size).toBe("LARGE");
37+
expect(result.variants.variant1.packSpecificationIds).toEqual([
38+
"pack-1",
39+
"pack-2",
40+
]);
41+
});
42+
43+
it("parses constraints on LetterVariant", () => {
44+
const result = parseWorkbook({
45+
packs: [makePackRow()],
46+
variants: [
47+
makeVariantRow({
48+
id: "variant-with-constraints",
49+
name: "Variant with Constraints",
50+
description: "Test variant",
51+
"constraints.sheets": "8",
52+
"constraints.deliveryDays": "3",
53+
}),
54+
],
55+
});
56+
57+
expect(result.variants.variantwithconstraints.constraints).toEqual({
58+
sheets: { value: 8, operator: "LESS_THAN" },
59+
deliveryDays: { value: 3, operator: "LESS_THAN" },
60+
});
61+
});
62+
63+
it("throws if LetterVariant type is invalid", () => {
64+
expect(() =>
65+
parseWorkbook({
66+
packs: [makePackRow()],
67+
variants: [
68+
makeVariantRow({
69+
id: "variant-1",
70+
type: "INVALID_TYPE",
71+
}),
72+
],
73+
}),
74+
).toThrow(/Validation failed.*variant-1/);
75+
});
76+
77+
it("parses LetterVariant with optional clientId and campaignIds", () => {
78+
const result = parseWorkbook({
79+
packs: [makePackRow()],
80+
variants: [
81+
makeVariantRow({
82+
id: "variant-with-ids",
83+
name: "Variant with IDs",
84+
description: "Test variant",
85+
clientId: "client-123",
86+
campaignIds: "campaign-1,campaign-2,campaign-3",
87+
}),
88+
],
89+
});
90+
91+
expect(result.variants.variantwithids.clientId).toBe("client-123");
92+
expect(result.variants.variantwithids.campaignIds).toEqual([
93+
"campaign-1",
94+
"campaign-2",
95+
"campaign-3",
96+
]);
97+
});
98+
99+
it("parses LetterVariant with optional supplierId", () => {
100+
const result = parseWorkbook({
101+
packs: [makePackRow()],
102+
variants: [
103+
makeVariantRow({
104+
id: "variant-with-supplier",
105+
name: "Variant with Supplier",
106+
description: "Test variant scoped to supplier",
107+
supplierId: "supplier-printco",
108+
}),
109+
],
110+
});
111+
112+
expect(result.variants.variantwithsupplier.supplierId).toBe(
113+
"supplier-printco",
114+
);
115+
});
116+
117+
it("parses LetterVariant priority when provided", () => {
118+
const result = parseWorkbook({
119+
packs: [
120+
makePackRow({
121+
id: "pack-priority",
122+
name: "Pack Priority",
123+
billingId: "billing-pack-priority",
124+
"postage.id": "postage-priority",
125+
}),
126+
],
127+
variants: [
128+
makeVariantRow({
129+
id: "variant-priority",
130+
name: "Variant Priority",
131+
volumeGroupId: "volume-group-priority",
132+
packSpecificationIds: "pack-priority",
133+
priority: 12,
134+
}),
135+
],
136+
volumeGroups: [
137+
{
138+
id: "volume-group-priority",
139+
name: "VolumeGroup Priority",
140+
startDate: "2025-01-01",
141+
status: "PROD",
142+
},
143+
],
144+
});
145+
146+
expect(result.variants.variantpriority.priority).toBe(12);
147+
});
148+
149+
it("uses the LetterVariant priority default when omitted", () => {
150+
const result = parseWorkbook({
151+
packs: [
152+
makePackRow({
153+
id: "pack-default-priority",
154+
name: "Pack Default Priority",
155+
billingId: "billing-pack-default-priority",
156+
"postage.id": "postage-default-priority",
157+
}),
158+
],
159+
variants: [
160+
makeVariantRow({
161+
id: "variant-default-priority",
162+
name: "Variant Default Priority",
163+
volumeGroupId: "volume-group-default-priority",
164+
packSpecificationIds: "pack-default-priority",
165+
}),
166+
],
167+
volumeGroups: [
168+
{
169+
id: "volume-group-default-priority",
170+
name: "VolumeGroup Default Priority",
171+
startDate: "2025-01-01",
172+
status: "PROD",
173+
},
174+
],
175+
});
176+
177+
expect(result.variants.variantdefaultpriority.priority).toBe(50);
178+
});
179+
180+
it("uses the LetterVariant priority default when the Excel cell is blank", () => {
181+
const result = parseWorkbook({
182+
packs: [
183+
makePackRow({
184+
id: "pack-blank-priority",
185+
name: "Pack Blank Priority",
186+
billingId: "billing-pack-blank-priority",
187+
"postage.id": "postage-blank-priority",
188+
}),
189+
],
190+
variants: [
191+
makeVariantRow({
192+
id: "variant-blank-priority",
193+
name: "Variant Blank Priority",
194+
volumeGroupId: "volume-group-blank-priority",
195+
packSpecificationIds: "pack-blank-priority",
196+
priority: " ",
197+
}),
198+
],
199+
volumeGroups: [
200+
{
201+
id: "volume-group-blank-priority",
202+
name: "VolumeGroup Blank Priority",
203+
startDate: "2025-01-01",
204+
status: "PROD",
205+
},
206+
],
207+
});
208+
209+
expect(result.variants.variantblankpriority.priority).toBe(50);
210+
});
211+
212+
it("throws when LetterVariant priority is outside the allowed range", () => {
213+
expect(() =>
214+
parseWorkbook({
215+
packs: [
216+
makePackRow({
217+
id: "pack-invalid-priority",
218+
name: "Pack Invalid Priority",
219+
billingId: "billing-pack-invalid-priority",
220+
"postage.id": "postage-invalid-priority",
221+
}),
222+
],
223+
variants: [
224+
makeVariantRow({
225+
id: "variant-invalid-priority",
226+
name: "Variant Invalid Priority",
227+
volumeGroupId: "volume-group-invalid-priority",
228+
packSpecificationIds: "pack-invalid-priority",
229+
priority: 100,
230+
}),
231+
],
232+
volumeGroups: [
233+
{
234+
id: "volume-group-invalid-priority",
235+
name: "VolumeGroup Invalid Priority",
236+
startDate: "2025-01-01",
237+
status: "PROD",
238+
},
239+
],
240+
}),
241+
).toThrow(/Validation failed.*variant-invalid-priority/);
242+
});
243+
244+
it("uses name as description when description is missing", () => {
245+
const result = parseWorkbook({
246+
packs: [makePackRow()],
247+
variants: [
248+
makeVariantRow({
249+
id: "variant-no-desc",
250+
name: "My Variant Name",
251+
description: undefined,
252+
}),
253+
],
254+
});
255+
256+
expect(result.variants.variantnodesc.description).toBe("My Variant Name");
257+
});
258+
259+
it("throws on empty packSpecificationIds", () => {
260+
expect(() =>
261+
parseWorkbook({
262+
packs: [makePackRow()],
263+
variants: [
264+
makeVariantRow({
265+
id: "variant-no-packs",
266+
name: "Variant No Packs",
267+
description: "Test",
268+
packSpecificationIds: "",
269+
}),
270+
],
271+
}),
272+
).toThrow(/Validation failed.*variant-no-packs/);
273+
});
274+
275+
it("leaves letter variant constraints undefined when none are provided", () => {
276+
const result = parseWorkbook({
277+
packs: [
278+
makePackRow({
279+
id: "pack-no-constraints",
280+
name: "Pack No Constraints",
281+
billingId: "billing-pack-no-constraints",
282+
}),
283+
],
284+
variants: [
285+
makeVariantRow({
286+
id: "variant-no-constraints",
287+
name: "Variant No Constraints",
288+
volumeGroupId: "volume-group-nc",
289+
packSpecificationIds: "pack-no-constraints",
290+
}),
291+
],
292+
volumeGroups: [
293+
{
294+
id: "volume-group-nc",
295+
name: "VolumeGroup NC",
296+
startDate: "2025-01-01",
297+
status: "PROD",
298+
},
299+
],
300+
});
301+
302+
expect(result.variants.variantnoconstraints.constraints).toBeUndefined();
303+
});
304+
305+
it("trims spaces in campaignIds and packSpecificationIds", () => {
306+
const result = parseWorkbook({
307+
packs: [
308+
makePackRow({
309+
id: "pack-space-1",
310+
name: "Pack Space 1",
311+
billingId: "billing-pack-space-1",
312+
"postage.id": "postage-space-1",
313+
}),
314+
makePackRow({
315+
id: "pack-space-2",
316+
name: "Pack Space 2",
317+
billingId: "billing-pack-space-2",
318+
"postage.id": "postage-space-2",
319+
}),
320+
],
321+
variants: [
322+
makeVariantRow({
323+
id: "variant-space",
324+
name: "Variant Space",
325+
volumeGroupId: "volume-group-space",
326+
packSpecificationIds: " pack-space-1 , pack-space-2 ",
327+
campaignIds: " campaign-1 , campaign-2 ",
328+
}),
329+
],
330+
volumeGroups: [
331+
{
332+
id: "volume-group-space",
333+
name: "VolumeGroup Space",
334+
startDate: "2025-01-01",
335+
status: "PROD",
336+
},
337+
],
338+
});
339+
340+
expect(result.variants.variantspace.packSpecificationIds).toEqual([
341+
"pack-space-1",
342+
"pack-space-2",
343+
]);
344+
expect(result.variants.variantspace.campaignIds).toEqual([
345+
"campaign-1",
346+
"campaign-2",
347+
]);
348+
});
349+
350+
it("parses constraints.sides on LetterVariant", () => {
351+
const result = parseWorkbook({
352+
packs: [makePackRow()],
353+
variants: [
354+
makeVariantRow({
355+
id: "variant-with-sides",
356+
name: "Variant with Sides Constraint",
357+
"constraints.sheets": "8",
358+
"constraints.sides": "16",
359+
"constraints.deliveryDays": "3",
360+
}),
361+
],
362+
});
363+
364+
expect(result.variants.variantwithsides.constraints).toEqual({
365+
sheets: { value: 8, operator: "LESS_THAN" },
366+
sides: { value: 16, operator: "LESS_THAN" },
367+
deliveryDays: { value: 3, operator: "LESS_THAN" },
368+
});
369+
});
370+
});

0 commit comments

Comments
 (0)