@fluid-experimental/property-changeset 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.0

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 (205) hide show
  1. package/dist/ajvFactory.cjs +19 -0
  2. package/dist/ajvFactory.cjs.map +1 -0
  3. package/dist/ajvFactory.d.cts +7 -0
  4. package/dist/ajvFactory.d.cts.map +1 -0
  5. package/dist/changeset.d.ts +3 -6
  6. package/dist/changeset.d.ts.map +1 -1
  7. package/dist/changeset.js +75 -75
  8. package/dist/changeset.js.map +1 -1
  9. package/dist/changeset_operations/array.d.ts +6 -2
  10. package/dist/changeset_operations/array.d.ts.map +1 -1
  11. package/dist/changeset_operations/array.js +94 -96
  12. package/dist/changeset_operations/array.js.map +1 -1
  13. package/dist/changeset_operations/arrayChangesetIterator.d.ts +2 -5
  14. package/dist/changeset_operations/arrayChangesetIterator.d.ts.map +1 -1
  15. package/dist/changeset_operations/arrayChangesetIterator.js +11 -12
  16. package/dist/changeset_operations/arrayChangesetIterator.js.map +1 -1
  17. package/dist/changeset_operations/changesetConflictTypes.d.ts.map +1 -1
  18. package/dist/changeset_operations/changesetConflictTypes.js +2 -2
  19. package/dist/changeset_operations/changesetConflictTypes.js.map +1 -1
  20. package/dist/changeset_operations/indexedCollection.d.ts +1 -4
  21. package/dist/changeset_operations/indexedCollection.d.ts.map +1 -1
  22. package/dist/changeset_operations/indexedCollection.js +48 -49
  23. package/dist/changeset_operations/indexedCollection.js.map +1 -1
  24. package/dist/changeset_operations/isEmptyChangeset.d.ts +1 -4
  25. package/dist/changeset_operations/isEmptyChangeset.d.ts.map +1 -1
  26. package/dist/changeset_operations/isEmptyChangeset.js +9 -9
  27. package/dist/changeset_operations/isEmptyChangeset.js.map +1 -1
  28. package/dist/helpers/typeidHelper.d.ts +0 -3
  29. package/dist/helpers/typeidHelper.d.ts.map +1 -1
  30. package/dist/helpers/typeidHelper.js +10 -10
  31. package/dist/helpers/typeidHelper.js.map +1 -1
  32. package/dist/index.d.ts +8 -8
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +19 -19
  35. package/dist/index.js.map +1 -1
  36. package/dist/isReservedKeyword.d.ts.map +1 -1
  37. package/dist/isReservedKeyword.js +2 -2
  38. package/dist/isReservedKeyword.js.map +1 -1
  39. package/dist/package.json +3 -0
  40. package/dist/pathHelper.d.ts +0 -3
  41. package/dist/pathHelper.d.ts.map +1 -1
  42. package/dist/pathHelper.js +2 -2
  43. package/dist/pathHelper.js.map +1 -1
  44. package/dist/rebase.js +8 -8
  45. package/dist/rebase.js.map +1 -1
  46. package/dist/templateSchema.d.ts.map +1 -1
  47. package/dist/templateSchema.js +2 -2
  48. package/dist/templateSchema.js.map +1 -1
  49. package/dist/templateValidator.d.ts +1 -1
  50. package/dist/templateValidator.d.ts.map +1 -1
  51. package/dist/templateValidator.js +49 -54
  52. package/dist/templateValidator.js.map +1 -1
  53. package/dist/test/array.spec.js +34 -36
  54. package/dist/test/array.spec.js.map +1 -1
  55. package/dist/test/indexedCollection.spec.js +9 -6
  56. package/dist/test/indexedCollection.spec.js.map +1 -1
  57. package/dist/test/map.spec.js +4 -4
  58. package/dist/test/map.spec.js.map +1 -1
  59. package/dist/test/pathHelper.spec.js +185 -185
  60. package/dist/test/pathHelper.spec.js.map +1 -1
  61. package/dist/test/reversibleCs.spec.js +5 -5
  62. package/dist/test/reversibleCs.spec.js.map +1 -1
  63. package/dist/test/schemaValidator.js +12 -11
  64. package/dist/test/schemaValidator.js.map +1 -1
  65. package/dist/test/schemas/badBothPropertiesAndTypeid.js +18 -18
  66. package/dist/test/schemas/badBothPropertiesAndTypeid.js.map +1 -1
  67. package/dist/test/schemas/badInvalidSemverInTypeid.js +40 -40
  68. package/dist/test/schemas/badInvalidSemverInTypeid.js.map +1 -1
  69. package/dist/test/schemas/badMissingSemverInTypeid.js +40 -40
  70. package/dist/test/schemas/badMissingSemverInTypeid.js.map +1 -1
  71. package/dist/test/schemas/badNestedProperties.js +40 -40
  72. package/dist/test/schemas/badNestedProperties.js.map +1 -1
  73. package/dist/test/schemas/badPrimitiveTypeid.js +25 -25
  74. package/dist/test/schemas/badPrimitiveTypeid.js.map +1 -1
  75. package/dist/test/schemas/badVersionedTypeid.js +41 -41
  76. package/dist/test/schemas/badVersionedTypeid.js.map +1 -1
  77. package/dist/test/schemas/goodColorPalette.js +15 -15
  78. package/dist/test/schemas/goodColorPalette.js.map +1 -1
  79. package/dist/test/schemas/goodDraftAsVersion.js +12 -12
  80. package/dist/test/schemas/goodDraftAsVersion.js.map +1 -1
  81. package/dist/test/schemas/goodPointId.js +40 -40
  82. package/dist/test/schemas/goodPointId.js.map +1 -1
  83. package/dist/test/schemas/goodReferenceAndRegular.js +16 -16
  84. package/dist/test/schemas/goodReferenceAndRegular.js.map +1 -1
  85. package/dist/test/schemas/goodReservedTypes.js +22 -22
  86. package/dist/test/schemas/goodReservedTypes.js.map +1 -1
  87. package/dist/test/schemas/goodUIBorder.js +34 -34
  88. package/dist/test/schemas/goodUIBorder.js.map +1 -1
  89. package/dist/test/schemas/index.js +55 -0
  90. package/dist/test/schemas/index.js.map +1 -0
  91. package/dist/test/tsconfig.cjs.tsbuildinfo +1 -0
  92. package/dist/test/validator/templateSyntax.spec.js +20 -25
  93. package/dist/test/validator/templateSyntax.spec.js.map +1 -1
  94. package/dist/test/validator/templateValidator.spec.js +118 -89
  95. package/dist/test/validator/templateValidator.spec.js.map +1 -1
  96. package/dist/test/validator/typeidHelper.spec.js +42 -41
  97. package/dist/test/validator/typeidHelper.spec.js.map +1 -1
  98. package/dist/utils.d.ts +17 -13
  99. package/dist/utils.d.ts.map +1 -1
  100. package/dist/utils.js +79 -79
  101. package/dist/utils.js.map +1 -1
  102. package/dist/validationResultBuilder.d.ts +2 -1
  103. package/dist/validationResultBuilder.d.ts.map +1 -1
  104. package/dist/validationResultBuilder.js.map +1 -1
  105. package/lib/ajvFactory.cjs +19 -0
  106. package/lib/ajvFactory.cjs.map +1 -0
  107. package/lib/ajvFactory.d.cts +7 -0
  108. package/lib/ajvFactory.d.cts.map +1 -0
  109. package/lib/changeset.d.ts +3 -6
  110. package/lib/changeset.d.ts.map +1 -1
  111. package/lib/changeset.js +16 -16
  112. package/lib/changeset.js.map +1 -1
  113. package/lib/changeset_operations/array.d.ts +6 -2
  114. package/lib/changeset_operations/array.d.ts.map +1 -1
  115. package/lib/changeset_operations/array.js +7 -9
  116. package/lib/changeset_operations/array.js.map +1 -1
  117. package/lib/changeset_operations/arrayChangesetIterator.d.ts +2 -5
  118. package/lib/changeset_operations/arrayChangesetIterator.d.ts.map +1 -1
  119. package/lib/changeset_operations/arrayChangesetIterator.js +3 -4
  120. package/lib/changeset_operations/arrayChangesetIterator.js.map +1 -1
  121. package/lib/changeset_operations/changesetConflictTypes.d.ts.map +1 -1
  122. package/lib/changeset_operations/changesetConflictTypes.js.map +1 -1
  123. package/lib/changeset_operations/indexedCollection.d.ts +1 -4
  124. package/lib/changeset_operations/indexedCollection.d.ts.map +1 -1
  125. package/lib/changeset_operations/indexedCollection.js +10 -11
  126. package/lib/changeset_operations/indexedCollection.js.map +1 -1
  127. package/lib/changeset_operations/isEmptyChangeset.d.ts +1 -4
  128. package/lib/changeset_operations/isEmptyChangeset.d.ts.map +1 -1
  129. package/lib/changeset_operations/isEmptyChangeset.js +3 -3
  130. package/lib/changeset_operations/isEmptyChangeset.js.map +1 -1
  131. package/lib/helpers/typeidHelper.d.ts +0 -3
  132. package/lib/helpers/typeidHelper.d.ts.map +1 -1
  133. package/lib/helpers/typeidHelper.js +1 -1
  134. package/lib/helpers/typeidHelper.js.map +1 -1
  135. package/lib/index.d.ts +8 -8
  136. package/lib/index.d.ts.map +1 -1
  137. package/lib/index.js +8 -8
  138. package/lib/index.js.map +1 -1
  139. package/lib/isReservedKeyword.d.ts.map +1 -1
  140. package/lib/isReservedKeyword.js.map +1 -1
  141. package/lib/pathHelper.d.ts +0 -3
  142. package/lib/pathHelper.d.ts.map +1 -1
  143. package/lib/pathHelper.js.map +1 -1
  144. package/lib/rebase.js +2 -2
  145. package/lib/rebase.js.map +1 -1
  146. package/lib/templateSchema.d.ts.map +1 -1
  147. package/lib/templateSchema.js.map +1 -1
  148. package/lib/templateValidator.d.ts +1 -1
  149. package/lib/templateValidator.d.ts.map +1 -1
  150. package/lib/templateValidator.js +24 -29
  151. package/lib/templateValidator.js.map +1 -1
  152. package/lib/test/array.spec.js +768 -0
  153. package/lib/test/array.spec.js.map +1 -0
  154. package/lib/test/indexedCollection.spec.js +75 -0
  155. package/lib/test/indexedCollection.spec.js.map +1 -0
  156. package/lib/test/map.spec.js +17 -0
  157. package/lib/test/map.spec.js.map +1 -0
  158. package/lib/test/pathHelper.spec.js +435 -0
  159. package/lib/test/pathHelper.spec.js.map +1 -0
  160. package/lib/test/reversibleCs.spec.js +42 -0
  161. package/lib/test/reversibleCs.spec.js.map +1 -0
  162. package/lib/test/schemaValidator.js +103 -0
  163. package/lib/test/schemaValidator.js.map +1 -0
  164. package/lib/test/schemas/badBothPropertiesAndTypeid.js +24 -0
  165. package/lib/test/schemas/badBothPropertiesAndTypeid.js.map +1 -0
  166. package/lib/test/schemas/badInvalidSemverInTypeid.js +46 -0
  167. package/lib/test/schemas/badInvalidSemverInTypeid.js.map +1 -0
  168. package/lib/test/schemas/badMissingSemverInTypeid.js +46 -0
  169. package/lib/test/schemas/badMissingSemverInTypeid.js.map +1 -0
  170. package/lib/test/schemas/badNestedProperties.js +46 -0
  171. package/lib/test/schemas/badNestedProperties.js.map +1 -0
  172. package/lib/test/schemas/badPrimitiveTypeid.js +31 -0
  173. package/lib/test/schemas/badPrimitiveTypeid.js.map +1 -0
  174. package/lib/test/schemas/badVersionedTypeid.js +47 -0
  175. package/lib/test/schemas/badVersionedTypeid.js.map +1 -0
  176. package/lib/test/schemas/goodColorPalette.js +21 -0
  177. package/lib/test/schemas/goodColorPalette.js.map +1 -0
  178. package/lib/test/schemas/goodDraftAsVersion.js +18 -0
  179. package/lib/test/schemas/goodDraftAsVersion.js.map +1 -0
  180. package/lib/test/schemas/goodPointId.js +46 -0
  181. package/lib/test/schemas/goodPointId.js.map +1 -0
  182. package/lib/test/schemas/goodReferenceAndRegular.js +22 -0
  183. package/lib/test/schemas/goodReferenceAndRegular.js.map +1 -0
  184. package/lib/test/schemas/goodReservedTypes.js +29 -0
  185. package/lib/test/schemas/goodReservedTypes.js.map +1 -0
  186. package/lib/test/schemas/goodUIBorder.js +41 -0
  187. package/lib/test/schemas/goodUIBorder.js.map +1 -0
  188. package/lib/test/schemas/index.js +29 -0
  189. package/lib/test/schemas/index.js.map +1 -0
  190. package/lib/test/tsconfig.tsbuildinfo +1 -0
  191. package/lib/test/validator/templateSyntax.spec.js +83 -0
  192. package/lib/test/validator/templateSyntax.spec.js.map +1 -0
  193. package/lib/test/validator/templateValidator.spec.js +1022 -0
  194. package/lib/test/validator/templateValidator.spec.js.map +1 -0
  195. package/lib/test/validator/typeidHelper.spec.js +142 -0
  196. package/lib/test/validator/typeidHelper.spec.js.map +1 -0
  197. package/lib/utils.d.ts +17 -13
  198. package/lib/utils.d.ts.map +1 -1
  199. package/lib/utils.js +23 -23
  200. package/lib/utils.js.map +1 -1
  201. package/lib/validationResultBuilder.d.ts +2 -1
  202. package/lib/validationResultBuilder.d.ts.map +1 -1
  203. package/lib/validationResultBuilder.js.map +1 -1
  204. package/package.json +37 -16
  205. package/dist/test/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,1022 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /* eslint no-unused-expressions: 0 */
