@pdtf/schemas 0.6.11 → 0.6.12

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,38 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
119
119
  }
120
120
  };
121
121
 
122
+ const validateVerifiedClaims = (verifiedClaimsArray) => {
123
+
124
+ const validatorVClaims = ajv.compile(verifiedClaimsSchema);
125
+
126
+ const validationErrorsArr = [];
127
+ const vClaimSchValidation = validatorVClaims({
128
+ verified_claims: verifiedClaimsArray,
129
+ });
130
+
131
+ if (!vClaimSchValidation) {
132
+ validationErrorsArr.push(validatorVClaims.errors);
133
+ }
134
+
135
+ verifiedClaimsArray.forEach((claim) => {
136
+ const [path] = Object.keys(claim.claims);
137
+
138
+ const validPath = isPathValid(path);
139
+ if (validPath) {
140
+ const subValidator = getSubschemaValidator(path);
141
+ const isValid = subValidator(claim.claims[path]);
142
+ if (!isValid) {
143
+ validationErrorsArr.push(...subValidator.errors);
144
+ }
145
+ } else {
146
+ validationErrorsArr.push(`Path ${path} is not a valid PDTF schema path`);
147
+ }
148
+ });
149
+
150
+ return validationErrorsArr;
151
+ };
152
+
153
+
122
154
  module.exports = {
123
155
  transactionSchema,
124
156
  validator,
@@ -127,4 +159,5 @@ module.exports = {
127
159
  getSubschemaValidator,
128
160
  getTitleAtPath,
129
161
  verifiedClaimsSchema,
162
+ validateVerifiedClaims
130
163
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "0.6.11",
3
+ "version": "0.6.12",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -7,6 +7,7 @@ const {
7
7
  isPathValid,
8
8
  getSubschemaValidator,
9
9
  getTitleAtPath,
10
+ validateVerifiedClaims
10
11
  } = require("../../index.js");
11
12
  const exampleTransaction = require("../examples/exampleTransaction.json");
12
13
 
@@ -182,3 +183,209 @@ test("correctly gets titles across schemas, arrays and non-existient title prope
182
183
  )
183
184
  ).toBe("Current energy rating");
184
185
  });
