Skip to content

Commit 5a517e1

Browse files
CCM-11886: Fix unit tests and linting
1 parent fbbc498 commit 5a517e1

19 files changed

+280
-181
lines changed

lambdas/event-publisher/src/__tests__/domain/event-builder.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const publishableEventRecord = (newStatus: string): PublishableEventRecord => ({
2929
S: 'owner',
3030
},
3131
id: {
32-
S: 'id',
32+
S: '92b676e9-470f-4d04-ab14-965ef145e15d',
3333
},
3434
clientId: {
3535
S: 'client-id',
@@ -189,24 +189,24 @@ const publishableEventRecord = (newStatus: string): PublishableEventRecord => ({
189189
},
190190
},
191191
},
192-
eventID: 'event-id',
192+
eventID: '7f2ae4b0-82c2-4911-9b84-8997d7f3f40d',
193193
tableName: 'table-name',
194194
});
195195

196196
const expectedEvent = (status: string, type: string, dataschema: string) => ({
197-
id: 'event-id',
197+
id: '7f2ae4b0-82c2-4911-9b84-8997d7f3f40d',
198198
datacontenttype: 'application/json',
199199
time: '2022-01-01T09:00:00.000Z',
200200
source: 'event-source',
201201
type,
202202
specversion: '1.0',
203203
dataschema,
204-
dataschemaversion: '1.0.0',
204+
dataschemaversion: '1.1.0',
205205
plane: 'control',
206-
subject: 'id',
206+
subject: '92b676e9-470f-4d04-ab14-965ef145e15d',
207207
data: {
208208
owner: 'owner',
209-
id: 'id',
209+
id: '92b676e9-470f-4d04-ab14-965ef145e15d',
210210
clientId: 'client-id',
211211
createdAt: 'created-at',
212212
createdBy: 'created-by',

packages/event-schemas/schemas/TemplateCompleted/v1.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description": "Unique ID for this event",
77
"type": "string",
88
"format": "uuid",
9-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
9+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
1010
},
1111
"time": {
1212
"description": "Time the event was generated",
@@ -36,7 +36,7 @@
3636
"description": "Unique identifier for the item in the event data",
3737
"type": "string",
3838
"format": "uuid",
39-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
39+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
4040
},
4141
"dataschema": {
4242
"type": "string",
@@ -69,7 +69,6 @@
6969
],
7070
"$defs": {
7171
"TemplateCompletedEventData": {
72-
"id": "TemplateCompletedEventData",
7372
"allOf": [
7473
{
7574
"anyOf": [
@@ -104,7 +103,6 @@
104103
]
105104
},
106105
"EmailTemplateEventData": {
107-
"id": "EmailTemplateEventData",
108106
"type": "object",
109107
"properties": {
110108
"owner": {
@@ -115,7 +113,7 @@
115113
"description": "Unique identifier for the template",
116114
"type": "string",
117115
"format": "uuid",
118-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
116+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
119117
},
120118
"clientId": {
121119
"description": "The client that owns the template",
@@ -192,7 +190,6 @@
192190
]
193191
},
194192
"NhsAppTemplateEventData": {
195-
"id": "NhsAppTemplateEventData",
196193
"type": "object",
197194
"properties": {
198195
"owner": {
@@ -203,7 +200,7 @@
203200
"description": "Unique identifier for the template",
204201
"type": "string",
205202
"format": "uuid",
206-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
203+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
207204
},
208205
"clientId": {
209206
"description": "The client that owns the template",
@@ -274,7 +271,6 @@
274271
]
275272
},
276273
"LetterTemplateEventData": {
277-
"id": "LetterTemplateEventData",
278274
"type": "object",
279275
"properties": {
280276
"owner": {
@@ -285,7 +281,7 @@
285281
"description": "Unique identifier for the template",
286282
"type": "string",
287283
"format": "uuid",
288-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
284+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
289285
},
290286
"clientId": {
291287
"description": "The client that owns the template",
@@ -430,7 +426,6 @@
430426
]
431427
},
432428
"SmsTemplateEventData": {
433-
"id": "SmsTemplateEventData",
434429
"type": "object",
435430
"properties": {
436431
"owner": {
@@ -441,7 +436,7 @@
441436
"description": "Unique identifier for the template",
442437
"type": "string",
443438
"format": "uuid",
444-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
439+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
445440
},
446441
"clientId": {
447442
"description": "The client that owns the template",

packages/event-schemas/schemas/TemplateDeleted/v1.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description": "Unique ID for this event",
77
"type": "string",
88
"format": "uuid",
9-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
9+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
1010
},
1111
"time": {
1212
"description": "Time the event was generated",
@@ -36,7 +36,7 @@
3636
"description": "Unique identifier for the item in the event data",
3737
"type": "string",
3838
"format": "uuid",
39-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
39+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
4040
},
4141
"dataschema": {
4242
"type": "string",
@@ -69,7 +69,6 @@
6969
],
7070
"$defs": {
7171
"TemplateDeletedEventData": {
72-
"id": "TemplateDeletedEventData",
7372
"allOf": [
7473
{
7574
"anyOf": [
@@ -104,7 +103,6 @@
104103
]
105104
},
106105
"EmailTemplateEventData": {
107-
"id": "EmailTemplateEventData",
108106
"type": "object",
109107
"properties": {
110108
"owner": {
@@ -115,7 +113,7 @@
115113
"description": "Unique identifier for the template",
116114
"type": "string",
117115
"format": "uuid",
118-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
116+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
119117
},
120118
"clientId": {
121119
"description": "The client that owns the template",
@@ -192,7 +190,6 @@
192190
]
193191
},
194192
"NhsAppTemplateEventData": {
195-
"id": "NhsAppTemplateEventData",
196193
"type": "object",
197194
"properties": {
198195
"owner": {
@@ -203,7 +200,7 @@
203200
"description": "Unique identifier for the template",
204201
"type": "string",
205202
"format": "uuid",
206-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
203+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
207204
},
208205
"clientId": {
209206
"description": "The client that owns the template",
@@ -274,7 +271,6 @@
274271
]
275272
},
276273
"LetterTemplateEventData": {
277-
"id": "LetterTemplateEventData",
278274
"type": "object",
279275
"properties": {
280276
"owner": {
@@ -285,7 +281,7 @@
285281
"description": "Unique identifier for the template",
286282
"type": "string",
287283
"format": "uuid",
288-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
284+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
289285
},
290286
"clientId": {
291287
"description": "The client that owns the template",
@@ -430,7 +426,6 @@
430426
]
431427
},
432428
"SmsTemplateEventData": {
433-
"id": "SmsTemplateEventData",
434429
"type": "object",
435430
"properties": {
436431
"owner": {
@@ -441,7 +436,7 @@
441436
"description": "Unique identifier for the template",
442437
"type": "string",
443438
"format": "uuid",
444-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
439+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
445440
},
446441
"clientId": {
447442
"description": "The client that owns the template",

packages/event-schemas/schemas/TemplateDrafted/v1.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description": "Unique ID for this event",
77
"type": "string",
88
"format": "uuid",
9-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
9+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
1010
},
1111
"time": {
1212
"description": "Time the event was generated",
@@ -36,7 +36,7 @@
3636
"description": "Unique identifier for the item in the event data",
3737
"type": "string",
3838
"format": "uuid",
39-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
39+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
4040
},
4141
"dataschema": {
4242
"type": "string",
@@ -69,7 +69,6 @@
6969
],
7070
"$defs": {
7171
"TemplateDraftedEventData": {
72-
"id": "TemplateDraftedEventData",
7372
"allOf": [
7473
{
7574
"anyOf": [
@@ -111,7 +110,6 @@
111110
]
112111
},
113112
"EmailTemplateEventData": {
114-
"id": "EmailTemplateEventData",
115113
"type": "object",
116114
"properties": {
117115
"owner": {
@@ -122,7 +120,7 @@
122120
"description": "Unique identifier for the template",
123121
"type": "string",
124122
"format": "uuid",
125-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
123+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
126124
},
127125
"clientId": {
128126
"description": "The client that owns the template",
@@ -199,7 +197,6 @@
199197
]
200198
},
201199
"NhsAppTemplateEventData": {
202-
"id": "NhsAppTemplateEventData",
203200
"type": "object",
204201
"properties": {
205202
"owner": {
@@ -210,7 +207,7 @@
210207
"description": "Unique identifier for the template",
211208
"type": "string",
212209
"format": "uuid",
213-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
210+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
214211
},
215212
"clientId": {
216213
"description": "The client that owns the template",
@@ -281,7 +278,6 @@
281278
]
282279
},
283280
"LetterTemplateEventData": {
284-
"id": "LetterTemplateEventData",
285281
"type": "object",
286282
"properties": {
287283
"owner": {
@@ -292,7 +288,7 @@
292288
"description": "Unique identifier for the template",
293289
"type": "string",
294290
"format": "uuid",
295-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
291+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
296292
},
297293
"clientId": {
298294
"description": "The client that owns the template",
@@ -437,7 +433,6 @@
437433
]
438434
},
439435
"SmsTemplateEventData": {
440-
"id": "SmsTemplateEventData",
441436
"type": "object",
442437
"properties": {
443438
"owner": {
@@ -448,7 +443,7 @@
448443
"description": "Unique identifier for the template",
449444
"type": "string",
450445
"format": "uuid",
451-
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$"
446+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
452447
},
453448
"clientId": {
454449
"description": "The client that owns the template",

packages/event-schemas/scripts/generate-json-schemas.ts

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,67 @@ import {
77
$TemplateDeletedEventV1,
88
$TemplateDraftedEventV1,
99
} from '../src';
10-
import { toJSONSchema, type ZodType } from 'zod';
10+
import { keyof, toJSONSchema, type ZodType } from 'zod';
11+
import { JSONSchema } from 'zod/v4/core';
12+
13+
const fixIdFieldInDefs = (jsonSchema: JSONSchema.JSONSchema): JSONSchema.JSONSchema => {
14+
const defs = jsonSchema.$defs ?? {};
15+
16+
const newDefs = Object.entries(defs).map(([key, value]) => {
17+
const { id: _, ...rest } = value;
18+
19+
return [key, rest];
20+
});
21+
22+
return {
23+
...jsonSchema,
24+
'$defs': Object.fromEntries(newDefs),
25+
};
26+
}
1127

1228
// Converts Zod Schema to JSON Schema and writes to JSON file
13-
function writeSchema(name: string, schema: ZodType, majorVersion: string, id: string) {
29+
function writeSchema(
30+
name: string,
31+
schema: ZodType,
32+
majorVersion: string,
33+
id: string
34+
) {
1435
const outDir = path.resolve(__dirname, '..', 'schemas', name);
1536
fs.mkdirSync(outDir, { recursive: true });
1637

1738
const jsonSchema = toJSONSchema(schema, { io: 'input' });
1839

40+
41+
1942
const outPath = path.resolve(outDir, `v${majorVersion}.json`);
20-
fs.writeFileSync(outPath, `${JSON.stringify({
21-
...jsonSchema,
22-
'$id': id,
23-
}, null, 2)}\n`);
43+
fs.writeFileSync(
44+
outPath,
45+
`${JSON.stringify(
46+
{
47+
...fixIdFieldInDefs(jsonSchema),
48+
'$id': id,
49+
},
50+
null,
51+
2
52+
)}\n`
53+
);
2454
}
2555

26-
writeSchema('TemplateCompleted', $TemplateCompletedEventV1, '1', 'https://notify.nhs.uk/events/schemas/TemplateCompleted/v1.json');
27-
writeSchema('TemplateDeleted', $TemplateDeletedEventV1, '1', 'https://notify.nhs.uk/events/schemas/TemplateDeleted/v1.json');
28-
writeSchema('TemplateDrafted', $TemplateDraftedEventV1, '1', 'https://notify.nhs.uk/events/schemas/TemplateDrafted/v1.json');
56+
writeSchema(
57+
'TemplateCompleted',
58+
$TemplateCompletedEventV1,
59+
'1',
60+
'https://notify.nhs.uk/events/schemas/TemplateCompleted/v1.json'
61+
);
62+
writeSchema(
63+
'TemplateDeleted',
64+
$TemplateDeletedEventV1,
65+
'1',
66+
'https://notify.nhs.uk/events/schemas/TemplateDeleted/v1.json'
67+
);
68+
writeSchema(
69+
'TemplateDrafted',
70+
$TemplateDraftedEventV1,
71+
'1',
72+
'https://notify.nhs.uk/events/schemas/TemplateDrafted/v1.json'
73+
);

0 commit comments

Comments
 (0)