Skip to content

Commit c240e34

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

18 files changed

Lines changed: 871 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 "@nhsdigital/nhs-notify-event-schemas-supplier-config/src/domain/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: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import {
2+
$PackSpecification,
3+
PackSpecification,
4+
} from "@nhsdigital/nhs-notify-event-schemas-supplier-config/src/domain/pack-specification";
5+
6+
describe("Specification schema validation", () => {
7+
const standardLetterSpecification: PackSpecification = {
8+
id: "standard-letter",
9+
name: "Standard Economy-class Letter",
10+
status: "INT",
11+
createdAt: "2023-01-01T00:00:00Z",
12+
updatedAt: "2023-01-01T00:00:00Z",
13+
version: 1,
14+
postage: {
15+
id: "economy",
16+
size: "STANDARD",
17+
deliveryDays: 4,
18+
},
19+
assembly: {
20+
envelopeId: "nhs-economy",
21+
printColour: "BLACK",
22+
},
23+
};
24+
25+
it("should validate a standard letter specification", () => {
26+
expect(() =>
27+
$PackSpecification.strict().parse(standardLetterSpecification),
28+
).not.toThrow();
29+
});
30+
31+
it("should accept a letter specification with unrecognised fields", () => {
32+
expect(() =>
33+
$PackSpecification.parse({
34+
...standardLetterSpecification,
35+
additionalField: { some: "data" },
36+
}),
37+
).not.toThrow();
38+
});
39+
40+
it("should validate a specification with optional description", () => {
41+
const specWithDescription: PackSpecification = {
42+
...standardLetterSpecification,
43+
description: "A standard economy-class letter for bulk mailings",
44+
};
45+
46+
expect(() =>
47+
$PackSpecification.strict().parse(specWithDescription),
48+
).not.toThrow();
49+
});
50+
51+
it("should validate a specification without description", () => {
52+
const specWithoutDescription: PackSpecification = {
53+
...standardLetterSpecification,
54+
};
55+
56+
expect(() =>
57+
$PackSpecification.strict().parse(specWithoutDescription),
58+
).not.toThrow();
59+
});
60+
61+
it("should validate a specification with duplex set to true", () => {
62+
const specWithDuplex: PackSpecification = {
63+
...standardLetterSpecification,
64+
assembly: {
65+
...standardLetterSpecification.assembly,
66+
duplex: true,
67+
},
68+
};
69+
70+
expect(() =>
71+
$PackSpecification.strict().parse(specWithDuplex),
72+
).not.toThrow();
73+
});
74+
75+
it("should validate a specification with duplex set to false", () => {
76+
const specWithoutDuplex: PackSpecification = {
77+
...standardLetterSpecification,
78+
assembly: {
79+
...standardLetterSpecification.assembly,
80+
duplex: false,
81+
},
82+
};
83+
84+
expect(() =>
85+
$PackSpecification.strict().parse(specWithoutDuplex),
86+
).not.toThrow();
87+
});
88+
89+
it("should validate a specification without duplex field", () => {
90+
const specWithoutDuplexField: PackSpecification = {
91+
...standardLetterSpecification,
92+
};
93+
94+
expect(() =>
95+
$PackSpecification.strict().parse(specWithoutDuplexField),
96+
).not.toThrow();
97+
});
98+
99+
it("should validate a specification with constraints", () => {
100+
const specWithConstraints: PackSpecification = {
101+
...standardLetterSpecification,
102+
constraints: {
103+
sheets: {
104+
value: 10,
105+
operator: "LESS_THAN",
106+
},
107+
deliveryDays: {
108+
value: 4,
109+
operator: "LESS_THAN",
110+
},
111+
},
112+
};
113+
114+
expect(() =>
115+
$PackSpecification.strict().parse(specWithConstraints),
116+
).not.toThrow();
117+
});
118+
119+
it("should validate a specification with all constraint fields", () => {
120+
const specWithConstraints: PackSpecification = {
121+
...standardLetterSpecification,
122+
constraints: {
123+
deliveryDays: {
124+
value: 5,
125+
operator: "EQUALS",
126+
},
127+
sheets: {
128+
value: 20,
129+
operator: "LESS_THAN",
130+
},
131+
sides: {
132+
value: 4,
133+
operator: "LESS_THAN",
134+
},
135+
blackCoveragePercentage: {
136+
value: 80,
137+
operator: "LESS_THAN",
138+
},
139+
colourCoveragePercentage: {
140+
value: 50,
141+
operator: "LESS_THAN",
142+
},
143+
},
144+
};
145+
146+
expect(() =>
147+
$PackSpecification.strict().parse(specWithConstraints),
148+
).not.toThrow();
149+
});
150+
151+
it("should reject a specification with invalid constraint value", () => {
152+
const specWithInvalidConstraints = {
153+
...standardLetterSpecification,
154+
constraints: {
155+
sheets: {
156+
value: "not a number",
157+
operator: "LESS_THAN",
158+
},
159+
},
160+
};
161+
162+
expect(() =>
163+
$PackSpecification.strict().parse(specWithInvalidConstraints),
164+
).toThrow();
165+
});
166+
167+
it("should validate a specification without constraints", () => {
168+
expect(() =>
169+
$PackSpecification.strict().parse(standardLetterSpecification),
170+
).not.toThrow();
171+
});
172+
});
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { z } from "zod";
2+
3+
export const $EnvironmentStatus = z
4+
.enum(["DRAFT", "INT", "PROD", "DISABLED"])
5+
.meta({
6+
title: "EnvironmentStatus",
7+
description:
8+
"Indicates whether the configuration is in draft, or enabled in the integration or production environment. " +
9+
"`PROD` implies that the configuration is also enabled in the integration environment.",
10+
});
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)