Skip to content

Commit

Permalink
Merge pull request #28 from ministryofjustice/MLPAB-1544
Browse files Browse the repository at this point in the history
MLPAB-1544: Harden lpa-updated:changeType to enum, add  lpa-updated:actorUID
  • Loading branch information
acsauk authored Mar 11, 2024
2 parents cf2af47 + b457fd1 commit 6b06ae1
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 26 deletions.
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace # trims trailing whitespace.
- id: end-of-file-fixer # ensures that a file is either empty, or ends with one newline.
- id: check-json # Attempts to load all json files to verify syntax.
- id: check-merge-conflict # checks for files that contain merge conflict strings.
- id: mixed-line-ending # replaces or checks mixed line ending.
args: [ "--fix=auto" ]
- id: no-commit-to-branch
args:
- --branch=main
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"uid": "M-1234-5678-9012",
"reducedFeeType": "remission",
"postedDate": "2024-01-18T00:00:00.000Z"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"uid": "M-1234-5678-9012",
"changeType": "CREATED"
"changeType": "CREATE"
}
5 changes: 5 additions & 0 deletions domains/POAS/events/lpa-updated/examples/other.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"uid": "M-1234-5678-9012",
"actorUID": "urn:opg:poas:makeregister:users:740e5834-3a29-46b4-9a6f-16142fde533a",
"changeType": "CERTIFICATE_PROVIDER_SIGN"
}
3 changes: 3 additions & 0 deletions domains/POAS/events/lpa-updated/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ producers:
- opg.poas.lpastore
consumers:
- opg.poas.sirius
- opg.poas.makeregister
owners:
- vega
---
Expand All @@ -17,6 +18,8 @@ When an LPA is created or updated, this event is triggered.

Sirius uses the event to update the LPA record and status, providing OPG staff with the latest data to provide application support.

MRLPA uses the event to update the status of the LPA and trigger communications to actors.

<NodeGraph title="Consumer / Producer Diagram" />

<EventExamples />
Expand Down
63 changes: 61 additions & 2 deletions domains/POAS/events/lpa-updated/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,69 @@
"description": "The UID of the LPA",
"pattern": "M(-[A-Z0-9]{4}){3}"
},
"actorUID": {
"type": "string",
"description": "The UID of the actor the change relates to",
"pattern": "urn:opg:poas:makeregister:users:([a-z0-9]{8}-)([a-z0-9]{4}-){3}([a-z0-9]{12})"
},
"changeType": {
"type": "string",
"description": "The type of change to the LPA"
"description": "The type of change to the LPA",
"enum": ["CREATE", "CERTIFICATE_PROVIDER_SIGN", "ATTORNEY_SIGN", "TRUST_CORPORATION_SIGN"]
}
},
"required": ["uid", "changeType"]
"allOf": [
{
"if": {
"properties": {
"changeType": { "const": "CERTIFICATE_PROVIDER_SIGN" }
}
},
"then": {
"properties": {
"changeType": { "const": "CERTIFICATE_PROVIDER_SIGN" }
},
"required": ["uid", "actorUID", "changeType"]
}
},
{
"if": {
"properties": {
"changeType": { "const": "ATTORNEY_SIGN" }
}
},
"then": {
"properties": {
"changeType": { "const": "ATTORNEY_SIGN" }
},
"required": ["uid", "actorUID", "changeType"]
}
},
{
"if": {
"properties": {
"changeType": { "const": "TRUST_CORPORATION_SIGN" }
}
},
"then": {
"properties": {
"changeType": { "const": "TRUST_CORPORATION_SIGN" }
},
"required": ["uid", "actorUID", "changeType"]
}
},
{
"if": {
"properties": {
"changeType": { "const": "CREATE" }
}
},
"then": {
"properties": {
"changeType": { "const": "CREATE" }
},
"required": ["uid", "changeType"]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"uid": "M-1234-5678-9012",
"actorType": "attorney",
"actorUID": "740e5834-3a29-46b4-9a6f-16142fde533a"
"actorUID": "urn:opg:poas:makeregister:users:740e5834-3a29-46b4-9a6f-16142fde533a"
}
2 changes: 1 addition & 1 deletion domains/POAS/events/paper-form-requested/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"description": "The type of actor that needs a paper form",
"enum": ["certificateProvider", "attorney", "replacementAttorney", "trustCorporation", "replacementTrustCorporation"]
},
"actorUid": {
"actorUID": {
"type": "string",
"description": "The UID of the actor that needs a paper form",
"pattern": "urn:opg:poas:makeregister:users:([a-z0-9]{8}-)([a-z0-9]{4}-){3}([a-z0-9]{12})"
Expand Down
44 changes: 24 additions & 20 deletions test/validate-examples.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,34 @@ addFormats(ajv);
const errors = [];
const __filename = fileURLToPath(import.meta.url);

const examples = await glob(
path.join(path.dirname(__filename), "/../domains/**/examples/*.json")
);

examples.forEach((examplePath) => {
const schemaPath = path.join(
path.dirname(path.dirname(examplePath)),
"schema.json"
);
const schemas = await glob(
path.join(path.dirname(__filename), "/../domains/**/schema.json")
)

for (const schemaPath of schemas) {
const examples = await glob(path.join(
path.dirname(schemaPath),
"**/examples/*.json"
));

const eventName = path.basename(path.dirname(schemaPath));

/** @type {import("ajv").Schema} schema */
const schema = JSON.parse(fs.readFileSync(schemaPath).toString());
const data = JSON.parse(fs.readFileSync(examplePath).toString());

const validateFn = ajv.compile(schema);
const valid = validateFn(data);
if (!valid) {
errors.push({
eventName,
errors: validateFn.errors,
});
}
});

examples.forEach((examplePath) => {
const data = JSON.parse(fs.readFileSync(examplePath).toString());

const validateFn = ajv.compile(schema);
const valid = validateFn(data);
if (!valid) {
errors.push({
eventName,
errors: validateFn.errors,
});
}
})
}

if (errors.length) {
console.log(`🚨 Some errors were detected in examples:`);
Expand Down

0 comments on commit 6b06ae1

Please sign in to comment.