@pdtf/schemas 2.0.0-4 → 2.0.0-6

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.
@@ -55,7 +55,7 @@
55
55
  "specialistIssues",
56
56
  "fixturesAndFittings",
57
57
  "waterAndDrainage",
58
- "utilities",
58
+ "connectedUtilities",
59
59
  "greenDealLoan",
60
60
  "centralHeating",
61
61
  "insurance",
@@ -745,6 +745,10 @@
745
745
  }
746
746
  },
747
747
  "general": {
748
+ "required": [
749
+ "typeOfLeasehold",
750
+ "leaseTerm"
751
+ ],
748
752
  "properties": {
749
753
  "typeOfLeasehold": {
750
754
  "baspiRef": "A1.3.1",
@@ -812,6 +816,10 @@
812
816
  },
813
817
  "leaseTerm": {
814
818
  "baspiRef": "A1.4.1",
819
+ "required": [
820
+ "startYearOfLease",
821
+ "lengthOfLeaseInYears"
822
+ ],
815
823
  "properties": {
816
824
  "startYearOfLease": {
817
825
  "baspiRef": "A1.4.1.1",
@@ -0,0 +1,128 @@
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
+ });
@@ -112,17 +112,7 @@ const coreSchema = deleteProperties(combinedSchema, [
112
112
  ]);
113
113
 
114
114
  fs.writeFileSync(
115
- "../schemas/v2/core.json",
115
+ "../schemas/v2/pdtf-transaction.json",
116
116
  JSON.stringify(coreSchema, null, 2)
117
117
  );
118
- console.log("Core schema written to ../schemas/v2/core.json");
119
- console.log(overlays.baspi);
120
- const mergedSchema = merge(overlays.baspi, coreSchema, {
121
- arrayMerge: combineMerge,
122
- });
123
-
124
- fs.writeFileSync(
125
- "../schemas/v2/merged.json",
126
- JSON.stringify(mergedSchema, null, 2)
127
- );
128
- console.log("Merged schema written to ../schemas/v2/merged.json");
118
+ console.log("Core schema written to ../schemas/v2/pdtf-transaction.json");
@@ -0,0 +1,44 @@
1
+ const { dereference } = require("@jdw/jst");
2
+ const traverse = require("traverse");
3
+ const jp = require("jsonpointer");
4
+ const fs = require("fs");
5
+ const merge = require("deepmerge");
6
+
7
+ const combinedSchema = require("../schemas/v2/combined.json");
8
+
9
+ const overlay = "baspiUI";
10
+ const keys = [
11
+ "isDependent",
12
+ "component",
13
+ "htmlClass",
14
+ "addButtonLabelFirst",
15
+ "addButtonLabelSubsequent",
16
+ ];
17
+
18
+ const returnSchema = {
19
+ $schema: "http://json-schema.org/draft-07/schema#",
20
+ $id: `https://trust.propdata.org.uk/schemas/v2/overlays/${overlay}.json`,
21
+ };
22
+
23
+ traverse(combinedSchema).forEach(function (element) {
24
+ let path = "/" + this.path.join("/");
25
+ if (path === "/") path = "";
26
+ if (keys.includes(this.key)) {
27
+ jp.set(returnSchema, path, element);
28
+ }
29
+ });
30
+
31
+ const fileName = `../schemas/v2/overlays/${overlay}.json`;
32
+ fs.writeFileSync(fileName, JSON.stringify(returnSchema, null, 2));
33
+ console.log(`Overlay ${overlay} written to ${overlay}`);
34
+
35
+ traverse(combinedSchema).forEach(function (element) {
36
+ if (keys.includes(this.key)) {
37
+ this.delete(true); // true = stop here
38
+ }
39
+ });
40
+
41
+ fs.writeFileSync(
42
+ "../schemas/v2/combined.json",
43
+ JSON.stringify(combinedSchema, null, 2)
44
+ );