@pdtf/schemas 3.0.0-3 → 3.0.0-30

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.
Files changed (39) hide show
  1. package/index.js +15 -13
  2. package/package.json +1 -1
  3. package/src/examples/v3/exampleAddParticipantVouch.json +32 -0
  4. package/src/examples/v3/exampleDocumentedVouch.json +40 -0
  5. package/src/examples/v3/exampleElectronicRecord.json +30 -0
  6. package/src/examples/v3/exampleTransaction.json +713 -665
  7. package/src/examples/v3/exampleVouch.json +25 -0
  8. package/src/schemas/v2/overlays/baspi.json +510 -2331
  9. package/src/schemas/v2/overlays/con29DW.json +36 -125
  10. package/src/schemas/v2/overlays/con29R.json +5 -143
  11. package/src/schemas/v2/overlays/fme1.json +48 -233
  12. package/src/schemas/v2/overlays/lpe1.json +75 -367
  13. package/src/schemas/v2/overlays/nts.json +17 -103
  14. package/src/schemas/v2/overlays/piq.json +146 -693
  15. package/src/schemas/v2/overlays/rds.json +50 -316
  16. package/src/schemas/v2/overlays/ta10.json +540 -1755
  17. package/src/schemas/v2/overlays/ta6.json +241 -1193
  18. package/src/schemas/v2/overlays/ta7.json +106 -440
  19. package/src/schemas/v3/combined.json +22568 -22480
  20. package/src/schemas/v3/overlays/baspi.json +5358 -7480
  21. package/src/schemas/v3/overlays/con29DW.json +537 -615
  22. package/src/schemas/v3/overlays/con29R.json +5 -143
  23. package/src/schemas/v3/overlays/fme1.json +1035 -1215
  24. package/src/schemas/v3/overlays/llc1.json +5 -5
  25. package/src/schemas/v3/overlays/lpe1.json +1782 -2024
  26. package/src/schemas/v3/overlays/nts.json +1393 -1329
  27. package/src/schemas/v3/overlays/oc1.json +821 -821
  28. package/src/schemas/v3/overlays/piq.json +2134 -2884
  29. package/src/schemas/v3/overlays/rds.json +2713 -3284
  30. package/src/schemas/v3/overlays/ta10.json +4786 -5338
  31. package/src/schemas/v3/overlays/ta6.json +2987 -3803
  32. package/src/schemas/v3/overlays/ta7.json +941 -1036
  33. package/src/schemas/v3/pdtf-transaction.json +19590 -18979
  34. package/src/schemas/v3/skeleton.json +2792 -2749
  35. package/src/tests/v3/transactionSchema.test.js +61 -59
  36. package/src/tests/v3/verifiedClaimsValidator.test.js +15 -15
  37. package/src/utils/extractOverlay.js +10 -27
  38. package/src/tests/v2/transactionSchema.test.js +0 -361
  39. package/src/tests/v2/verifiedClaimsValidator.test.js +0 -128