6
+ // Lint disable to avoid needing to place `async` on many test functions
7
+ // as validity of testing is in general questionable and trying to avoid
8
+ // changes.
9
+ /* eslint-disable @typescript-eslint/promise-function-async */
10
+ /**
11
+ * @fileoverview In this file, we will test template validation.
12
+ */
13
+ import { constants } from "@fluid-experimental/property-common";
14
+ import { expect } from "chai";
15
+ import semver from "semver";
16
+ import { TemplateValidator } from "../../templateValidator.js";
17
+ import { SchemaValidator } from "../schemaValidator.js";
18
+ import { badInvalidSemverInTypeid, badMissingSemverInTypeid, badPrimitiveTypeid, goodPointId, goodReservedTypes, goodUIBorder, } from "../schemas/index.js";
19
+ (function () {
20
+ const MSG = constants.MSG;
21
+ const performValidation = function (async, template, templatePrevious, skipSemver, asyncErrorMessage) {
22
+ let schemaValidator = new SchemaValidator();
23
+ // @ts-expect-error - per the catch and no throw below
24
+ return async
25
+ ? schemaValidator
26
+ .validate(template, templatePrevious, async, skipSemver)
27
+ .catch((error) => {
28
+ expect(error.message).to.have.string(asyncErrorMessage);
29
+ // This really should re-throw the error. As it stands this
30
+ // catch returns `undefined` which is not SchemaValidationResult.
31
+ // Throwing will cause "fail: previous template: invalid semver"
32
+ // test case to fail with uncaught error.
33
+ // This also has impact on the malformed validate function below.
34
+ // throw error;
35
+ })
36
+ : // A better pattern is simply Promise.resolve(...). However without all callers
37
+ // properly specifying they are `async` (lint disabled for file), they may fail.
38
+ // In particular see test case
39
+ // "should fail if map with context key type typeid is not constant"
40
+ new Promise((resolve) => {
41
+ resolve(schemaValidator.validate(template, templatePrevious, async, skipSemver));
42
+ });
43
+ };
44
+ // Performs both synchronous and asynchronous validation
45
+ let validate = function (expectations, template, templatePrevious, skipSemver, asyncErrorMessage) {
46
+ return performValidation(false, template, templatePrevious, skipSemver)
47
+ .then(expectations)
48
+ .then(
49
+ // This patten is invalid. The `then` parameter is expected to be callable.
50
+ // Instead performValidation is called and its result is is called. Or at least
51
+ // should be. As set up the following .then is executed (apparently) on the
52
+ // results of the prior performValidation. This could be address with this prefix:
53
+ // async () =>
54
+ // However doing so causes tests to fail. Testing coming through here appears
55
+ // invalid.
56
+ // @ts-expect-error
57
+ performValidation(true, template, templatePrevious, skipSemver, asyncErrorMessage))
58
+ .then(expectations);
59
+ };
60
+ describe("Template Validation", function () {
61
+ // --- INPUT ---
62
+ describe("input validation", function () {
63
+ it("fail: empty template", function () {
64
+ let expectations = function (result) {
65
+ expect(result).property("isValid", false);
66
+ expect(result.errors.length).to.be.at.least(1);
67
+ expect(result.errors[0].message).to.have.string(MSG.NO_TEMPLATE);
68
+ return result;
69
+ };
70
+ return validate(expectations);
71
+ });
72
+ it("fail: template with no typeid", function () {
73
+ let expectations = function (result) {
74
+ expect(result).property("isValid", false);
75
+ expect(result.errors.length).to.be.at.least(1);
76
+ expect(result.errors[0].message).to.have.string(MSG.MISSING_TYPE_ID);
77
+ return result;
78
+ };
79
+ return validate(expectations, {});
80
+ });
81
+ });
82
+ // --- TYPEID ---
83
+ describe("typeid validation", function () {
84
+ it("pass: valid typeid", function () {
85
+ let template = JSON.parse(JSON.stringify(goodPointId.templateSchema));
86
+ let expectations = function (result) {
87
+ expect(result).property("isValid", true);
88
+ expect(result.typeid).to.equal(template.typeid);
89
+ expect(result.errors).to.be.empty;
90
+ expect(result.warnings).to.be.empty;
91
+ return result;
92
+ };
93
+ return validate(expectations, template);
94
+ });
95
+ it("fail: missing semver", function () {
96
+ let template = JSON.parse(JSON.stringify(badMissingSemverInTypeid.templateSchema));
97
+ let expectations = function (result) {
98
+ expect(result).property("isValid", false);
99
+ expect(result.typeid).to.equal(template.typeid);
100
+ expect(result.errors.length).to.be.at.least(1);
101
+ expect(result.errors[0].message).to.have.string("'TeamLeoValidation2:PointID' is not valid");
102
+ expect(result.errors[0].instancePath).to.equal("/typeid");
103
+ return result;
104
+ };
105
+ return validate(expectations, template);
106
+ });
107
+ it("fail: invalid semver 1", function () {
108
+ let template = JSON.parse(JSON.stringify(badInvalidSemverInTypeid.templateSchema));
109
+ let expectations = function (result) {
110
+ expect(result).property("isValid", false);
111
+ expect(result.typeid).to.equal(template.typeid);
112
+ expect(result.errors.length).to.be.at.least(1);
113
+ expect(result.errors[0].instancePath).to.equal("/typeid");
114
+ return result;
115
+ };
116
+ return validate(expectations, template);
117
+ });
118
+ it("fail: invalid semver 2", function () {
119
+ let template = JSON.parse(JSON.stringify(badInvalidSemverInTypeid.templateSchema));
120
+ template.typeid = "TeamLeoValidation2:PointID-1.0.01";
121
+ let expectations = function (result) {
122
+ expect(result).property("isValid", false);
123
+ expect(result.typeid).to.equal(template.typeid);
124
+ expect(result.errors.length).to.be.at.least(1);
125
+ expect(result.errors[0].message).to.have.string(MSG.INVALID_VERSION_1);
126
+ return result;
127
+ };
128
+ return validate(expectations, template);
129
+ });
130
+ it("fail: previous template: invalid semver", function () {
131
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
132
+ let template = JSON.parse(JSON.stringify(templatePrevious));
133
+ let badTypeId = "TeamLeoValidation2:PointID-1.0.0.1";
134
+ templatePrevious.typeid = badTypeId;
135
+ let expectations = function (result) {
136
+ expect(result).property("isValid", false);
137
+ expect(result.typeid).to.equal(badTypeId);
138
+ expect(result.errors.length).to.be.at.least(1);
139
+ expect(result.errors[0].message).to.have.string(`'${badTypeId}' is not valid`);
140
+ return result;
141
+ };
142
+ return validate(expectations, template, templatePrevious, false, "Invalid Version: 1.0.0.1");
143
+ });
144
+ });
145
+ // --- Template versioning ---
146
+ describe("template versioning", function () {
147
+ it("fail: version regression: 1.0.0 -> 0.9.9", function () {
148
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
149
+ let template = JSON.parse(JSON.stringify(templatePrevious));
150
+ template.typeid = "TeamLeoValidation2:PointID-0.9.9";
151
+ let expectations = function (result) {
152
+ expect(result).property("isValid", false);
153
+ expect(result.errors.length).to.be.at.least(1);
154
+ expect(result.errors[0].message).to.have.string(MSG.VERSION_REGRESSION_1);
155
+ return result;
156
+ };
157
+ return validate(expectations, template, templatePrevious);
158
+ });
159
+ describe("same version", function () {
160
+ it("pass: same content", function () {
161
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
162
+ let template = JSON.parse(JSON.stringify(templatePrevious));
163
+ let expectations = function (result) {
164
+ expect(result).property("isValid", true);
165
+ expect(result.errors).to.be.empty;
166
+ expect(result.warnings).to.be.empty;
167
+ return result;
168
+ };
169
+ return validate(expectations, template, templatePrevious);
170
+ });
171
+ it("fail: changed 'annotation'", function () {
172
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
173
+ templatePrevious.annotation = { description: "Test" };
174
+ let template = JSON.parse(JSON.stringify(templatePrevious));
175
+ template.annotation.description = "Changed!";
176
+ let expectations = function (result) {
177
+ expect(result).property("isValid", false);
178
+ expect(result.errors.length).to.be.at.least(1);
179
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_SAME_VERSION_1);
180
+ return result;
181
+ };
182
+ return validate(expectations, template, templatePrevious);
183
+ });
184
+ it("fail: deleted 'annotation'", function () {
185
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
186
+ templatePrevious.annotation = { description: "Test" };
187
+ let template = JSON.parse(JSON.stringify(templatePrevious));
188
+ delete template.annotation;
189
+ let expectations = function (result) {
190
+ expect(result).property("isValid", false);
191
+ expect(result.errors.length).to.be.at.least(1);
192
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_SAME_VERSION_1);
193
+ return result;
194
+ };
195
+ return validate(expectations, template, templatePrevious);
196
+ });
197
+ it("fail: added 'annotation'", function () {
198
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
199
+ let template = JSON.parse(JSON.stringify(templatePrevious));
200
+ template.annotation = { description: "Test" };
201
+ let expectations = function (result) {
202
+ expect(result).property("isValid", false);
203
+ expect(result.errors.length).to.be.at.least(1);
204
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_SAME_VERSION_1);
205
+ return result;
206
+ };
207
+ return validate(expectations, template, templatePrevious);
208
+ });
209
+ it("fail: changed 'value'", function () {
210
+ let templatePrevious = JSON.parse(JSON.stringify(goodUIBorder.templateSchema));
211
+ let template = JSON.parse(JSON.stringify(templatePrevious));
212
+ template.properties[0].properties[0].value = 123456;
213
+ let expectations = function (result) {
214
+ expect(result).property("isValid", false);
215
+ expect(result.errors.length).to.be.at.least(1);
216
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_SAME_VERSION_1);
217
+ return result;
218
+ };
219
+ return validate(expectations, template, templatePrevious);
220
+ });
221
+ it("fail: changed 'id'", function () {
222
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
223
+ let template = JSON.parse(JSON.stringify(templatePrevious));
224
+ template.properties[0].properties[0].id = "xx";
225
+ let expectations = function (result) {
226
+ expect(result).property("isValid", false);
227
+ expect(result.errors.length).to.be.at.least(1);
228
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_SAME_VERSION_1);
229
+ return result;
230
+ };
231
+ return validate(expectations, template, templatePrevious);
232
+ });
233
+ it("fail: changed 'inherits'", function () {
234
+ let templatePrevious = JSON.parse(JSON.stringify(goodReservedTypes.templateSchema));
235
+ let template = JSON.parse(JSON.stringify(templatePrevious));
236
+ template.inherits = "Reference<Adsk.Core:Math.Color-1.0.0>";
237
+ let expectations = function (result) {
238
+ expect(result).property("isValid", false);
239
+ expect(result.errors.length).to.be.at.least(1);
240
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_SAME_VERSION_1);
241
+ return result;
242
+ };
243
+ return validate(expectations, template, templatePrevious);
244
+ });
245
+ it("fail: added property", function () {
246
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
247
+ templatePrevious.annotation = { description: "Test" };
248
+ let template = JSON.parse(JSON.stringify(templatePrevious));
249
+ template.properties[0].properties.push({ id: "newPropId", typeid: "Float32" });
250
+ let expectations = function (result) {
251
+ expect(result).property("isValid", false);
252
+ expect(result.errors.length).to.be.at.least(1);
253
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_SAME_VERSION_1);
254
+ return result;
255
+ };
256
+ return validate(expectations, template, templatePrevious);
257
+ });
258
+ it("fail: deleted property", function () {
259
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
260
+ templatePrevious.annotation = { description: "Test" };
261
+ let template = JSON.parse(JSON.stringify(templatePrevious));
262
+ template.properties[0].properties.pop();
263
+ let expectations = function (result) {
264
+ expect(result).property("isValid", false);
265
+ expect(result.errors.length).to.be.at.least(1);
266
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_SAME_VERSION_1);
267
+ return result;
268
+ };
269
+ return validate(expectations, template, templatePrevious);
270
+ });
271
+ });
272
+ describe("incremented patch level", function () {
273
+ it("pass: same content", function () {
274
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
275
+ let template = JSON.parse(JSON.stringify(templatePrevious));
276
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "patch");
277
+ let expectations = function (result) {
278
+ expect(result).property("isValid", true);
279
+ expect(result.errors).to.be.empty;
280
+ expect(result.warnings).to.be.empty;
281
+ return result;
282
+ };
283
+ return validate(expectations, template, templatePrevious);
284
+ });
285
+ it("pass: unstable with major content change: 0.0.1 -> 0.0.2", function () {
286
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
287
+ templatePrevious.typeid = "TeamLeoValidation2:PointID-0.0.1";
288
+ let template = JSON.parse(JSON.stringify(templatePrevious));
289
+ template.typeid = "TeamLeoValidation2:PointID-0.0.2";
290
+ template.properties[1].typeid = "TeamLeoValidation2:ColorID-9.0.0";
291
+ let expectations = function (result) {
292
+ expect(result).property("isValid", true);
293
+ expect(result.errors).to.be.empty;
294
+ expect(result.warnings).to.be.empty;
295
+ return result;
296
+ };
297
+ return validate(expectations, template, templatePrevious);
298
+ });
299
+ it("pass: changed 'annotation'", function () {
300
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
301
+ templatePrevious.annotation = { description: "Test" };
302
+ let template = JSON.parse(JSON.stringify(templatePrevious));
303
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "patch");
304
+ template.annotation.description = "Changed!";
305
+ let expectations = function (result) {
306
+ expect(result).property("isValid", true);
307
+ expect(result.errors).to.be.empty;
308
+ expect(result.warnings).to.be.empty;
309
+ return result;
310
+ };
311
+ return validate(expectations, template, templatePrevious);
312
+ });
313
+ it("pass: deleted 'annotation'", function () {
314
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
315
+ templatePrevious.annotation = { description: "Test" };
316
+ let template = JSON.parse(JSON.stringify(templatePrevious));
317
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "patch");
318
+ delete template.annotation;
319
+ let expectations = function (result) {
320
+ expect(result).property("isValid", true);
321
+ expect(result.errors).to.be.empty;
322
+ expect(result.warnings).to.be.empty;
323
+ return result;
324
+ };
325
+ return validate(expectations, template, templatePrevious);
326
+ });
327
+ it("pass: added 'annotation'", function () {
328
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
329
+ let template = JSON.parse(JSON.stringify(templatePrevious));
330
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "patch");
331
+ template.annotation = { description: "Test" };
332
+ let expectations = function (result) {
333
+ expect(result).property("isValid", true);
334
+ expect(result.errors).to.be.empty;
335
+ expect(result.warnings).to.be.empty;
336
+ return result;
337
+ };
338
+ return validate(expectations, template, templatePrevious);
339
+ });
340
+ it("warn: changed 'value'", function () {
341
+ let templatePrevious = JSON.parse(JSON.stringify(goodUIBorder.templateSchema));
342
+ let template = JSON.parse(JSON.stringify(templatePrevious));
343
+ template.typeid = "Adsk.Core:UI.Border-" + semver.inc("1.0.0", "patch");
344
+ template.properties[0].properties[0].value = 123456;
345
+ let expectations = function (result) {
346
+ expect(result).property("isValid", true);
347
+ expect(result.errors).to.be.empty;
348
+ expect(result.warnings.length).to.be.at.least(1);
349
+ expect(result.warnings[0]).to.have.string(MSG.CHANGE_LEVEL_TOO_LOW_1);
350
+ return result;
351
+ };
352
+ return validate(expectations, template, templatePrevious);
353
+ });
354
+ it("warn: changed 'id' (delete, add)", function () {
355
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
356
+ let template = JSON.parse(JSON.stringify(templatePrevious));
357
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "patch");
358
+ template.properties[0].properties[0].id = "xx";
359
+ let expectations = function (result) {
360
+ expect(result).property("isValid", true);
361
+ expect(result.errors).to.be.empty;
362
+ expect(result.warnings.length).to.be.at.least(2); // 1st for the delete and the 2nd for the add
363
+ expect(result.warnings[0]).to.have.string(MSG.CHANGE_LEVEL_TOO_LOW_1);
364
+ return result;
365
+ };
366
+ return validate(expectations, template, templatePrevious);
367
+ });
368
+ it("warn: changed 'inherits'", function () {
369
+ let templatePrevious = JSON.parse(JSON.stringify(goodReservedTypes.templateSchema));
370
+ let template = JSON.parse(JSON.stringify(templatePrevious));
371
+ template.typeid = "TeamLeoValidation2:Example-" + semver.inc("1.0.0", "patch");
372
+ template.inherits = "Reference<Adsk.Core:Math.Color-1.0.0>";
373
+ let expectations = function (result) {
374
+ expect(result).property("isValid", true);
375
+ expect(result.errors).to.be.empty;
376
+ expect(result.warnings.length).to.be.at.least(1);
377
+ expect(result.warnings[0]).to.have.string(MSG.CHANGE_LEVEL_TOO_LOW_1);
378
+ return result;
379
+ };
380
+ return validate(expectations, template, templatePrevious);
381
+ });
382
+ it("warn: added property", function () {
383
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
384
+ templatePrevious.annotation = { description: "Test" };
385
+ let template = JSON.parse(JSON.stringify(templatePrevious));
386
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "patch");
387
+ template.properties[0].properties.push({ id: "newPropId", typeid: "Float32" });
388
+ let expectations = function (result) {
389
+ expect(result).property("isValid", true);
390
+ expect(result.errors).to.be.empty;
391
+ expect(result.warnings.length).to.be.at.least(1);
392
+ expect(result.warnings[0]).to.have.string(MSG.CHANGE_LEVEL_TOO_LOW_1);
393
+ return result;
394
+ };
395
+ return validate(expectations, template, templatePrevious);
396
+ });
397
+ it("warn: deleted property", function () {
398
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
399
+ templatePrevious.annotation = { description: "Test" };
400
+ let template = JSON.parse(JSON.stringify(templatePrevious));
401
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "patch");
402
+ template.properties[0].properties.pop();
403
+ let expectations = function (result) {
404
+ expect(result).property("isValid", true);
405
+ expect(result.errors).to.be.empty;
406
+ expect(result.warnings.length).to.be.at.least(1);
407
+ expect(result.warnings[0]).to.have.string(MSG.CHANGE_LEVEL_TOO_LOW_1);
408
+ return result;
409
+ };
410
+ return validate(expectations, template, templatePrevious);
411
+ });
412
+ });
413
+ describe("incremented minor level", function () {
414
+ it("pass: same content", function () {
415
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
416
+ let template = JSON.parse(JSON.stringify(templatePrevious));
417
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "minor");
418
+ let expectations = function (result) {
419
+ expect(result).property("isValid", true);
420
+ expect(result.errors).to.be.empty;
421
+ expect(result.warnings).to.be.empty;
422
+ return result;
423
+ };
424
+ return validate(expectations, template, templatePrevious);
425
+ });
426
+ it("pass: changed 'annotation'", function () {
427
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
428
+ templatePrevious.annotation = { description: "Test" };
429
+ let template = JSON.parse(JSON.stringify(templatePrevious));
430
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "minor");
431
+ template.annotation.description = "Changed!";
432
+ let expectations = function (result) {
433
+ expect(result).property("isValid", true);
434
+ expect(result.errors).to.be.empty;
435
+ expect(result.warnings).to.be.empty;
436
+ return result;
437
+ };
438
+ return validate(expectations, template, templatePrevious);
439
+ });
440
+ it("pass: deleted 'annotation'", function () {
441
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
442
+ templatePrevious.annotation = { description: "Test" };
443
+ let template = JSON.parse(JSON.stringify(templatePrevious));
444
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "minor");
445
+ delete template.annotation;
446
+ let expectations = function (result) {
447
+ expect(result).property("isValid", true);
448
+ expect(result.errors).to.be.empty;
449
+ expect(result.warnings).to.be.empty;
450
+ return result;
451
+ };
452
+ return validate(expectations, template, templatePrevious);
453
+ });
454
+ it("pass: added 'annotation'", function () {
455
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
456
+ let template = JSON.parse(JSON.stringify(templatePrevious));
457
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "minor");
458
+ template.annotation = { description: "Test" };
459
+ let expectations = function (result) {
460
+ expect(result).property("isValid", true);
461
+ expect(result.errors).to.be.empty;
462
+ expect(result.warnings).to.be.empty;
463
+ return result;
464
+ };
465
+ return validate(expectations, template, templatePrevious);
466
+ });
467
+ it("pass: changed 'value'", function () {
468
+ let templatePrevious = JSON.parse(JSON.stringify(goodUIBorder.templateSchema));
469
+ let template = JSON.parse(JSON.stringify(templatePrevious));
470
+ template.typeid = "Adsk.Core:UI.Border-" + semver.inc("1.0.0", "minor");
471
+ template.properties[0].properties[0].value = 123456;
472
+ let expectations = function (result) {
473
+ expect(result).property("isValid", true);
474
+ expect(result.errors).to.be.empty;
475
+ expect(result.warnings).to.be.empty;
476
+ return result;
477
+ };
478
+ return validate(expectations, template, templatePrevious);
479
+ });
480
+ it("warn: changed 'id' (delete, add)", function () {
481
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
482
+ let template = JSON.parse(JSON.stringify(templatePrevious));
483
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "minor");
484
+ template.properties[0].properties[0].id = "xx";
485
+ let expectations = function (result) {
486
+ expect(result).property("isValid", true);
487
+ expect(result.errors).to.be.empty;
488
+ expect(result.warnings.length).to.be.at.least(1);
489
+ expect(result.warnings[0]).to.have.string(MSG.CHANGE_LEVEL_TOO_LOW_1);
490
+ return result;
491
+ };
492
+ return validate(expectations, template, templatePrevious);
493
+ });
494
+ it("warn: changed 'inherits'", function () {
495
+ let templatePrevious = JSON.parse(JSON.stringify(goodReservedTypes.templateSchema));
496
+ let template = JSON.parse(JSON.stringify(templatePrevious));
497
+ template.typeid = "TeamLeoValidation2:Example-" + semver.inc("1.0.0", "minor");
498
+ template.inherits = "Reference<Adsk.Core:Math.Color-1.0.0>";
499
+ let expectations = function (result) {
500
+ expect(result).property("isValid", true);
501
+ expect(result.errors).to.be.empty;
502
+ expect(result.warnings.length).to.be.at.least(1);
503
+ expect(result.warnings[0]).to.have.string(MSG.CHANGE_LEVEL_TOO_LOW_1);
504
+ return result;
505
+ };
506
+ return validate(expectations, template, templatePrevious);
507
+ });
508
+ it("pass: added property", function () {
509
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
510
+ templatePrevious.annotation = { description: "Test" };
511
+ let template = JSON.parse(JSON.stringify(templatePrevious));
512
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "minor");
513
+ template.properties[0].properties.push({ id: "newPropId", typeid: "Float32" });
514
+ let expectations = function (result) {
515
+ expect(result).property("isValid", true);
516
+ expect(result.errors).to.be.empty;
517
+ expect(result.warnings).to.be.empty;
518
+ return result;
519
+ };
520
+ return validate(expectations, template, templatePrevious);
521
+ });
522
+ it("warn: deleted property", function () {
523
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
524
+ templatePrevious.annotation = { description: "Test" };
525
+ let template = JSON.parse(JSON.stringify(templatePrevious));
526
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "minor");
527
+ template.properties[0].properties.pop();
528
+ let expectations = function (result) {
529
+ expect(result).property("isValid", true);
530
+ expect(result.errors).to.be.empty;
531
+ expect(result.warnings.length).to.be.at.least(1);
532
+ expect(result.warnings[0]).to.have.string(MSG.CHANGE_LEVEL_TOO_LOW_1);
533
+ return result;
534
+ };
535
+ return validate(expectations, template, templatePrevious);
536
+ });
537
+ });
538
+ describe("incremented major level", function () {
539
+ it("pass: same content", function () {
540
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
541
+ let template = JSON.parse(JSON.stringify(templatePrevious));
542
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "major");
543
+ let expectations = function (result) {
544
+ expect(result).property("isValid", true);
545
+ expect(result.errors).to.be.empty;
546
+ expect(result.warnings).to.be.empty;
547
+ return result;
548
+ };
549
+ return validate(expectations, template, templatePrevious);
550
+ });
551
+ it("pass: changed 'annotation'", function () {
552
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
553
+ templatePrevious.annotation = { description: "Test" };
554
+ let template = JSON.parse(JSON.stringify(templatePrevious));
555
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "major");
556
+ template.annotation.description = "Changed!";
557
+ let expectations = function (result) {
558
+ expect(result).property("isValid", true);
559
+ expect(result.errors).to.be.empty;
560
+ expect(result.warnings).to.be.empty;
561
+ return result;
562
+ };
563
+ return validate(expectations, template, templatePrevious);
564
+ });
565
+ it("pass: deleted 'annotation'", function () {
566
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
567
+ templatePrevious.annotation = { description: "Test" };
568
+ let template = JSON.parse(JSON.stringify(templatePrevious));
569
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "major");
570
+ delete template.annotation;
571
+ let expectations = function (result) {
572
+ expect(result).property("isValid", true);
573
+ expect(result.errors).to.be.empty;
574
+ expect(result.warnings).to.be.empty;
575
+ return result;
576
+ };
577
+ return validate(expectations, template, templatePrevious);
578
+ });
579
+ it("pass: added 'annotation'", function () {
580
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
581
+ let template = JSON.parse(JSON.stringify(templatePrevious));
582
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "major");
583
+ template.annotation = { description: "Test" };
584
+ let expectations = function (result) {
585
+ expect(result).property("isValid", true);
586
+ expect(result.errors).to.be.empty;
587
+ expect(result.warnings).to.be.empty;
588
+ return result;
589
+ };
590
+ return validate(expectations, template, templatePrevious);
591
+ });
592
+ it("pass: changed 'value'", function () {
593
+ let templatePrevious = JSON.parse(JSON.stringify(goodUIBorder.templateSchema));
594
+ let template = JSON.parse(JSON.stringify(templatePrevious));
595
+ template.typeid = "Adsk.Core:UI.Border-" + semver.inc("1.0.0", "major");
596
+ template.properties[0].properties[0].value = 123456;
597
+ let expectations = function (result) {
598
+ expect(result).property("isValid", true);
599
+ expect(result.errors).to.be.empty;
600
+ expect(result.warnings).to.be.empty;
601
+ return result;
602
+ };
603
+ return validate(expectations, template, templatePrevious);
604
+ });
605
+ it("pass: changed 'id' (delete, add)", function () {
606
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
607
+ let template = JSON.parse(JSON.stringify(templatePrevious));
608
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "major");
609
+ template.properties[0].properties[0].id = "xx";
610
+ let expectations = function (result) {
611
+ expect(result).property("isValid", true);
612
+ expect(result.errors).to.be.empty;
613
+ expect(result.warnings).to.be.empty;
614
+ return result;
615
+ };
616
+ return validate(expectations, template, templatePrevious);
617
+ });
618
+ it("pass: changed 'inherits'", function () {
619
+ let templatePrevious = JSON.parse(JSON.stringify(goodReservedTypes.templateSchema));
620
+ let template = JSON.parse(JSON.stringify(templatePrevious));
621
+ template.typeid = "TeamLeoValidation2:Example-" + semver.inc("1.0.0", "major");
622
+ template.inherits = "Reference<Adsk.Core:Math.Color-1.0.0>";
623
+ let expectations = function (result) {
624
+ expect(result).property("isValid", true);
625
+ expect(result.errors).to.be.empty;
626
+ expect(result.warnings).to.be.empty;
627
+ return result;
628
+ };
629
+ return validate(expectations, template, templatePrevious);
630
+ });
631
+ it("pass: added property", function () {
632
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
633
+ templatePrevious.annotation = { description: "Test" };
634
+ let template = JSON.parse(JSON.stringify(templatePrevious));
635
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "major");
636
+ template.properties[0].properties.push({ id: "newPropId", typeid: "Float32" });
637
+ let expectations = function (result) {
638
+ expect(result).property("isValid", true);
639
+ expect(result.errors).to.be.empty;
640
+ expect(result.warnings).to.be.empty;
641
+ return result;
642
+ };
643
+ return validate(expectations, template, templatePrevious);
644
+ });
645
+ it("pass: deleted property", function () {
646
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
647
+ templatePrevious.annotation = { description: "Test" };
648
+ let template = JSON.parse(JSON.stringify(templatePrevious));
649
+ template.typeid = "TeamLeoValidation2:PointID-" + semver.inc("1.0.0", "major");
650
+ template.properties[0].properties.pop();
651
+ let expectations = function (result) {
652
+ expect(result).property("isValid", true);
653
+ expect(result.errors).to.be.empty;
654
+ expect(result.warnings).to.be.empty;
655
+ return result;
656
+ };
657
+ return validate(expectations, template, templatePrevious);
658
+ });
659
+ });
660
+ });
661
+ describe("skip semver validation", function () {
662
+ it("pass: deep equal on scrambled arrays", function () {
663
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
664
+ let template = JSON.parse(JSON.stringify(templatePrevious));
665
+ let tmp = template.properties[0].properties[0];
666
+ template.properties[0].properties[0] = template.properties[0].properties[2];
667
+ template.properties[0].properties[2] = tmp;
668
+ tmp = template.properties[1];
669
+ template.properties[1] = template.properties[2];
670
+ template.properties[2] = tmp;
671
+ // Skip semver validation to cause a deep compare
672
+ let expectations = function (result) {
673
+ expect(result).property("isValid", true);
674
+ expect(result.errors).to.be.empty;
675
+ expect(result.warnings).to.be.empty;
676
+ return result;
677
+ };
678
+ return validate(expectations, template, templatePrevious, true);
679
+ });
680
+ it("pass: deep equal with version regression", function () {
681
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
682
+ let template = JSON.parse(JSON.stringify(templatePrevious));
683
+ let expectations = function (result) {
684
+ expect(result).property("isValid", true);
685
+ expect(result.errors).to.be.empty;
686
+ expect(result.warnings).to.be.empty;
687
+ return result;
688
+ };
689
+ return validate(expectations, template, templatePrevious, true);
690
+ });
691
+ it("pass: preserves input templates", function () {
692
+ let templatePrevious = JSON.parse(JSON.stringify(goodPointId.templateSchema));
693
+ let template = JSON.parse(JSON.stringify(templatePrevious));
694
+ let copies = [
695
+ JSON.parse(JSON.stringify(templatePrevious)),
696
+ JSON.parse(JSON.stringify(template)),
697
+ ];
698
+ let expectations = function (result) {
699
+ expect(result).property("isValid", true);
700
+ expect(result.errors).to.be.empty;
701
+ expect(result.warnings).to.be.empty;
702
+ expect(templatePrevious).to.deep.equal(copies[0]);
703
+ expect(template).to.deep.equal(copies[1]);
704
+ return result;
705
+ };
706
+ return validate(expectations, template, templatePrevious);
707
+ });
708
+ it("fail: changed value", function () {
709
+ let templatePrevious = JSON.parse(JSON.stringify(goodUIBorder.templateSchema));
710
+ let template = JSON.parse(JSON.stringify(templatePrevious));
711
+ template.properties[0].properties[0].value = 123456;
712
+ let expectations = function (result) {
713
+ expect(result).property("isValid", false);
714
+ expect(result.warnings).to.be.empty;
715
+ expect(result.errors.length).to.be.at.least(1);
716
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_1);
717
+ return result;
718
+ };
719
+ return validate(expectations, template, templatePrevious, true);
720
+ });
721
+ });
722
+ describe("syntax validation", function () {
723
+ it("pass: validate a simple file", function () {
724
+ let template = goodPointId.templateSchema;
725
+ let expectations = function (result) {
726
+ expect(result.isValid).to.equal(true);
727
+ return result;
728
+ };
729
+ return validate(expectations, template, null, true);
730
+ });
731
+ it("fail: invalid file", function () {
732
+ let template = badPrimitiveTypeid.templateSchema;
733
+ let expectations = function (result) {
734
+ expect(result.isValid).to.equal(false);
735
+ expect(result.errors.length).to.be.greaterThan(0);
736
+ expect(result.unresolvedTypes.length).to.equal(1);
737
+ return result;
738
+ };
739
+ return validate(expectations, template, null, true);
740
+ });
741
+ it("should pass a schema with an empty array of properties", function () {
742
+ let EmptyPropertySchema = {
743
+ typeid: "Test:EmptyPropertySchema-1.0.0",
744
+ properties: [],
745
+ };
746
+ let expectations = function (result) {
747
+ expect(result.isValid).to.equal(true);
748
+ return result;
749
+ };
750
+ return validate(expectations, EmptyPropertySchema, null);
751
+ });
752
+ });
753
+ describe("bugs", function () {
754
+ describe("@bugfix Template validation with multiple inheritance", function () {
755
+ it("pass: deep equal with multiple inheritance", function () {
756
+ let templateString = '{"typeid":"autodesk.core:translation.controller-1.0.0","inherits":["NamedProperty","NodeProperty"]}';
757
+ let templatePrevious = JSON.parse(templateString);
758
+ let template = JSON.parse(templateString);
759
+ let expectations = function (result) {
760
+ expect(result).property("isValid", true);
761
+ expect(result.errors).to.be.empty;
762
+ expect(result.warnings).to.be.empty;
763
+ return result;
764
+ };
765
+ return validate(expectations, template, templatePrevious, true);
766
+ });
767
+ it("fail: deep equal with out of order multiple inheritance", function () {
768
+ let template = JSON.parse('{"typeid":"autodesk.core:translation.controller-1.0.0",' +
769
+ '"inherits":["NamedProperty","NodeProperty"]}');
770
+ let templatePrevious = JSON.parse('{"typeid":"autodesk.core:translation.controller-1.0.0",' +
771
+ '"inherits":["NodeProperty","NamedProperty"]}');
772
+ let expectations = function (result) {
773
+ expect(result).property("isValid", false);
774
+ expect(result.errors.length).to.be.greaterThan(0);
775
+ expect(result.errors[0].message).to.have.string(MSG.MODIFIED_TEMPLATE_1);
776
+ return result;
777
+ };
778
+ return validate(expectations, template, templatePrevious, true);
779
+ });
780
+ });
781
+ describe("@bugfix Local templates with 'abstract' properties fail validation " +
782
+ "with remote one.", () => {
783
+ describe("pass: deep equal between no properties and an empty properties array", () => {
784
+ let templateArray = {
785
+ typeid: "SimpleTest:Shape-1.0.0",
786
+ properties: [],
787
+ };
788
+ let templateAbstract = {
789
+ typeid: "SimpleTest:Shape-1.0.0",
790
+ };
791
+ it("source is abstract and target is an empty properties array", function () {
792
+ let expectations = function (result) {
793
+ expect(result).property("isValid", true);
794
+ expect(result.errors).to.be.empty;
795
+ expect(result.warnings).to.be.empty;
796
+ return result;
797
+ };
798
+ return validate(expectations, templateAbstract, templateArray);
799
+ });
800
+ it("target is abstract and source is an empty properties array", function () {
801
+ let expectations = function (result) {
802
+ expect(result).property("isValid", true);
803
+ expect(result.errors).to.be.empty;
804
+ expect(result.warnings).to.be.empty;
805
+ return result;
806
+ };
807
+ return validate(expectations, templateArray, templateAbstract);
808
+ });
809
+ });
810
+ });
811
+ });
812
+ describe("Constants", function () {
813
+ before(function () {
814
+ let schemaValidator = new SchemaValidator();
815
+ new TemplateValidator({
816
+ skipSemver: true,
817
+ inheritsFrom: schemaValidator.inheritsFrom,
818
+ hasSchema: schemaValidator.hasSchema,
819
+ });
820
+ });
821
+ let expectationsGenerator = function (msg) {
822
+ return function (result) {
823
+ expect(result.isValid).to.equal(false);
824
+ expect(result.errors.length).to.equal(1);
825
+ expect(result.errors[0].message).to.equal(msg);
826
+ return result;
827
+ };
828
+ };
829
+ it("should pass a valid template", function () {
830
+ let ConstantValid = {
831
+ typeid: "ConstantTest:ConstantValid-1.0.0",
832
+ constants: [{ id: "valid", typeid: "String", value: "value" }],
833
+ };
834
+ let expectations = function (result) {
835
+ expect(result.isValid).to.equal(true);
836
+ return result;
837
+ };
838
+ return validate(expectations, ConstantValid, null);
839
+ });
840
+ it("should fail if constants array has no elements", function () {
841
+ let ConstantEmptyArray = {
842
+ typeid: "ConstantTest:ConstantEmptyArray-1.0.0",
843
+ constants: [],
844
+ };
845
+ return validate(expectationsGenerator("/constants must NOT have fewer than 1 items"), ConstantEmptyArray, null, true);
846
+ });
847
+ it("should fail if constant does not have an id", function () {
848
+ let ConstantNoId = {
849
+ typeid: "ConstantTest:ConstantNoId-1.0.0",
850
+ constants: [{ typeid: "String", value: "value" }],
851
+ };
852
+ return validate(expectationsGenerator("/constants/0 must have required property 'id'"), ConstantNoId, null, true);
853
+ });
854
+ it("should fail if constant does not have a typeid", function () {
855
+ let ConstantNoTypeid = {
856
+ typeid: "ConstantTest:ConstantNoTypeid-1.0.0",
857
+ constants: [{ id: "id", value: "value" }],
858
+ };
859
+ return validate(function (result) {
860
+ expect(result.isValid).to.equal(false);
861
+ // console.log(result.errors);
862
+ expect(result.errors.length).to.equal(5);
863
+ expect(result.errors[3].message).to.include("must have required property 'inherits'");
864
+ expect(result.errors[4].message).to.include("/constants/0 must have required property 'typeid'");
865
+ return result;
866
+ }, ConstantNoTypeid, null, true);
867
+ });
868
+ it("should pass if constant does not have a typeid but maybe inherits from elsewhere", function () {
869
+ let ConstantNoTypeid = {
870
+ typeid: "ConstantTest:ConstantNoTypeid-1.0.0",
871
+ inherits: "ConstantTest:ConstantParentWithTypeid-1.0.0",
872
+ constants: [{ id: "id", value: "value" }],
873
+ };
874
+ let expectations = function (result) {
875
+ expect(result.isValid).to.equal(true);
876
+ return result;
877
+ };
878
+ return validate(expectations, ConstantNoTypeid, null);
879
+ });
880
+ it("should not fail if constant does not have a value or typedValue", function () {
881
+ let ConstantNoValue = {
882
+ typeid: "ConstantTest:ConstantNoValue-1.0.0",
883
+ constants: [{ id: "id", typeid: "String" }],
884
+ };
885
+ let expectations = function (result) {
886
+ expect(result.isValid).to.equal(true);
887
+ return result;
888
+ };
889
+ return validate(expectations, ConstantNoValue, null, true);
890
+ });
891
+ it("should pass if constant map with context key type typeid has typeids as keys", function () {
892
+ let Constant = {
893
+ typeid: "ConstantTest:Constant-1.0.0",
894
+ constants: [
895
+ {
896
+ id: "map",
897
+ typeid: "Int32",
898
+ context: "map",
899
+ contextKeyType: "typeid",
900
+ value: {
901
+ "SimpleTest:ConstantTemplate1-1.0.0": 1,
902
+ "SimpleTest:ConstantTemplate2-1.0.0": -1,
903
+ },
904
+ },
905
+ ],
906
+ };
907
+ let expectations = function (result) {
908
+ expect(result.isValid).to.equal(true);
909
+ return result;
910
+ };
911
+ return validate(expectations, Constant, null, true);
912
+ });
913
+ it("should fail if constant map with context key type that is not a valid value", function () {
914
+ let ConstantNoValue = {
915
+ typeid: "ConstantTest:ConstantNoValue-1.0.0",
916
+ constants: [
917
+ {
918
+ id: "map",
919
+ typeid: "Int32",
920
+ context: "map",
921
+ contextKeyType: "badvalue",
922
+ value: {
923
+ "SimpleTest:ConstantTemplate1-1.0.0": 1,
924
+ "SimpleTest:ConstantTemplate2-1.0.0": -1,
925
+ },
926
+ },
927
+ ],
928
+ };
929
+ return validate(function (result) {
930
+ expect(result.isValid).to.equal(false);
931
+ expect(result.errors.length).to.equal(1);
932
+ expect(result.errors[0].message).to.include("should match one of the following: typeid,string");
933
+ return result;
934
+ }, ConstantNoValue, null, true);
935
+ });
936
+ it("should fail if constant map with context key type typeid has invalid typeids as keys", function () {
937
+ let ConstantMapWithBadKeys = {
938
+ typeid: "ConstantTest:ConstantMapWithBadKeys-1.0.0",
939
+ constants: [
940
+ {
941
+ id: "map",
942
+ typeid: "Int32",
943
+ context: "map",
944
+ contextKeyType: "typeid",
945
+ value: { NotATypeId: 1, AlsoNotATypeId: -1 },
946
+ },
947
+ ],
948
+ };
949
+ let expectations = function (result) {
950
+ expect(result.isValid).to.equal(false);
951
+ expect(result.errors.length).to.equal(2);
952
+ expect(result.errors[0].message).to.include(MSG.KEY_MUST_BE_TYPEID + "NotATypeId");
953
+ expect(result.errors[1].message).to.include(MSG.KEY_MUST_BE_TYPEID + "AlsoNotATypeId");
954
+ return result;
955
+ };
956
+ return validate(expectations, ConstantMapWithBadKeys, null, true);
957
+ });
958
+ it("should fail if map with context key type typeid is not constant", function () {
959
+ let ConstantMapWithProperty = {
960
+ typeid: "ConstantTest:Outerprop-1.0.0",
961
+ properties: [
962
+ {
963
+ id: "map",
964
+ typeid: "Int32",
965
+ context: "map",
966
+ contextKeyType: "typeid",
967
+ value: {
968
+ "SimpleTest:ConstantTemplate1-1.0.0": 1,
969
+ "SimpleTest:ConstantTemplate2-1.0.0": -1,
970
+ },
971
+ },
972
+ ],
973
+ };
974
+ let expectations = function (result) {
975
+ throw new Error("This should not be called");
976
+ };
977
+ let failExpectations = function (error) {
978
+ expect(error.toString()).to.include("SV-013: A map with typeids as keys must be constant");
979
+ };
980
+ return performValidation(false, ConstantMapWithProperty, null, true)
981
+ .then(expectations)
982
+ .catch(failExpectations);
983
+ });
984
+ });
985
+ describe("Async validation", function () {
986
+ it("can perform context validation asynchronously", function (done) {
987
+ let schemaValidator = new SchemaValidator();
988
+ let templateValidator = new TemplateValidator({
989
+ inheritsFromAsync: schemaValidator.inheritsFromAsync,
990
+ hasSchemaAsync: schemaValidator.hasSchemaAsync,
991
+ });
992
+ // Doesn't inherit from 'NamedProperty'. Will cause an error
993
+ let grandParentSchema = {
994
+ typeid: "test:grandparentschema-1.0.0",
995
+ };
996
+ let parentSchema = {
997
+ typeid: "test:parentschema-1.0.0",
998
+ inherits: ["test:grandparentschema-1.0.0"],
999
+ };
1000
+ let childSchema = {
1001
+ typeid: "test:childchema-1.0.0",
1002
+ properties: [
1003
+ {
1004
+ id: "set",
1005
+ typeid: "test:parentschema-1.0.0",
1006
+ context: "set",
1007
+ },
1008
+ ],
1009
+ };
1010
+ schemaValidator.register(grandParentSchema);
1011
+ schemaValidator.register(parentSchema);
1012
+ templateValidator.validateAsync(childSchema).then(() => {
1013
+ done(new Error("Should not be valid!"));
1014
+ }, (error) => {
1015
+ expect(error).to.exist;
1016
+ done();
1017
+ });
1018
+ });
1019
+ });
1020
+ });
1021
+ })();
1022
+ //# sourceMappingURL=templateValidator.spec.js.map