@pdtf/schemas 0.6.11 → 0.6.14

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/index.js CHANGED
@@ -119,6 +119,44 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
119
119
  }
120
120
  };
121
121
 
122
+ const validateVerifiedClaims = (verifiedClaims) => {
123
+ const validatorVClaims = ajv.compile(verifiedClaimsSchema);
124
+
125
+ const validationErrorsArr = [];
126
+ const vClaimSchValidation = validatorVClaims({
127
+ verified_claims: verifiedClaims,
128
+ });
129
+
130
+ if (!vClaimSchValidation) {
131
+ validationErrorsArr.push(validatorVClaims.errors);
132
+ }
133
+
134
+ const verifiedClaimsArray = Array.isArray(verifiedClaims)
135
+ ? verifiedClaims
136
+ : [verifiedClaims];
137
+
138
+ verifiedClaimsArray.forEach((claim) => {
139
+ const paths = Object.keys(claim.claims);
140
+
141
+ for (const path of paths) {
142
+ const validPath = isPathValid(path);
143
+ if (validPath) {
144
+ const subValidator = getSubschemaValidator(path);
145
+ const isValid = subValidator(claim.claims[path]);
146
+ if (!isValid) {
147
+ validationErrorsArr.push(...subValidator.errors);
148
+ }
149
+ } else {
150
+ validationErrorsArr.push(
151
+ `Path ${path} is not a valid PDTF schema path`
152
+ );
153
+ }
154
+ }
155
+ });
156
+
157
+ return validationErrorsArr;
158
+ };
159
+
122
160
  module.exports = {
123
161
  transactionSchema,
124
162
  validator,
@@ -127,4 +165,5 @@ module.exports = {
127
165
  getSubschemaValidator,
128
166
  getTitleAtPath,
129
167
  verifiedClaimsSchema,
168
+ validateVerifiedClaims,
130
169
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "0.6.11",
3
+ "version": "0.6.14",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -4,19 +4,7 @@
4
4
  "time": "2022-01-25T13:16:44.527Z",
5
5
  "evidence": [
6
6
  {
7
- "verification_method": {
8
- "type": "auth"
9
- },
10
7
  "type": "vouch",
11
- "attestation": {
12
- "voucher": {
13
- "name": "Maria Harris"
14
- },
15
- "type": "digital_attestation"
16
- }
17
- },
18
- {
19
- "type": "document",
20
8
  "attachments": [
21
9
  {
22
10
  "digest": {
@@ -26,7 +14,16 @@
26
14
  "url": "https://fakeFileStore.com/some/kind/of/file",
27
15
  "desc": "proofOfAddress.pdf"
28
16
  }
29
- ]
17
+ ],
18
+ "verification_method": {
19
+ "type": "auth"
20
+ },
21
+ "attestation": {
22
+ "voucher": {
23
+ "name": "Maria Harris"
24
+ },
25
+ "type": "digital_attestation"
26
+ }
30
27
  }
31
28
  ]
32
29
  },
@@ -0,0 +1,96 @@
1
+ const { validateVerifiedClaims } = require("../../index.js");
2
+
3
+ const exampleVouch = require("../examples/exampleVouch.json");
4
+ const exampleDocumentedVouch = require("../examples/exampleDocumentedVouch.json");
5
+
6
+ test("returns an empty array for a valid claim", () => {
7
+ expect(validateVerifiedClaims(exampleVouch)).toEqual([]);
8
+ });
9
+
10
+ test("returns an empty array for a valid array of claims", () => {
11
+ const claimsArray = [exampleVouch, exampleDocumentedVouch];
12
+ expect(validateVerifiedClaims(claimsArray)).toEqual([]);
13
+ });
14
+
15
+ test("returns an array with an error stating if path is incorrect", () => {
16
+ const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
17
+ const originalPath = Object.keys(clonedVouch.claims)[0];
18
+ const data = clonedVouch.claims[originalPath];
19
+ clonedVouch.claims = {
20
+ "/propertyPack/INVALID/materialFacts/councilTax": data,
21
+ };
22
+ expect(validateVerifiedClaims(clonedVouch)).toEqual([
23
+ "Path /propertyPack/INVALID/materialFacts/councilTax is not a valid PDTF schema path",
24
+ ]);
25
+ });
26
+
27
+ test("returns an array of errors if data in the path is in invalid format", () => {
28
+ const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
29
+ clonedVouch.claims = {
30
+ "/propertyPack/materialFacts/councilTax": {
31
+ councilTaxBand: "D",
32
+ councilTaxAffectingAlterationsINVALID: {
33
+ yesNo: "Yes",
34
+ details:
35
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
36
+ },
37
+ },
38
+ };
39
+ expect(validateVerifiedClaims(clonedVouch)).toEqual([
40
+ {
41
+ instancePath: "",
42
+ schemaPath: "#/required",
43
+ keyword: "required",
44
+ params: { missingProperty: "councilTaxAffectingAlterations" },
45
+ message: "must have required property 'councilTaxAffectingAlterations'",
46
+ },
47
+ ]);
48
+ });
49
+
50
+ test("returns an array of errors for verified claim with multiple paths", () => {
51
+ const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
52
+ clonedVouch.claims = {
53
+ "/propertyPack/materialFacts/cousncilTaxBad": {
54
+ councilTaxBand: "D",
55
+ councilTaxAffectingAlterations: {
56
+ yesNo: "Yes",
57
+ details:
58
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
59
+ },
60
+ },
61
+ "/propertyPack/materialFacts/councilTaxBadTwo": {
62
+ councilTaxBand: "D",
63
+ councilTaxAffectingAlterations: {
64
+ yesNo: "Yes",
65
+ details:
66
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
67
+ },
68
+ },
69
+ };
70
+ expect(validateVerifiedClaims(clonedVouch)).toEqual([
71
+ "Path /propertyPack/materialFacts/cousncilTaxBad is not a valid PDTF schema path",
72
+ "Path /propertyPack/materialFacts/councilTaxBadTwo is not a valid PDTF schema path",
73
+ ]);
74
+ });
75
+
76
+ test("returns an empty array of errors for verified claim with multiple valid paths", () => {
77
+ const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
78
+ clonedVouch.claims = {
79
+ "/propertyPack/materialFacts/councilTax": {
80
+ councilTaxBand: "D",
81
+ councilTaxAffectingAlterations: {
82
+ yesNo: "Yes",
83
+ details:
84
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
85
+ },
86
+ },
87
+ "/propertyPack/materialFacts/address": {
88
+ line1: "property.line1",
89
+ line2: "property.line2",
90
+ town: "property.city",
91
+ county: "property.province",
92
+ postcode: "property.postcode",
93
+ },
94
+ };
95
+ expect(validateVerifiedClaims(clonedVouch)).toEqual([]);
96
+ });