@@ -1,361 +0,0 @@
1
- const jp = require("jsonpointer");
2
- const fs = require("fs");
3
-
4
- const {
5
- getTransactionSchema,
6
- getSubschema,
7
- isPathValid,
8
- getValidator,
9
- getSubschemaValidator,
10
- getTitleAtPath,
11
- } = require("../../../index.js");
12
-
13
- const exampleTransaction = require("../../examples/v2/exampleTransaction.json");
14
- const schemaId =
15
- "https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json";
16
- // const validator = getValidator(schemaId);
17
- const v2TransactionSchema = getTransactionSchema(schemaId);
18
-
19
- test("exports a property pack schema, v2 with baspi overlay by default", () => {
20
- const testSchema = getTransactionSchema(schemaId);
21
- expect(testSchema.$id).toEqual(
22
- "https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json"
23
- );
24
- expect(
25
- testSchema.properties.propertyPack.properties.materialFacts.baspiRef
26
- ).toEqual("A");
27
- });
28
-
29
- test("sample is valid BASPI", () => {
30
- const testSchema = getTransactionSchema(schemaId);
31
- expect(
32
- testSchema.properties.propertyPack.properties.materialFacts.properties
33
- .centralHeating.title
34
- ).toEqual("Central Heating");
35
- const validator = getValidator(schemaId);
36
- const isValid = validator(exampleTransaction);
37
- if (!isValid) console.log(validator.errors);
38
- expect(isValid).toBe(true);
39
- });
40
-
41
- test("invalid sample is invalid", () => {
42
- const clonedExampleTransaction = JSON.parse(
43
- JSON.stringify(exampleTransaction)
44
- );
45
- delete clonedExampleTransaction.propertyPack.materialFacts.notices;
46
- const validator = getValidator(schemaId);
47
- const isValid = validator(clonedExampleTransaction);
48
- expect(isValid).toBe(false);
49
- });
50
-
51
- test("sample with missing dependent required fields is invalid", () => {
52
- const clonedExampleTransaction = JSON.parse(
53
- JSON.stringify(exampleTransaction)
54
- );
55
- clonedExampleTransaction.propertyPack.materialFacts.ownership.ownershipsToBeTransferred[0].ownershipType =
56
- "leasehold";
57
- const validator = getValidator(schemaId);
58
- const isValid = validator(clonedExampleTransaction);
59
- expect(isValid).toBe(false);
60
- });
61
-
62
- test("correctly gets a top level subschema", () => {
63
- const subschema = getSubschema("/propertyPack", schemaId);
64
- expect(subschema.title).toBe("Property Pack");
65
- });
66
-
67
- test("correctly identifies a valid path", () => {
68
- const isValid = isPathValid("/propertyPack/materialFacts", schemaId);
69
- expect(isValid).toBe(true);
70
- });
71
-
72
- test("correctly identifies an undefined invalid path", () => {
73
- const isValid = isPathValid("/propertyPack/materialItems", schemaId);
74
- expect(isValid).toBe(false);
75
- });
76
-
77
- test("correctly identifies an error generating invalid path", () => {
78
- const isValid = isPathValid(
79
- "/propertyPack/materialItems/someProperty/item",
80
- schemaId
81
- );
82
- expect(isValid).toBe(false);
83
- });
84
-
85
- test("correctly identifies an array invalid path", () => {
86
- const isValid = isPathValid("/propertyPack/materialFacts/1/item", schemaId);
87
- expect(isValid).toBe(false);
88
- });
89
-
90
- test("correctly gets a subschema", () => {
91
- const subschema = getSubschema(
92
- "/propertyPack/materialFacts/notices",
93
- schemaId
94
- );
95
- expect(subschema.title).toBe("Notices which Affect the Property");
96
- });
97
-
98
- test("correctly gets a subschema through an arrays element", () => {
99
- const subschema = getSubschema(
100
- "/propertyPack/titlesToBeSold/0/registerExtract",
101
- schemaId
102
- );
103
- expect(Object.keys(subschema.properties)).toEqual([
104
- "OCSummaryData",
105
- "OCRegisterData",
106
- ]);
107
- });
108
-
109
- test("correctly gets a subschema through a dependency", () => {
110
- const subschema = getSubschema(
111
- "/propertyPack/materialFacts/delayFactors/hasDelayFactors/details",
112
- schemaId
113
- );
114
- expect(subschema.title).toBe(
115
- "Provide details and likely timescale for delay"
116
- );
117
- });
118
-
119
- test("correctly gets another subschema through a dependency", () => {
120
- const subschema = getSubschema(
121
- "/propertyPack/materialFacts/ownership/ownershipsToBeTransferred/0/leaseholdInformation/leaseTerm/lengthOfLeaseInYears",
122
- schemaId
123
- );
124
- expect(subschema.title).toBe("Length of lease (years)");
125
- });
126
-
127
- test("correctly gets yet another subschema through a dependency", () => {
128
- const subschema = getSubschema(
129
- "/propertyPack/materialFacts/ownership/ownershipsToBeTransferred/0/leaseholdInformation/groundRent/rentSubjectToIncrease/rentIncreaseCalculated",
130
- schemaId
131
- );
132
- expect(subschema.title).toBe("How is the increase calculated?");
133
- });
134
-
135
- test("correctly gets yet, yet another subschema through a dependency", () => {
136
- const subschema = getSubschema(
137
- "/propertyPack/materialFacts/listingAndConservation/isConservationArea/yesNo",
138
- schemaId
139
- );
140
- expect(subschema.type).toBe("string");
141
- expect(subschema.enum).toStrictEqual(["Yes", "No", "Not known"]);
142
- });
143
-
144
- test("correctly gets yet, yet, yet another subschema through a dependency", () => {
145
- const subschema = getSubschema(
146
- "/propertyPack/materialFacts/environmentalIssues/flooding/typeOfFlooding/other/yesNo",
147
- schemaId
148
- );
149
- expect(subschema.type).toBe("string");
150
- expect(subschema.enum).toStrictEqual(["Yes", "No"]);
151
- });
152
-
153
- test("correctly gets yet, yet, yet another subschema through a second item dependency", () => {
154
- const subschema = getSubschema(
155
- "/propertyPack/materialFacts/environmentalIssues/flooding/typeOfFlooding",
156
- schemaId
157
- );
158
- expect(subschema.type).toBe("object");
159
- });
160
-
161
- test("correctly gets yes another subschema but through a non-baspi oneOf structure", () => {
162
- const subschema = getSubschema(
163
- "/propertyPack/titlesToBeSold/0/registerExtract/OCSummaryData/RestrictionDetails/RestrictionEntry/ChargeRestriction/EntryDetails/EntryText",
164
- schemaId
165
- );
166
- expect(subschema).toEqual({ type: "string" });
167
- });
168
-
169
- test("correctly gets yes another subschema but through a non-baspi oneOf structure with array option", () => {
170
- const subschema = getSubschema(
171
- "/propertyPack/titlesToBeSold/0/registerExtract/OCSummaryData/RestrictionDetails/RestrictionEntry/0/ChargeRestriction/EntryDetails/EntryText",
172
- schemaId
173
- );
174
- expect(subschema).toEqual({ type: "string" });
175
- });
176
-
177
- test("correctly gets a subschema with multiple overlays", () => {
178
- const subschema = getSubschema(
179
- "/propertyPack/materialFacts/parking/parkingArrangements",
180
- schemaId,
181
- ["baspiV4", "ta6ed4"]
182
- );
183
- expect(subschema.baspiRef).toBe("A1.6.0");
184
- expect(subschema.ta6Ref).toBe("9.1");
185
- });
186
-
187
- test("correctly gets a subschema validator which is already cached", () => {
188
- const validator = getSubschemaValidator(
189
- "/propertyPack/materialFacts/energyEfficiency/certificate",
190
- schemaId
191
- );
192
- expect(validator).not.toBeNull();
193
- const anotherValidator = getSubschemaValidator(
194
- "/propertyPack/materialFacts/energyEfficiency/certificate",
195
- schemaId
196
- );
197
- expect(anotherValidator).not.toBeNull();
198
- });
199
-
200
- test("correctly gets a subschema validator for a TA6 overlay", () => {
201
- const path = "/propertyPack";
202
- const data = jp.get(exampleTransaction, path);
203
- const validator = getSubschemaValidator(path, exampleTransaction.$schema, [
204
- "ta6ed4",
205
- ]);
206
- let isValid = validator(data);
207
- // console.log(validator.errors);
208
- expect(isValid).toBe(true);
209
- });
210
-
211
- test("correctly gets a subschema validator for a TA6 overlay which validates", () => {
212
- const path =
213
- "/propertyPack/additionalLegalInfo/guaranteesWarrantiesAndIndemnityInsurances/subsidenceWork";
214
- const data = { yesNo: "Yes" };
215
- const validator = getSubschemaValidator(path, exampleTransaction.$schema, [
216
- "ta6ed4",
217
- ]);
218
- let isValid = validator(data);
219
- expect(isValid).toBe(false);
220
- expect(validator.errors[0].message).toBe(
221
- "must have required property 'attachments'"
222
- );
223
- });
224
-
225
- test("correctly gets a subschema validator for a TA6 overlay which validates with non-TA6 field missing", () => {
226
- const path = "/propertyPack";
227
- const clonedExampleTransaction = JSON.parse(
228
- JSON.stringify(exampleTransaction)
229
- );
230
- const data = jp.get(exampleTransaction, path);
231
- data.materialFacts.uprn = undefined;
232
- const validator = getSubschemaValidator(path, exampleTransaction.$schema, [
233
- "ta6ed4",
234
- ]);
235
- let isValid = validator(data);
236
- expect(isValid).toBe(true);
237
- });
238
-
239
- test("correctly gets a subschema validator for a TA6 overlay which validates with non-TA6 section missing", () => {
240
- const path = "/propertyPack";
241
- const clonedExampleTransaction = JSON.parse(
242
- JSON.stringify(exampleTransaction)
243
- );
244
- const data = jp.get(clonedExampleTransaction, path);
245
- data.additionalLegalInfo.smartHomeSystems = undefined;
246
- const validator = getSubschemaValidator(path, exampleTransaction.$schema, [
247
- "ta6ed4",
248
- ]);
249
- let isValid = validator(data);
250
- // console.log(validator.errors);
251
- expect(isValid).toBe(true);
252
- });
253
-
254
- test("correctly gets a subschema validator for a TA6 overlay which fails to validate with BASPI/TA6 section missing", () => {
255
- const path = "/propertyPack";
256
- const clonedExampleTransaction = JSON.parse(
257
- JSON.stringify(exampleTransaction)
258
- );
259
- const data = jp.get(clonedExampleTransaction, path);
260
- data.materialFacts.waterAndDrainage = {};
261
- const validator = getSubschemaValidator(path, exampleTransaction.$schema, [
262
- "ta6ed4",
263
- ]);
264
- let isValid = validator(data);
265
- expect(isValid).toBe(false);
266
- });
267
-
268
- test("correctly gets a subschema validator for an NTS overlay", () => {
269
- const path = "/propertyPack";
270
- const clonedExampleTransaction = JSON.parse(
271
- JSON.stringify(exampleTransaction)
272
- );
273
- const data = jp.get(clonedExampleTransaction, path);
274
- const validator = getSubschemaValidator(path, exampleTransaction.$schema, [
275
- "nts2023",
276
- ]);
277
- let isValid = validator(data);
278
- expect(isValid).toBe(true);
279
- });
280
-
281
- test("correctly gets a subschema validator for an LPE1 overlay", () => {
282
- const path = "/propertyPack";
283
- const clonedExampleTransaction = JSON.parse(
284
- JSON.stringify(exampleTransaction)
285
- );
286
- const data = jp.get(clonedExampleTransaction, path);
287
- const validator = getSubschemaValidator(path, exampleTransaction.$schema, [
288
- "lpe1ed4",
289
- ]);
290
- let isValid = validator(data);
291
- expect(isValid).toBe(false);
292
- });
293
-
294
- test("correctly gets a subschema validator which validates", () => {
295
- const path = "/propertyPack/materialFacts/notices";
296
- const validator = getSubschemaValidator(path);
297
- const data = jp.get(exampleTransaction, path);
298
- expect(data.neighbourDevelopment.yesNo).toBe("No");
299
- let isValid = validator(data);
300
- expect(isValid).toBe(true);
301
- data.neighbourDevelopment.yesNo = "Invalid string";
302
- isValid = validator(data);
303
- expect(isValid).toBe(false);
304
- });
305
-
306
- test("correctly gets titles across schemas, arrays and non-existient title properties", () => {
307
- expect(
308
- getTitleAtPath(
309
- v2TransactionSchema,
310
- "/propertyPack/materialFacts/ownership/ownershipsToBeTransferred/0/ownershipType"
311
- )
312
- ).toBe("What type of ownership is the property?");
313
- expect(
314
- getTitleAtPath(
315
- v2TransactionSchema,
316
- "/propertyPack/materialFacts/ownership/ownershipsToBeTransferred/0/leaseholdInformation/leaseTerm/lengthOfLeaseInYears"
317
- )
318
- ).toBe("Length of lease (years)");
319
- expect(
320
- getTitleAtPath(
321
- v2TransactionSchema,
322
- "/propertyPack/materialFacts/ownership/ownershipsToBeTransferred/0/leaseholdInformation/serviceCharge/annualServiceCharge"
323
- )
324
- ).toBe("Amount of current annual service charge (£)");
325
- expect(
326
- getTitleAtPath(
327
- v2TransactionSchema,
328
- "/propertyPack/materialFacts/invalidPath"
329
- )
330
- ).toBe(undefined);
331
- expect(
332
- getTitleAtPath(
333
- v2TransactionSchema,
334
- "/propertyPack/titlesToBeSold/0/registerExtract"
335
- )
336
- ).toBe("HMLR Official Copy Register Extract");
337
- expect(
338
- getTitleAtPath(
339
- v2TransactionSchema,
340
- "/propertyPack/titlesToBeSold/0/registerExtract/OCSummaryData/PropertyAddress"
341
- )
342
- ).toBe("Property address");
343
- expect(
344
- getTitleAtPath(
345
- v2TransactionSchema,
346
- "/propertyPack/titlesToBeSold/0/registerExtract/OCSummaryData/InvalidProp"
347
- )
348
- ).toBe(undefined);
349
- expect(
350
- getTitleAtPath(
351
- v2TransactionSchema,
352
- "/propertyPack/materialFacts/energyEfficiency/certificate/currentEnergyRating"
353
- )
354
- ).toBe("Current energy efficiency rating");
355
- expect(
356
- getTitleAtPath(
357
- v2TransactionSchema,
358
- "/propertyPack/additionalLegalInfo/occupiers/othersAged17OrOver/aged17OrOverNames"
359
- )
360
- ).toBe("Please provide their full names and ages.");
361
- });
@@ -1,128 +0,0 @@
1
- const { validateVerifiedClaims } = require("../../../index.js");
2
-
3
- const exampleVouch = require("../../examples/v1/exampleVouch.json");
4
- const exampleDocumentedVouch = require("../../examples/v1/exampleDocumentedVouch.json");
5
- const v2SchemaId =
6
- "https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json";
7
-
8
- test("returns an empty array for a valid claim", () => {
9
- expect(validateVerifiedClaims([exampleVouch])).toEqual([]);
10
- });
11
-
12
- test("returns an empty array for a valid array of claims", () => {
13
- const claimsArray = [exampleVouch, exampleDocumentedVouch];
14
- expect(validateVerifiedClaims(claimsArray)).toEqual([]);
15
- });
16
-
17
- test("returns an array with an error stating if path is incorrect", () => {
18
- const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
19
- const originalPath = Object.keys(clonedVouch.claims)[0];
20
- const data = clonedVouch.claims[originalPath];
21
- clonedVouch.claims = {
22
- "/propertyPack/INVALID/materialFacts/councilTax": data,
23
- };
24
- // v2 schema, no overlay
25
- expect(validateVerifiedClaims([clonedVouch], v2SchemaId, null)).toEqual([
26
- "Path /propertyPack/INVALID/materialFacts/councilTax is not a valid PDTF schema path",
27
- ]);
28
- });
29
-
30
- test("returns errors if BASPI requirements are not met and BASPI overlay is specified (default)", () => {
31
- const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
32
- clonedVouch.claims = {
33
- "/propertyPack/materialFacts/delayFactors": {
34
- hasDelayFactors: { yesNo: "Yes" },
35
- },
36
- };
37
- const errors = validateVerifiedClaims([clonedVouch], v2SchemaId);
38
- expect(errors).toEqual([
39
- {
40
- instancePath: "/hasDelayFactors",
41
- schemaPath: "#/properties/hasDelayFactors/oneOf/1/required",
42
- keyword: "required",
43
- params: { missingProperty: "details" },
44
- message: "must have required property 'details'",
45
- },
46
- {
47
- instancePath: "/hasDelayFactors",
48
- schemaPath: "#/properties/hasDelayFactors/oneOf/1/required",
49
- keyword: "required",
50
- params: { missingProperty: "attachments" },
51
- message: "must have required property 'attachments'",
52
- },
53
- ]);
54
- });
55
-
56
- test("returns no errors if BASPI requirements are not met and null overlay is specified", () => {
57
- const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
58
- clonedVouch.claims = {
59
- "/propertyPack/materialFacts/delayFactors": {
60
- hasDelayFactors: { yesNo: "Yes" },
61
- },
62
- };
63
- const errors = validateVerifiedClaims([clonedVouch], v2SchemaId, null);
64
- expect(errors).toEqual([]);
65
- });
66
-
67
- test("returns errors for invalid fields even if null overlay is specified", () => {
68
- const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
69
- clonedVouch.claims = {
70
- "/propertyPack/materialFacts/delayFactors": {
71
- hasDelayFactors: { yesNo: "Maybe" },
72
- },
73
- };
74
- const errors = validateVerifiedClaims([clonedVouch], v2SchemaId, null);
75
- expect(errors).toHaveLength(4);
76
- });
77
-
78
- test("returns an array of errors for verified claim with multiple paths", () => {
79
- const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
80
- clonedVouch.claims = {
81
- "/propertyPack/materialFacts/cousncilTaxBad": {
82
- councilTaxBand: "D",
83
- councilTaxAffectingAlterations: {
84
- yesNo: "Yes",
85
- details:
86
- "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
87
- },
88
- },
89
- "/propertyPack/materialFacts/councilTaxBadTwo": {
90
- councilTaxBand: "D",
91
- councilTaxAffectingAlterations: {
92
- yesNo: "Yes",
93
- details:
94
- "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
95
- },
96
- },
97
- };
98
- expect(validateVerifiedClaims([clonedVouch], v2SchemaId, null)).toEqual([
99
- "Path /propertyPack/materialFacts/cousncilTaxBad is not a valid PDTF schema path",
100
- "Path /propertyPack/materialFacts/councilTaxBadTwo is not a valid PDTF schema path",
101
- ]);
102
- });
103
-
104
- test("returns an empty array of errors for verified claim with multiple valid paths", () => {
105
- const clonedVouch = JSON.parse(
106
- JSON.stringify(exampleVouch),
107
- v2SchemaId,
108
- null
109
- );
110
- clonedVouch.claims = {
111
- "/propertyPack/materialFacts/councilTax": {
112
- councilTaxBand: "D",
113
- councilTaxAffectingAlterations: {
114
- yesNo: "Yes",
115
- details:
116
- "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
117
- },
118
- },
119
- "/propertyPack/materialFacts/address": {
120
- line1: "property.line1",
121
- line2: "property.line2",
122
- town: "property.city",
123
- county: "property.province",
124
- postcode: "property.postcode",
125
- },
126
- };
127
- expect(validateVerifiedClaims([clonedVouch], v2SchemaId, null)).toEqual([]);
128
- });