Skip to content

Commit c5d9d4f

Browse files
Copied schemas from nhd-notify-supplier-config - DO NOT MERGE THIS PR
1 parent fa5d2e1 commit c5d9d4f

19 files changed

Lines changed: 942 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { PackSpecification } from "./pack-specification";
2+
import { $SupplierPack, SupplierPack } from "../supplier-pack";
3+
4+
describe("SpecificationSupplier schema validation", () => {
5+
const standardLetterSpecification: PackSpecification = {
6+
id: "standard-letter" as any,
7+
name: "Standard Economy-class Letter",
8+
status: "PROD",
9+
createdAt: "2023-01-01T00:00:00Z",
10+
updatedAt: "2023-01-01T00:00:00Z",
11+
version: 1,
12+
postage: {
13+
id: "economy",
14+
size: "STANDARD",
15+
deliveryDays: 4,
16+
},
17+
assembly: {
18+
envelopeId: "nhs-economy",
19+
printColour: "BLACK",
20+
},
21+
};
22+
23+
const testSupplierPack: SupplierPack = {
24+
id: "test-specification-supplier" as any,
25+
packSpecificationId: standardLetterSpecification.id,
26+
supplierId: "supplier-123",
27+
approval: "APPROVED",
28+
status: "PROD",
29+
};
30+
31+
it("should validate a specification supplier", () => {
32+
expect(() => $SupplierPack.parse(testSupplierPack)).not.toThrow();
33+
});
34+
35+
describe("approval status validation", () => {
36+
it("should accept DRAFT approval status", () => {
37+
const supplierPack = { ...testSupplierPack, approval: "DRAFT" };
38+
expect(() => $SupplierPack.parse(supplierPack)).not.toThrow();
39+
});
40+
41+
it("should accept SUBMITTED approval status", () => {
42+
const supplierPack = { ...testSupplierPack, approval: "SUBMITTED" };
43+
expect(() => $SupplierPack.parse(supplierPack)).not.toThrow();
44+
});
45+
46+
it("should accept PROOF_RECEIVED approval status", () => {
47+
const supplierPack = { ...testSupplierPack, approval: "PROOF_RECEIVED" };
48+
expect(() => $SupplierPack.parse(supplierPack)).not.toThrow();
49+
});
50+
51+
it("should accept APPROVED approval status", () => {
52+
const supplierPack = { ...testSupplierPack, approval: "APPROVED" };
53+
expect(() => $SupplierPack.parse(supplierPack)).not.toThrow();
54+
});
55+
56+
it("should accept REJECTED approval status", () => {
57+
const supplierPack = { ...testSupplierPack, approval: "REJECTED" };
58+
expect(() => $SupplierPack.parse(supplierPack)).not.toThrow();
59+
});
60+
61+
it("should accept DISABLED approval status", () => {
62+
const supplierPack = { ...testSupplierPack, approval: "DISABLED" };
63+
expect(() => $SupplierPack.parse(supplierPack)).not.toThrow();
64+
});
65+
66+
it("should reject invalid approval status", () => {
67+
const supplierPack = { ...testSupplierPack, approval: "INVALID_STATUS" };
68+
expect(() => $SupplierPack.parse(supplierPack)).toThrow();
69+
});
70+
});
71+
});
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import { $PackSpecification, PackSpecification } from "./pack-specification";
2+
3+
describe("Specification schema validation", () => {
4+
const standardLetterSpecification: PackSpecification = {
5+
id: "standard-letter",
6+
name: "Standard Economy-class Letter",
7+
status: "INT",
8+
createdAt: "2023-01-01T00:00:00Z",
9+
updatedAt: "2023-01-01T00:00:00Z",
10+
version: 1,
11+
postage: {
12+
id: "economy",
13+
size: "STANDARD",
14+
deliveryDays: 4,
15+
},
16+
assembly: {
17+
envelopeId: "nhs-economy",
18+
printColour: "BLACK",
19+
},
20+
};
21+
22+
it("should validate a standard letter specification", () => {
23+
expect(() =>
24+
$PackSpecification.strict().parse(standardLetterSpecification),
25+
).not.toThrow();
26+
});
27+
28+
it("should accept a letter specification with unrecognised fields", () => {
29+
expect(() =>
30+
$PackSpecification.parse({
31+
...standardLetterSpecification,
32+
additionalField: { some: "data" },
33+
}),
34+
).not.toThrow();
35+
});
36+
37+
it("should validate a specification with optional description", () => {
38+
const specWithDescription: PackSpecification = {
39+
...standardLetterSpecification,
40+
description: "A standard economy-class letter for bulk mailings",
41+
};
42+
43+
expect(() =>
44+
$PackSpecification.strict().parse(specWithDescription),
45+
).not.toThrow();
46+
});
47+
48+
it("should validate a specification without description", () => {
49+
const specWithoutDescription: PackSpecification = {
50+
...standardLetterSpecification,
51+
};
52+
53+
expect(() =>
54+
$PackSpecification.strict().parse(specWithoutDescription),
55+
).not.toThrow();
56+
});
57+
58+
it("should validate a specification with duplex set to true", () => {
59+
const specWithDuplex: PackSpecification = {
60+
...standardLetterSpecification,
61+
assembly: {
62+
...standardLetterSpecification.assembly,
63+
duplex: true,
64+
},
65+
};
66+
67+
expect(() =>
68+
$PackSpecification.strict().parse(specWithDuplex),
69+
).not.toThrow();
70+
});
71+
72+
it("should validate a specification with duplex set to false", () => {
73+
const specWithoutDuplex: PackSpecification = {
74+
...standardLetterSpecification,
75+
assembly: {
76+
...standardLetterSpecification.assembly,
77+
duplex: false,
78+
},
79+
};
80+
81+
expect(() =>
82+
$PackSpecification.strict().parse(specWithoutDuplex),
83+
).not.toThrow();
84+
});
85+
86+
it("should validate a specification without duplex field", () => {
87+
const specWithoutDuplexField: PackSpecification = {
88+
...standardLetterSpecification,
89+
};
90+
91+
expect(() =>
92+
$PackSpecification.strict().parse(specWithoutDuplexField),
93+
).not.toThrow();
94+
});
95+
96+
it("should validate a specification with constraints", () => {
97+
const specWithConstraints: PackSpecification = {
98+
...standardLetterSpecification,
99+
constraints: {
100+
sheets: {
101+
value: 10,
102+
operator: "LESS_THAN",
103+
},
104+
deliveryDays: {
105+
value: 4,
106+
operator: "LESS_THAN",
107+
},
108+
},
109+
};
110+
111+
expect(() =>
112+
$PackSpecification.strict().parse(specWithConstraints),
113+
).not.toThrow();
114+
});
115+
116+
it("should validate a specification with all constraint fields", () => {
117+
const specWithConstraints: PackSpecification = {
118+
...standardLetterSpecification,
119+
constraints: {
120+
deliveryDays: {
121+
value: 5,
122+
operator: "EQUALS",
123+
},
124+
sheets: {
125+
value: 20,
126+
operator: "LESS_THAN",
127+
},
128+
sides: {
129+
value: 4,
130+
operator: "LESS_THAN",
131+
},
132+
blackCoveragePercentage: {
133+
value: 80,
134+
operator: "LESS_THAN",
135+
},
136+
colourCoveragePercentage: {
137+
value: 50,
138+
operator: "LESS_THAN",
139+
},
140+
},
141+
};
142+
143+
expect(() =>
144+
$PackSpecification.strict().parse(specWithConstraints),
145+
).not.toThrow();
146+
});
147+
148+
it("should reject a specification with invalid constraint value", () => {
149+
const specWithInvalidConstraints = {
150+
...standardLetterSpecification,
151+
constraints: {
152+
sheets: {
153+
value: "not a number",
154+
operator: "LESS_THAN",
155+
},
156+
},
157+
};
158+
159+
expect(() =>
160+
$PackSpecification.strict().parse(specWithInvalidConstraints),
161+
).toThrow();
162+
});
163+
164+
it("should validate a specification without constraints", () => {
165+
expect(() =>
166+
$PackSpecification.strict().parse(standardLetterSpecification),
167+
).not.toThrow();
168+
});
169+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { z } from "zod";
2+
3+
export const $ChannelType = z.enum(["NHSAPP", "SMS", "EMAIL", "LETTER"]);
4+
5+
export type ChannelType = z.infer<typeof $ChannelType>;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { z } from "zod";
2+
3+
// eslint-disable-next-line import-x/prefer-default-export
4+
export const $EnvironmentStatus = z
5+
.enum(["DRAFT", "INT", "PROD", "DISABLED"])
6+
.meta({
7+
title: "EnvironmentStatus",
8+
description:
9+
"Indicates whether the configuration is in draft, or enabled in the integration or production environment. " +
10+
"`PROD` implies that the configuration is also enabled in the integration environment.",
11+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { z } from "zod";
2+
3+
export const $Constraint = z
4+
.object({
5+
value: z.number(),
6+
operator: z
7+
.enum(["EQUALS", "NOT_EQUALS", "GREATER_THAN", "LESS_THAN"])
8+
.default("LESS_THAN"),
9+
})
10+
.meta({
11+
title: "Constraint",
12+
});
13+
export type Constraint = z.infer<typeof $Constraint>;
14+
15+
export const $Constraints = z.object({
16+
deliveryDays: $Constraint.optional().meta({
17+
title: "Delivery Days",
18+
description:
19+
"The expected number of days for delivery under this configuration.",
20+
}),
21+
sheets: $Constraint.optional().meta({
22+
title: "Sheets of paper",
23+
description:
24+
"The number of sheets that can be accommodated with this configuration.",
25+
}),
26+
sides: $Constraint.optional().meta({
27+
title: "Sides",
28+
description:
29+
"The number of sides to be printed for this letter. Dependent on duplex printing options.",
30+
}),
31+
blackCoveragePercentage: $Constraint.optional().meta({
32+
title: "Black Coverage Percentage",
33+
description:
34+
"The percentage of black coverage allowed on the paper under this configuration.",
35+
}),
36+
colourCoveragePercentage: $Constraint.optional().meta({
37+
title: "Colour Coverage Percentage",
38+
description:
39+
"The percentage of colour coverage allowed on the paper under this configuration.",
40+
}),
41+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { z } from "zod";
2+
3+
export const $EnvelopeFeature = z.enum([
4+
"WHITEMAIL",
5+
"NHS_BRANDING",
6+
"NHS_BARCODE",
7+
]);
8+
9+
export const $Envelope = z
10+
.object({
11+
id: z.string(),
12+
name: z.string(),
13+
size: z.enum(["C5", "C4", "DL"]),
14+
features: z.array($EnvelopeFeature).optional(),
15+
artwork: z.url().optional().meta({
16+
title: "Artwork URL",
17+
description:
18+
"An S3 URL pointing to the artwork for this envelope, if applicable.",
19+
}),
20+
maxThicknessMm: z
21+
.number()
22+
.optional()
23+
.meta({
24+
title: "Max Thickness (mm)",
25+
description:
26+
"The maximum thickness in millimetres for this envelope. " +
27+
"Used to validate that the assembled pack will fit within the envelope.",
28+
}),
29+
maxSheets: z
30+
.number()
31+
.optional()
32+
.meta({
33+
title: "Max Sheets",
34+
description:
35+
"The maximum number of sheets that can be accommodated within this envelope. " +
36+
"Used to validate that the assembled pack will fit within the envelope.",
37+
}),
38+
})
39+
.describe("Envelope");
40+
export type Envelope = z.infer<typeof $Envelope>;

0 commit comments

Comments
 (0)