@defra/grants-reporting-publisher 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/package.json +4 -4
- package/src/schema.js +15 -14
- package/src/validate.test.js +43 -0
|
@@ -54,7 +54,7 @@ jobs:
|
|
|
54
54
|
|
|
55
55
|
- name: Create Release Pull Request or Release
|
|
56
56
|
id: changesets
|
|
57
|
-
uses: changesets/action@
|
|
57
|
+
uses: changesets/action@ae32849d5ba541f9ae29e40e22a623bc13562f51 #v2.1.2
|
|
58
58
|
with:
|
|
59
59
|
publish-script: npm run github:release
|
|
60
60
|
commit-message: 'Create new config version'
|
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/grants-reporting-publisher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "NPM module for publishing grants reporting events",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"@babel/preset-env": "8.0.2",
|
|
49
49
|
"@changesets/changelog-github": "1.0.0",
|
|
50
50
|
"@changesets/cli": "3.0.1",
|
|
51
|
-
"@vitest/coverage-v8": "
|
|
51
|
+
"@vitest/coverage-v8": "5.0.0",
|
|
52
52
|
"eslint": "10.7.0",
|
|
53
53
|
"eslint-config-prettier": "10.1.1",
|
|
54
54
|
"husky": "9.1.7",
|
|
55
|
-
"lint-staged": "17.
|
|
55
|
+
"lint-staged": "17.4.1",
|
|
56
56
|
"neostandard": "0.13.0",
|
|
57
57
|
"prettier": "3.9.6",
|
|
58
|
-
"vitest": "
|
|
58
|
+
"vitest": "5.0.0",
|
|
59
59
|
"vitest-fetch-mock": "0.4.5"
|
|
60
60
|
},
|
|
61
61
|
"overrides": {
|
package/src/schema.js
CHANGED
|
@@ -8,6 +8,19 @@ const accountId = Joi.alternatives()
|
|
|
8
8
|
.try(Joi.string().max(MAX_50), Joi.number())
|
|
9
9
|
.custom(String);
|
|
10
10
|
|
|
11
|
+
const optionsSchema = Joi.array().items(
|
|
12
|
+
Joi.object({
|
|
13
|
+
parcelReference: Joi.string().allow("").required(),
|
|
14
|
+
parcelSizeUnderAgreement: Joi.number().optional(),
|
|
15
|
+
optionCode: Joi.string().required(),
|
|
16
|
+
optionYear: Joi.number().integer().optional(),
|
|
17
|
+
optionStartDate: Joi.date().iso().optional(),
|
|
18
|
+
optionEndDate: Joi.date().iso().optional(),
|
|
19
|
+
optionQuantity: Joi.number().required(),
|
|
20
|
+
optionValue: Joi.number().required(),
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
|
|
11
24
|
export const eventSchema = Joi.object({
|
|
12
25
|
correlationId: Joi.string().max(MAX_50).required(),
|
|
13
26
|
datetime: Joi.date().iso().required(),
|
|
@@ -28,20 +41,7 @@ export const eventSchema = Joi.object({
|
|
|
28
41
|
agreementEndDate: Joi.date().iso().optional(),
|
|
29
42
|
agreementValue: Joi.number().optional(),
|
|
30
43
|
sbi: accountId.required(),
|
|
31
|
-
options:
|
|
32
|
-
.items(
|
|
33
|
-
Joi.object({
|
|
34
|
-
parcelReference: Joi.string().allow("").required(),
|
|
35
|
-
parcelSizeUnderAgreement: Joi.number().optional(),
|
|
36
|
-
optionCode: Joi.string().required(),
|
|
37
|
-
optionYear: Joi.number().integer().optional(),
|
|
38
|
-
optionStartDate: Joi.date().iso().optional(),
|
|
39
|
-
optionEndDate: Joi.date().iso().optional(),
|
|
40
|
-
optionQuantity: Joi.number().required(),
|
|
41
|
-
optionValue: Joi.number().required(),
|
|
42
|
-
}),
|
|
43
|
-
)
|
|
44
|
-
.required(),
|
|
44
|
+
options: optionsSchema.required(),
|
|
45
45
|
}),
|
|
46
46
|
})
|
|
47
47
|
.when(Joi.object({ eventType: AGREEMENT_STATUS_CHANGED }).unknown(), {
|
|
@@ -53,6 +53,7 @@ export const eventSchema = Joi.object({
|
|
|
53
53
|
agreementEndDate: Joi.date().iso().optional(),
|
|
54
54
|
agreementValue: Joi.number().optional(),
|
|
55
55
|
userId: Joi.string().optional(),
|
|
56
|
+
options: optionsSchema.optional(),
|
|
56
57
|
}),
|
|
57
58
|
})
|
|
58
59
|
.unknown()
|
package/src/validate.test.js
CHANGED
|
@@ -394,6 +394,49 @@ describe("validateReportingEvent", () => {
|
|
|
394
394
|
expect(result.valid).toBe(true);
|
|
395
395
|
});
|
|
396
396
|
|
|
397
|
+
test("accepts a valid Agreement status changed event with options", () => {
|
|
398
|
+
const result = validateReportingEvent({
|
|
399
|
+
...validBase,
|
|
400
|
+
eventData: {
|
|
401
|
+
eventType: AGREEMENT_STATUS_CHANGED,
|
|
402
|
+
agreementId: "WMP123456789",
|
|
403
|
+
agreementStatus: "ACCEPTED",
|
|
404
|
+
statusDate: "2026-09-02T10:00:00Z",
|
|
405
|
+
options: [
|
|
406
|
+
{
|
|
407
|
+
parcelReference: "SD8545-9935",
|
|
408
|
+
optionCode: "WMP1",
|
|
409
|
+
optionQuantity: 15.75,
|
|
410
|
+
optionValue: 1575.0,
|
|
411
|
+
},
|
|
412
|
+
],
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
expect(result.valid).toBe(true);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test("rejects Agreement status changed event if options contain invalid data", () => {
|
|
419
|
+
const result = validateReportingEvent({
|
|
420
|
+
...validBase,
|
|
421
|
+
eventData: {
|
|
422
|
+
eventType: AGREEMENT_STATUS_CHANGED,
|
|
423
|
+
agreementId: "WMP123456789",
|
|
424
|
+
agreementStatus: "ACCEPTED",
|
|
425
|
+
statusDate: "2026-09-02T10:00:00Z",
|
|
426
|
+
options: [
|
|
427
|
+
{
|
|
428
|
+
parcelReference: "SD8545-9935",
|
|
429
|
+
// missing mandatory option fields like optionCode
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
expect(result.valid).toBe(false);
|
|
435
|
+
expect(result.errors).toContain(
|
|
436
|
+
'"eventData.options[0].optionCode" is required',
|
|
437
|
+
);
|
|
438
|
+
});
|
|
439
|
+
|
|
397
440
|
test("rejects Agreement status changed event if required fields are missing", () => {
|
|
398
441
|
const result = validateReportingEvent({
|
|
399
442
|
...validBase,
|