Skip to content

Commit 33d961d

Browse files
committed
feat: add priority field to letter variants and update related tests
1 parent 2c36369 commit 33d961d

3 files changed

Lines changed: 80 additions & 3 deletions

File tree

packages/events/src/domain/letter-variant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export const $LetterVariant = z
4444
"This is used to restrict a particular variant to a single supplier, " +
4545
"for example individual admail campaigns.",
4646
}),
47-
priority: z.int().default(50).meta({
47+
priority: z.int().min(1).max(100).default(50).meta({
4848
title: "Priority",
4949
description:
50-
"Integer priority used to order letters for dispatch to suppliers. Defaults to 50 when omitted.",
50+
"Integer priority used to order letters for dispatch to suppliers on a 1 to 100 scale, where lower values indicate higher priority. Defaults to 50 when omitted.",
5151
}),
5252
packSpecificationIds: z.array(idRef($PackSpecification)).nonempty().meta({
5353
title: "Pack Specifications",

packages/events/src/events/__tests__/letter-variant-events.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,60 @@ describe("LetterVariant Events", () => {
202202
expect(result.data?.data.priority).toBe(50);
203203
});
204204

205+
it("should validate priority at the highest boundary value", () => {
206+
const eventAtHighestPriority = {
207+
...validProdEvent,
208+
data: {
209+
...validProdEvent.data,
210+
priority: 1,
211+
},
212+
};
213+
214+
const result = $LetterVariantEvent.safeParse(eventAtHighestPriority);
215+
expect(result.success).toBe(true);
216+
expect(result.data?.data.priority).toBe(1);
217+
});
218+
219+
it("should validate priority at the lowest boundary value", () => {
220+
const eventAtLowestPriority = {
221+
...validProdEvent,
222+
data: {
223+
...validProdEvent.data,
224+
priority: 100,
225+
},
226+
};
227+
228+
const result = $LetterVariantEvent.safeParse(eventAtLowestPriority);
229+
expect(result.success).toBe(true);
230+
expect(result.data?.data.priority).toBe(100);
231+
});
232+
233+
it("should reject priority lower than the allowed range", () => {
234+
const invalidEvent = {
235+
...validProdEvent,
236+
data: {
237+
...validProdEvent.data,
238+
priority: 0,
239+
},
240+
};
241+
242+
const result = $LetterVariantEvent.safeParse(invalidEvent);
243+
expect(result.success).toBe(false);
244+
});
245+
246+
it("should reject priority higher than the allowed range", () => {
247+
const invalidEvent = {
248+
...validProdEvent,
249+
data: {
250+
...validProdEvent.data,
251+
priority: 101,
252+
},
253+
};
254+
255+
const result = $LetterVariantEvent.safeParse(invalidEvent);
256+
expect(result.success).toBe(false);
257+
});
258+
205259
it("should validate specialised schema enforces PROD status", () => {
206260
const prodSchema = letterVariantEvents["letter-variant.prod"];
207261

packages/file-store/src/__tests__/config-store-validator.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jest.mock("@nhsdigital/nhs-notify-event-schemas-supplier-config", () => {
1414
}),
1515
$LetterVariant: z.object({
1616
id: z.string(),
17-
priority: z.number().int().default(50),
17+
priority: z.number().int().min(1).max(100).default(50),
1818
packSpecificationIds: z.array(z.string()).min(1),
1919
}),
2020
$PackSpecification: z.object({
@@ -165,6 +165,29 @@ describe("validateConfigStore", () => {
165165
expect(result.issues[0]?.path).toEqual(["packSpecificationIds", 0]);
166166
});
167167

168+
it("should reject letter variant priority values outside the allowed range", () => {
169+
const result = validateConfigStore({
170+
rootPath: mockRootPath,
171+
records: [
172+
makeRecord("letter-variant", "lv-1", {
173+
id: "lv-1",
174+
priority: 101,
175+
packSpecificationIds: ["pack-spec-1"],
176+
}),
177+
],
178+
});
179+
180+
expect(result.ok).toBe(false);
181+
expect(result.issues).toEqual(
182+
expect.arrayContaining([
183+
expect.objectContaining({
184+
entity: "letter-variant",
185+
path: ["priority"],
186+
}),
187+
]),
188+
);
189+
});
190+
168191
it("should return ok=true with no issues when all records are valid", () => {
169192
const result = validateConfigStore({
170193
rootPath: mockRootPath,

0 commit comments

Comments
 (0)