186
+
187
+ test("returns an array with an error stating if path is incorrect", () => {
188
+ const vClaims = [
189
+ {
190
+ verification: {
191
+ trust_framework: "uk_pdtf",
192
+ time: "2022-01-25T13:16:44.527Z",
193
+ evidence: [
194
+ {
195
+ verification_method: {
196
+ type: "auth",
197
+ },
198
+ type: "vouch",
199
+ attestation: {
200
+ voucher: {
201
+ name: "Maria Harris",
202
+ },
203
+ type: "digital_attestation",
204
+ },
205
+ },
206
+ {
207
+ type: "document",
208
+ attachments: [
209
+ {
210
+ digest: {
211
+ alg: "md5",
212
+ value: "randomHashValue",
213
+ },
214
+ url: "https://fakeFileStore.com/some/kind/of/file",
215
+ desc: "proofOfAddress.pdf",
216
+ },
217
+ ],
218
+ },
219
+ ],
220
+ },
221
+ claims: {
222
+ "/propertyPack/INVALID/materialFacts/councilTax": {
223
+ councilTaxBand: "D",
224
+ councilTaxAffectingAlterations: {
225
+ yesNo: "Yes",
226
+ details:
227
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
228
+ },
229
+ },
230
+ },
231
+ },
232
+ ];
233
+ expect(validateVerifiedClaims(vClaims)).toEqual([
234
+ "Path /propertyPack/INVALID/materialFacts/councilTax is not a valid PDTF schema path",
235
+ ]);
236
+ });
237
+
238
+ test("returns an empty array if path is correct", () => {
239
+ const vClaims = [
240
+ {
241
+ verification: {
242
+ trust_framework: "uk_pdtf",
243
+ time: "2022-01-25T13:16:44.527Z",
244
+ evidence: [
245
+ {
246
+ verification_method: {
247
+ type: "auth",
248
+ },
249
+ type: "vouch",
250
+ attestation: {
251
+ voucher: {
252
+ name: "Maria Harris",
253
+ },
254
+ type: "digital_attestation",
255
+ },
256
+ },
257
+ {
258
+ type: "document",
259
+ attachments: [
260
+ {
261
+ digest: {
262
+ alg: "md5",
263
+ value: "randomHashValue",
264
+ },
265
+ url: "https://fakeFileStore.com/some/kind/of/file",
266
+ desc: "proofOfAddress.pdf",
267
+ },
268
+ ],
269
+ },
270
+ ],
271
+ },
272
+ claims: {
273
+ "/propertyPack/materialFacts/councilTax": {
274
+ councilTaxBand: "D",
275
+ councilTaxAffectingAlterations: {
276
+ yesNo: "Yes",
277
+ details:
278
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
279
+ },
280
+ },
281
+ },
282
+ },
283
+ ];
284
+ expect(validateVerifiedClaims(vClaims)).toEqual([]);
285
+ });
286
+
287
+ test("returns an array of errors if data in the path is in invalid format", () => {
288
+ const vClaims = [
289
+ {
290
+ verification: {
291
+ trust_framework: "uk_pdtf",
292
+ time: "2022-01-25T13:16:44.527Z",
293
+ evidence: [
294
+ {
295
+ verification_method: {
296
+ type: "auth",
297
+ },
298
+ type: "vouch",
299
+ attestation: {
300
+ voucher: {
301
+ name: "Maria Harris",
302
+ },
303
+ type: "digital_attestation",
304
+ },
305
+ },
306
+ {
307
+ type: "document",
308
+ attachments: [
309
+ {
310
+ digest: {
311
+ alg: "md5",
312
+ value: "randomHashValue",
313
+ },
314
+ url: "https://fakeFileStore.com/some/kind/of/file",
315
+ desc: "proofOfAddress.pdf",
316
+ },
317
+ ],
318
+ },
319
+ ],
320
+ },
321
+ claims: {
322
+ "/propertyPack/materialFacts/councilTax": {
323
+ councilTaxBand: "D",
324
+ councilTaxAffectingAlterationsINVALID: {
325
+ yesNo: "Yes",
326
+ details:
327
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
328
+ },
329
+ },
330
+ },
331
+ },
332
+ ];
333
+ expect(validateVerifiedClaims(vClaims)).toEqual([
334
+ {
335
+ instancePath: "",
336
+ schemaPath: "#/required",
337
+ keyword: "required",
338
+ params: { missingProperty: "councilTaxAffectingAlterations" },
339
+ message: "must have required property 'councilTaxAffectingAlterations'",
340
+ },
341
+ ]);
342
+ });
343
+
344
+ test("returns an empty array of errors if data in the path is in valid format", () => {
345
+ const vClaims = [
346
+ {
347
+ verification: {
348
+ trust_framework: "uk_pdtf",
349
+ time: "2022-01-25T13:16:44.527Z",
350
+ evidence: [
351
+ {
352
+ verification_method: {
353
+ type: "auth",
354
+ },
355
+ type: "vouch",
356
+ attestation: {
357
+ voucher: {
358
+ name: "Maria Harris",
359
+ },
360
+ type: "digital_attestation",
361
+ },
362
+ },
363
+ {
364
+ type: "document",
365
+ attachments: [
366
+ {
367
+ digest: {
368
+ alg: "md5",
369
+ value: "randomHashValue",
370
+ },
371
+ url: "https://fakeFileStore.com/some/kind/of/file",
372
+ desc: "proofOfAddress.pdf",
373
+ },
374
+ ],
375
+ },
376
+ ],
377
+ },
378
+ claims: {
379
+ "/propertyPack/materialFacts/councilTax": {
380
+ councilTaxBand: "D",
381
+ councilTaxAffectingAlterations: {
382
+ yesNo: "Yes",
383
+ details:
384
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
385
+ },
386
+ },
387
+ },
388
+ },
389
+ ];
390
+ expect(validateVerifiedClaims(vClaims)).toEqual([]);
391
+ });