@pdtf/schemas 3.5.1-7 → 3.5.1-8
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 +16 -9
- package/package.json +1 -1
- package/src/tests/v3/transactionSchema.test.js +22 -0
package/index.js
CHANGED
|
@@ -104,7 +104,7 @@ const transactionSchemas = {
|
|
|
104
104
|
};
|
|
105
105
|
|
|
106
106
|
// Custom array merge function for oneOf arrays
|
|
107
|
-
const arrayMerge = (target, source) => {
|
|
107
|
+
const arrayMerge = (target, source, options) => {
|
|
108
108
|
// For string arrays (enum, required, etc.)
|
|
109
109
|
if (
|
|
110
110
|
target.length > 0 &&
|
|
@@ -114,16 +114,23 @@ const arrayMerge = (target, source) => {
|
|
|
114
114
|
source[0] &&
|
|
115
115
|
typeof source[0] === "string"
|
|
116
116
|
) {
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
117
|
+
// Detect if this is a required array by checking the parent key
|
|
118
|
+
// Required arrays are property names (camelCase, no spaces)
|
|
119
|
+
// Enum arrays are values (can contain spaces, capitals, etc.)
|
|
120
|
+
const isRequiredArray = target.every(
|
|
120
121
|
(item) =>
|
|
121
122
|
typeof item === "string" &&
|
|
122
123
|
item.length > 0 &&
|
|
123
|
-
|
|
124
|
-
!item.includes("
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
// Required field names are typically camelCase without spaces
|
|
125
|
+
!item.includes(" ") &&
|
|
126
|
+
// First character is usually lowercase for field names
|
|
127
|
+
(item[0] === item[0].toLowerCase() || item.startsWith("is") || item.startsWith("has"))
|
|
128
|
+
) && source.every(
|
|
129
|
+
(item) =>
|
|
130
|
+
typeof item === "string" &&
|
|
131
|
+
item.length > 0 &&
|
|
132
|
+
!item.includes(" ") &&
|
|
133
|
+
(item[0] === item[0].toLowerCase() || item.startsWith("is") || item.startsWith("has"))
|
|
127
134
|
);
|
|
128
135
|
|
|
129
136
|
if (isRequiredArray) {
|
|
@@ -137,7 +144,7 @@ const arrayMerge = (target, source) => {
|
|
|
137
144
|
return combined;
|
|
138
145
|
}
|
|
139
146
|
|
|
140
|
-
// For other string arrays (like enum),
|
|
147
|
+
// For other string arrays (like enum), replace with source
|
|
141
148
|
return source.length > 0 ? source : target;
|
|
142
149
|
}
|
|
143
150
|
|
package/package.json
CHANGED
|
@@ -591,3 +591,25 @@ test("waterAndDrainage state with mainsFoulDrainage No missing offMainsDrainageS
|
|
|
591
591
|
);
|
|
592
592
|
expect(relevantError).toBeDefined();
|
|
593
593
|
});
|
|
594
|
+
|
|
595
|
+
test("TA7 overlay organisesBuildingInsurance enum has exactly three items", () => {
|
|
596
|
+
const schema = getTransactionSchema(schemaId, ["ta7ed3"]);
|
|
597
|
+
|
|
598
|
+
// Navigate to the organisesBuildingInsurance property in the merged schema
|
|
599
|
+
const organisesBuildingInsurance =
|
|
600
|
+
schema.properties?.propertyPack?.properties?.ownership?.properties
|
|
601
|
+
?.ownershipsToBeTransferred?.items?.oneOf?.[2]?.properties
|
|
602
|
+
?.leaseholdInformation?.properties?.contactDetails?.properties
|
|
603
|
+
?.serviceContactAssignments?.properties?.organisesBuildingInsurance;
|
|
604
|
+
|
|
605
|
+
expect(organisesBuildingInsurance).toBeDefined();
|
|
606
|
+
expect(organisesBuildingInsurance.enum).toBeDefined();
|
|
607
|
+
|
|
608
|
+
// The TA7 overlay defines exactly 3 enum values, which should replace the base schema's 6 values
|
|
609
|
+
expect(organisesBuildingInsurance.enum).toHaveLength(3);
|
|
610
|
+
expect(organisesBuildingInsurance.enum).toEqual([
|
|
611
|
+
"the Lessees",
|
|
612
|
+
"Management Company",
|
|
613
|
+
"Landlord",
|
|
614
|
+
]);
|
|
615
|
+
});
|