@api-client/core 0.14.0 → 0.14.1

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 (140) hide show
  1. package/build/src/amf/AmfTypes.d.ts +1 -1
  2. package/build/src/amf/AmfTypes.js +1 -1
  3. package/build/src/amf/AmfTypes.js.map +1 -1
  4. package/build/src/amf/Utils.d.ts +0 -6
  5. package/build/src/amf/Utils.d.ts.map +1 -1
  6. package/build/src/amf/Utils.js +0 -14
  7. package/build/src/amf/Utils.js.map +1 -1
  8. package/build/src/browser.d.ts +1 -0
  9. package/build/src/browser.d.ts.map +1 -1
  10. package/build/src/browser.js +1 -0
  11. package/build/src/browser.js.map +1 -1
  12. package/build/src/index.d.ts +1 -0
  13. package/build/src/index.d.ts.map +1 -1
  14. package/build/src/index.js +1 -0
  15. package/build/src/index.js.map +1 -1
  16. package/build/src/legacy.d.ts +0 -8
  17. package/build/src/legacy.d.ts.map +1 -1
  18. package/build/src/legacy.js +0 -9
  19. package/build/src/legacy.js.map +1 -1
  20. package/build/src/modeling/Bindings.d.ts +1 -1
  21. package/build/src/modeling/Bindings.js.map +1 -1
  22. package/build/src/modeling/DataDomain.js +2 -2
  23. package/build/src/modeling/DataDomain.js.map +1 -1
  24. package/build/src/modeling/DataFormat.d.ts +0 -40
  25. package/build/src/modeling/DataFormat.d.ts.map +1 -1
  26. package/build/src/modeling/DataFormat.js +0 -27
  27. package/build/src/modeling/DataFormat.js.map +1 -1
  28. package/build/src/modeling/DomainAssociation.d.ts +28 -0
  29. package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
  30. package/build/src/modeling/DomainAssociation.js +73 -4
  31. package/build/src/modeling/DomainAssociation.js.map +1 -1
  32. package/build/src/modeling/DomainEntity.d.ts +25 -9
  33. package/build/src/modeling/DomainEntity.d.ts.map +1 -1
  34. package/build/src/modeling/DomainEntity.js +65 -21
  35. package/build/src/modeling/DomainEntity.js.map +1 -1
  36. package/build/src/modeling/DomainFile.d.ts +1 -1
  37. package/build/src/modeling/DomainFile.js +1 -1
  38. package/build/src/modeling/DomainFile.js.map +1 -1
  39. package/build/src/modeling/DomainImpactAnalysis.d.ts +1 -1
  40. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  41. package/build/src/modeling/DomainImpactAnalysis.js +3 -3
  42. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  43. package/build/src/modeling/DomainModel.d.ts +2 -2
  44. package/build/src/modeling/DomainModel.js +2 -2
  45. package/build/src/modeling/DomainModel.js.map +1 -1
  46. package/build/src/modeling/DomainProperty.d.ts +28 -12
  47. package/build/src/modeling/DomainProperty.d.ts.map +1 -1
  48. package/build/src/modeling/DomainProperty.js +61 -26
  49. package/build/src/modeling/DomainProperty.js.map +1 -1
  50. package/build/src/modeling/Semantics.d.ts +109 -0
  51. package/build/src/modeling/Semantics.d.ts.map +1 -0
  52. package/build/src/modeling/Semantics.js +97 -0
  53. package/build/src/modeling/Semantics.js.map +1 -0
  54. package/build/src/models/kinds.d.ts +0 -24
  55. package/build/src/models/kinds.d.ts.map +1 -1
  56. package/build/src/models/kinds.js +0 -24
  57. package/build/src/models/kinds.js.map +1 -1
  58. package/build/src/models/store/data_catalog.d.ts +1 -1
  59. package/build/src/models/store/data_catalog.js.map +1 -1
  60. package/build/tsconfig.tsbuildinfo +1 -1
  61. package/data/models/example-generator-api.json +11 -11
  62. package/package.json +1 -1
  63. package/src/amf/AmfTypes.ts +1 -1
  64. package/src/amf/Utils.ts +0 -15
  65. package/src/modeling/Bindings.ts +1 -1
  66. package/src/modeling/DataDomain.ts +2 -2
  67. package/src/modeling/DataFormat.ts +0 -48
  68. package/src/modeling/DomainAssociation.ts +66 -3
  69. package/src/modeling/DomainEntity.ts +56 -17
  70. package/src/modeling/DomainFile.ts +1 -1
  71. package/src/modeling/DomainImpactAnalysis.ts +3 -3
  72. package/src/modeling/DomainModel.ts +2 -2
  73. package/src/modeling/DomainProperty.ts +60 -21
  74. package/src/modeling/Semantics.ts +178 -0
  75. package/src/modeling/graph.md +14 -14
  76. package/src/modeling/readme.md +29 -29
  77. package/src/models/kinds.ts +0 -25
  78. package/src/models/store/data_catalog.ts +1 -1
  79. package/tests/unit/modeling/data_domain_change_observers.spec.ts +11 -10
  80. package/tests/unit/modeling/data_domain_entities.spec.ts +129 -1
  81. package/tests/unit/modeling/data_domain_property.spec.ts +1 -1
  82. package/tests/unit/modeling/domain_asociation.spec.ts +177 -0
  83. package/tests/unit/modeling/domain_entity.spec.ts +27 -26
  84. package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +11 -11
  85. package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +10 -10
  86. package/tests/unit/modeling/{domain.property.spec.ts → domain_property.spec.ts} +139 -23
  87. package/build/src/amf/AmfShapeGenerator.d.ts +0 -103
  88. package/build/src/amf/AmfShapeGenerator.d.ts.map +0 -1
  89. package/build/src/amf/AmfShapeGenerator.js +0 -416
  90. package/build/src/amf/AmfShapeGenerator.js.map +0 -1
  91. package/build/src/modeling/legacy/DataAssociation.d.ts +0 -284
  92. package/build/src/modeling/legacy/DataAssociation.d.ts.map +0 -1
  93. package/build/src/modeling/legacy/DataAssociation.js +0 -443
  94. package/build/src/modeling/legacy/DataAssociation.js.map +0 -1
  95. package/build/src/modeling/legacy/DataEntity.d.ts +0 -358
  96. package/build/src/modeling/legacy/DataEntity.d.ts.map +0 -1
  97. package/build/src/modeling/legacy/DataEntity.js +0 -855
  98. package/build/src/modeling/legacy/DataEntity.js.map +0 -1
  99. package/build/src/modeling/legacy/DataEntityBuilder.d.ts +0 -162
  100. package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +0 -1
  101. package/build/src/modeling/legacy/DataEntityBuilder.js +0 -221
  102. package/build/src/modeling/legacy/DataEntityBuilder.js.map +0 -1
  103. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +0 -298
  104. package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +0 -1
  105. package/build/src/modeling/legacy/DataImpactAnalysis.js +0 -441
  106. package/build/src/modeling/legacy/DataImpactAnalysis.js.map +0 -1
  107. package/build/src/modeling/legacy/DataModel.d.ts +0 -99
  108. package/build/src/modeling/legacy/DataModel.d.ts.map +0 -1
  109. package/build/src/modeling/legacy/DataModel.js +0 -237
  110. package/build/src/modeling/legacy/DataModel.js.map +0 -1
  111. package/build/src/modeling/legacy/DataNamespace.d.ts +0 -340
  112. package/build/src/modeling/legacy/DataNamespace.d.ts.map +0 -1
  113. package/build/src/modeling/legacy/DataNamespace.js +0 -784
  114. package/build/src/modeling/legacy/DataNamespace.js.map +0 -1
  115. package/build/src/modeling/legacy/DataProperty.d.ts +0 -332
  116. package/build/src/modeling/legacy/DataProperty.d.ts.map +0 -1
  117. package/build/src/modeling/legacy/DataProperty.js +0 -415
  118. package/build/src/modeling/legacy/DataProperty.js.map +0 -1
  119. package/build/src/models/store/DataFile.d.ts +0 -29
  120. package/build/src/models/store/DataFile.d.ts.map +0 -1
  121. package/build/src/models/store/DataFile.js +0 -87
  122. package/build/src/models/store/DataFile.js.map +0 -1
  123. package/src/amf/AmfShapeGenerator.ts +0 -477
  124. package/src/modeling/legacy/DataAssociation.ts +0 -554
  125. package/src/modeling/legacy/DataEntity.ts +0 -1019
  126. package/src/modeling/legacy/DataEntityBuilder.ts +0 -236
  127. package/src/modeling/legacy/DataImpactAnalysis.ts +0 -530
  128. package/src/modeling/legacy/DataModel.ts +0 -276
  129. package/src/modeling/legacy/DataNamespace.ts +0 -929
  130. package/src/modeling/legacy/DataProperty.ts +0 -630
  131. package/src/models/store/DataFile.ts +0 -95
  132. package/tests/unit/modeling/legacy/amf_shape_generator.spec.ts +0 -1041
  133. package/tests/unit/modeling/legacy/data_association.spec.ts +0 -710
  134. package/tests/unit/modeling/legacy/data_entity.spec.ts +0 -2061
  135. package/tests/unit/modeling/legacy/data_entity_generator_json.spec.ts +0 -987
  136. package/tests/unit/modeling/legacy/data_entity_generator_xml.spec.ts +0 -1451
  137. package/tests/unit/modeling/legacy/data_model.spec.ts +0 -395
  138. package/tests/unit/modeling/legacy/data_namespace.spec.ts +0 -1312
  139. package/tests/unit/modeling/legacy/data_property.spec.ts +0 -887
  140. package/tests/unit/modeling/legacy/impact_analysis.spec.ts +0 -373
@@ -1,1451 +0,0 @@
1
- import { test } from '@japa/runner'
2
- import { JSDOM } from 'jsdom'
3
- import { DataNamespace, DataEntity, DataModel, DataProperty } from '../../../../src/legacy.js'
4
-
5
- const rfc3339Re = /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z$/
6
- const dateRe = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
7
- const timeRe = /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/
8
- const mime = 'application/xml'
9
-
10
- test.group('XML DataEntity Generator: string', (group) => {
11
- let e1: DataEntity
12
-
13
- group.each.setup(() => {
14
- const ns = new DataNamespace()
15
- const d1 = ns.addDataModel('d1')
16
- e1 = d1.addEntity('e1')
17
- })
18
-
19
- test('generates an example', ({ assert }) => {
20
- e1.addTypedProperty('string', 'p1')
21
- const result = e1.toExample(mime) as string
22
- assert.typeOf(result, 'string', 'result is a string')
23
-
24
- const dom = new JSDOM(result, { contentType: mime })
25
- const schema = dom.window.document
26
-
27
- const outer = schema.querySelector('e1')!
28
- assert.ok(outer, 'has the outer element')
29
- const inner = outer.querySelector('p1')!
30
- assert.ok(inner, 'has the inner element')
31
- assert.isNotEmpty(inner.textContent!.trim(), 'has the generated content')
32
- })
33
-
34
- test('has min length with schema', ({ assert }) => {
35
- const p1 = e1.addTypedProperty('string', 'p1')
36
- p1.schema = {
37
- minimum: 10,
38
- }
39
-
40
- const result = e1.toExample(mime) as string
41
- assert.typeOf(result, 'string', 'result is a string')
42
-
43
- const dom = new JSDOM(result, { contentType: mime })
44
- const schema = dom.window.document
45
-
46
- const inner = schema.querySelector('p1')!
47
- assert.ok(inner, 'has the inner element')
48
- const value = inner.textContent!.trim()
49
- assert.isAtLeast(value.length, 10, 'has the minimum length')
50
- })
51
-
52
- test('has max length with schema', ({ assert }) => {
53
- const p1 = e1.addTypedProperty('string', 'p1')
54
- p1.schema = {
55
- maximum: 10,
56
- }
57
-
58
- const result = e1.toExample(mime) as string
59
- assert.typeOf(result, 'string', 'result is a string')
60
-
61
- const dom = new JSDOM(result, { contentType: mime })
62
- const schema = dom.window.document
63
- const inner = schema.querySelector('p1')!
64
- assert.ok(inner, 'has the inner element')
65
- const value = inner.textContent!.trim()
66
- assert.isAtMost(value.length, 10, 'has the maximum length')
67
- })
68
-
69
- test('returns an array when multiple property', ({ assert }) => {
70
- const p1 = e1.addTypedProperty('string', 'p1')
71
- p1.multiple = true
72
- const result = e1.toExample(mime) as string
73
-
74
- assert.typeOf(result, 'string', 'result is a string')
75
-
76
- const dom = new JSDOM(result, { contentType: mime })
77
- const schema = dom.window.document
78
- assert.lengthOf(schema.querySelectorAll('e1'), 1, 'has the parent')
79
- assert.lengthOf(schema.querySelectorAll('e1 p1'), 1, 'has only one property')
80
- const inner = schema.querySelector('p1')!
81
- const value = inner.textContent!.trim()
82
- assert.isAtMost(value.length, 10, 'has the maximum length')
83
- })
84
-
85
- test('returns example value when defined on the mime type scheme', ({ assert }) => {
86
- const p1 = e1.addTypedProperty('string', 'p1')
87
- p1.schema = {
88
- minimum: 1,
89
- maximum: 3,
90
- examples: ['test123'],
91
- }
92
- const result = e1.toExample(mime) as string
93
- assert.typeOf(result, 'string', 'result is a string')
94
- const dom = new JSDOM(result, { contentType: mime })
95
- const schema = dom.window.document
96
- assert.lengthOf(schema.querySelectorAll('e1'), 1, 'has the parent')
97
- assert.lengthOf(schema.querySelectorAll('e1 p1'), 1, 'has only one property')
98
- const inner = schema.querySelector('p1')!
99
- const value = inner.textContent!.trim()
100
- assert.equal(value, 'test123', 'has the example value')
101
- })
102
-
103
- test('returns all example values with multiple property', ({ assert }) => {
104
- const p1 = e1.addTypedProperty('string', 'p1')
105
- p1.multiple = true
106
- p1.schema = {
107
- examples: ['test123', '123test'],
108
- }
109
- const result = e1.toExample(mime) as string
110
- assert.typeOf(result, 'string', 'result is a string')
111
- const dom = new JSDOM(result, { contentType: mime })
112
- const schema = dom.window.document
113
- const ps = schema.querySelectorAll('p1')
114
- assert.lengthOf(ps, 2, 'has an example')
115
- assert.equal(ps[0].textContent!.trim(), 'test123')
116
- assert.equal(ps[1].textContent!.trim(), '123test')
117
- })
118
-
119
- test('returns the default value when defined', ({ assert }) => {
120
- const p1 = e1.addTypedProperty('string', 'p1')
121
- p1.schema = {
122
- defaultValue: { value: 'test123', type: 'literal' },
123
- }
124
-
125
- const result = e1.toExample(mime) as string
126
- assert.typeOf(result, 'string', 'result is a string')
127
-
128
- const dom = new JSDOM(result, { contentType: mime })
129
- const schema = dom.window.document
130
-
131
- assert.lengthOf(schema.querySelectorAll('e1'), 1, 'has the parent')
132
- assert.lengthOf(schema.querySelectorAll('e1 p1'), 1, 'has only one property')
133
- const inner = schema.querySelector('p1')!
134
- const value = inner.textContent!.trim()
135
- assert.equal(value, 'test123', 'has the default value')
136
- })
137
-
138
- test('returns the default value when multiple property', ({ assert }) => {
139
- const p1 = e1.addTypedProperty('string', 'p1')
140
- p1.multiple = true
141
- p1.schema = {
142
- defaultValue: { value: 'test123', type: 'literal' },
143
- }
144
- const result = e1.toExample(mime) as string
145
-
146
- assert.typeOf(result, 'string', 'result is a string')
147
- const dom = new JSDOM(result, { contentType: mime })
148
- const schema = dom.window.document
149
-
150
- assert.lengthOf(schema.querySelectorAll('e1'), 1, 'has the parent')
151
- assert.lengthOf(schema.querySelectorAll('e1 p1'), 1, 'has only one property')
152
- const inner = schema.querySelector('p1')!
153
- const value = inner.textContent!.trim()
154
- assert.equal(value, 'test123', 'has the default value')
155
- })
156
-
157
- test('respects both the min and max length', ({ assert }) => {
158
- const p1 = e1.addTypedProperty('string', 'p1')
159
- p1.schema = {
160
- minimum: 15,
161
- maximum: 30,
162
- }
163
-
164
- const result = e1.toExample(mime) as string
165
- assert.typeOf(result, 'string', 'result is a string')
166
-
167
- const dom = new JSDOM(result, { contentType: mime })
168
- const schema = dom.window.document
169
-
170
- assert.lengthOf(schema.querySelectorAll('e1'), 1, 'has the parent')
171
- assert.lengthOf(schema.querySelectorAll('e1 p1'), 1, 'has only one property')
172
- const inner = schema.querySelector('p1')!
173
- const value = inner.textContent!.trim()
174
-
175
- assert.isAtLeast(value.length, 15, 'has the minimum length')
176
- assert.isAtMost(value.length, 30, 'has the maximum length')
177
- })
178
- })
179
-
180
- test.group('XML DataEntity Generator: number', (group) => {
181
- let e1: DataEntity
182
-
183
- group.each.setup(() => {
184
- const ns = new DataNamespace()
185
- const d1 = ns.addDataModel('d1')
186
- e1 = d1.addEntity('e1')
187
- })
188
-
189
- test('generates an example value', ({ assert }) => {
190
- e1.addTypedProperty('number', 'p1')
191
- const result = e1.toExample(mime) as string
192
- assert.typeOf(result, 'string', 'result is a string')
193
-
194
- const dom = new JSDOM(result, { contentType: mime })
195
- const schema = dom.window.document
196
-
197
- const outer = schema.querySelector('e1')!
198
- assert.ok(outer, 'has the outer element')
199
- const inner = outer.querySelector('p1')!
200
- assert.ok(inner, 'has the inner element')
201
- assert.match(inner.textContent!.trim(), /^\d+$/, 'has the property number')
202
- })
203
-
204
- test('has the minimum value', ({ assert }) => {
205
- const p1 = e1.addTypedProperty('number', 'p1')
206
- p1.schema = {
207
- minimum: 10,
208
- }
209
- const result = e1.toExample(mime) as string
210
- assert.typeOf(result, 'string', 'result is a string')
211
-
212
- const dom = new JSDOM(result, { contentType: mime })
213
- const schema = dom.window.document
214
-
215
- const outer = schema.querySelector('e1')!
216
- assert.ok(outer, 'has the outer element')
217
- const inner = outer.querySelector('p1')!
218
- assert.ok(inner, 'has the inner element')
219
- const value = Number(inner.textContent!.trim())
220
- assert.isAtLeast(value, 10, 'has the minimum length')
221
- })
222
-
223
- test('has the maximum value', ({ assert }) => {
224
- const p1 = e1.addTypedProperty('number', 'p1')
225
- p1.schema = {
226
- maximum: 10,
227
- }
228
- const result = e1.toExample(mime) as string
229
- assert.typeOf(result, 'string', 'result is a string')
230
-
231
- const dom = new JSDOM(result, { contentType: mime })
232
- const schema = dom.window.document
233
-
234
- const outer = schema.querySelector('e1')!
235
- assert.ok(outer, 'has the outer element')
236
- const inner = outer.querySelector('p1')!
237
- assert.ok(inner, 'has the inner element')
238
- const value = Number(inner.textContent!.trim())
239
- assert.isAtMost(value, 10, 'has the maximum length')
240
- })
241
-
242
- test('respects both the min and max', ({ assert }) => {
243
- const p1 = e1.addTypedProperty('number', 'p1')
244
- p1.schema = {
245
- minimum: 5,
246
- maximum: 10,
247
- }
248
- const result = e1.toExample(mime) as string
249
- assert.typeOf(result, 'string', 'result is a string')
250
-
251
- const dom = new JSDOM(result, { contentType: mime })
252
- const schema = dom.window.document
253
-
254
- const outer = schema.querySelector('e1')!
255
- assert.ok(outer, 'has the outer element')
256
- const inner = outer.querySelector('p1')!
257
- assert.ok(inner, 'has the inner element')
258
- const value = Number(inner.textContent!.trim())
259
-
260
- assert.isAtLeast(value, 5, 'has the minimum length')
261
- assert.isAtMost(value, 10, 'has the maximum length')
262
- })
263
-
264
- // Note, this may randomly fail because the data generation library does not
265
- // guarantee to always generate a float (it does generate a float but with `.00` value).
266
- test('generates a floating-point number for a float format', ({ assert }) => {
267
- const p1 = e1.addTypedProperty('number', 'p1')
268
- p1.bindings = [
269
- {
270
- type: 'web',
271
- schema: {
272
- format: 'float',
273
- },
274
- },
275
- ]
276
- const result = e1.toExample(mime) as string
277
- assert.typeOf(result, 'string', 'result is a string')
278
-
279
- const dom = new JSDOM(result, { contentType: mime })
280
- const schema = dom.window.document
281
-
282
- const outer = schema.querySelector('e1')!
283
- assert.ok(outer, 'has the outer element')
284
- const inner = outer.querySelector('p1')!
285
- assert.ok(inner, 'has the inner element')
286
- const value = Number(inner.textContent!.trim())
287
- assert.isNotNaN(value)
288
- // const rest = value % 1;
289
- // assert.isAbove(rest, 0, 'module is above 0');
290
- // assert.isBelow(rest, 1, 'module is below 0');
291
- })
292
-
293
- test('generates a floating-point number for a double format', ({ assert }) => {
294
- const p1 = e1.addTypedProperty('number', 'p1')
295
- p1.bindings = [
296
- {
297
- type: 'web',
298
- schema: {
299
- format: 'double',
300
- },
301
- },
302
- ]
303
- const result = e1.toExample(mime) as string
304
- assert.typeOf(result, 'string', 'result is a string')
305
-
306
- const dom = new JSDOM(result, { contentType: mime })
307
- const schema = dom.window.document
308
-
309
- const outer = schema.querySelector('e1')!
310
- assert.ok(outer, 'has the outer element')
311
- const inner = outer.querySelector('p1')!
312
- assert.ok(inner, 'has the inner element')
313
- const value = Number(inner.textContent!.trim())
314
- assert.isNotNaN(value)
315
- // const rest = value % 1;
316
- // assert.isAbove(rest, 0, 'module is above 0');
317
- // assert.isBelow(rest, 1, 'module is below 0');
318
- })
319
-
320
- test('returns an array number property when multiple property', ({ assert }) => {
321
- const p1 = e1.addTypedProperty('number', 'p1')
322
- p1.multiple = true
323
- const result = e1.toExample(mime) as string
324
- assert.typeOf(result, 'string', 'result is a string')
325
-
326
- const dom = new JSDOM(result, { contentType: mime })
327
- const schema = dom.window.document
328
-
329
- const outer = schema.querySelector('e1')!
330
- assert.ok(outer, 'has the outer element')
331
- const inner = outer.querySelector('p1')!
332
- assert.ok(inner, 'has the inner element')
333
- const value = Number(inner.textContent!.trim())
334
- assert.isNotNaN(value)
335
- })
336
-
337
- test('respects the "multipleOf" schema property', ({ assert }) => {
338
- const p1 = e1.addTypedProperty('number', 'p1')
339
- p1.schema = {
340
- multipleOf: 5,
341
- }
342
- const result = e1.toExample(mime) as string
343
- assert.typeOf(result, 'string', 'result is a string')
344
-
345
- const dom = new JSDOM(result, { contentType: mime })
346
- const schema = dom.window.document
347
-
348
- const outer = schema.querySelector('e1')!
349
- assert.ok(outer, 'has the outer element')
350
- const inner = outer.querySelector('p1')!
351
- assert.ok(inner, 'has the inner element')
352
- const value = Number(inner.textContent!.trim())
353
- assert.equal(value % 5, 0, 'has a value multipliable by 5')
354
- })
355
-
356
- test('returns the example value', ({ assert }) => {
357
- const p1 = e1.addTypedProperty('number', 'p1')
358
- p1.schema = {
359
- examples: ['1', '2', '3'],
360
- }
361
- const result = e1.toExample(mime) as string
362
- assert.typeOf(result, 'string', 'result is a string')
363
-
364
- const dom = new JSDOM(result, { contentType: mime })
365
- const schema = dom.window.document
366
-
367
- const outer = schema.querySelector('e1')!
368
- assert.ok(outer, 'has the outer element')
369
- const inner = outer.querySelector('p1')!
370
- assert.ok(inner, 'has the inner element')
371
- const value = Number(inner.textContent!.trim())
372
-
373
- assert.equal(value, 1, 'has the first example')
374
- })
375
-
376
- test('returns all examples when multiple property', ({ assert }) => {
377
- const p1 = e1.addTypedProperty('number', 'p1')
378
- p1.multiple = true
379
- p1.schema = {
380
- examples: ['1', '2', '3'],
381
- }
382
- const result = e1.toExample(mime) as string
383
- assert.typeOf(result, 'string', 'result is a string')
384
-
385
- const dom = new JSDOM(result, { contentType: mime })
386
- const schema = dom.window.document
387
-
388
- const outer = schema.querySelector('e1')!
389
- assert.ok(outer, 'has the outer element')
390
-
391
- const params = outer.querySelectorAll('p1')
392
- assert.lengthOf(params, 3, 'has all example values')
393
- assert.equal(params[0].textContent!.trim(), '1')
394
- assert.equal(params[1].textContent!.trim(), '2')
395
- assert.equal(params[2].textContent!.trim(), '3')
396
- })
397
-
398
- test('returns the default value', ({ assert }) => {
399
- const p1 = e1.addTypedProperty('number', 'p1')
400
- p1.schema = {
401
- defaultValue: { value: '123', type: 'literal' },
402
- }
403
- const result = e1.toExample(mime) as string
404
- assert.typeOf(result, 'string', 'result is a string')
405
-
406
- const dom = new JSDOM(result, { contentType: mime })
407
- const schema = dom.window.document
408
-
409
- const outer = schema.querySelector('e1')!
410
- assert.ok(outer, 'has the outer element')
411
- const inner = outer.querySelector('p1')!
412
- assert.ok(inner, 'has the inner element')
413
- const value = Number(inner.textContent!.trim())
414
-
415
- assert.equal(value, 123, 'has the first example')
416
- })
417
- })
418
-
419
- test.group('XML DataEntity Generator: int64 format', (group) => {
420
- let e1: DataEntity
421
- let p1: DataProperty
422
-
423
- group.each.setup(() => {
424
- const ns = new DataNamespace()
425
- const d1 = ns.addDataModel('d1')
426
- e1 = d1.addEntity('e1')
427
- p1 = e1.addTypedProperty('number', 'p1')
428
- p1.getWebBinding().format = 'int64'
429
- })
430
-
431
- test('generates an example value', ({ assert }) => {
432
- const result = e1.toExample(mime) as string
433
- assert.typeOf(result, 'string', 'result is a string')
434
-
435
- const dom = new JSDOM(result, { contentType: mime })
436
- const schema = dom.window.document
437
-
438
- const outer = schema.querySelector('e1')!
439
- assert.ok(outer, 'has the outer element')
440
- const inner = outer.querySelector('p1')!
441
- assert.ok(inner, 'has the inner element')
442
- const value = Number(inner.textContent!.trim())
443
-
444
- assert.typeOf(value, 'number', 'has the property number')
445
- })
446
-
447
- test('has the minimum value', ({ assert }) => {
448
- p1.schema = {
449
- minimum: 10,
450
- }
451
- const result = e1.toExample(mime) as string
452
- assert.typeOf(result, 'string', 'result is a string')
453
-
454
- const dom = new JSDOM(result, { contentType: mime })
455
- const schema = dom.window.document
456
-
457
- const outer = schema.querySelector('e1')!
458
- assert.ok(outer, 'has the outer element')
459
- const inner = outer.querySelector('p1')!
460
- assert.ok(inner, 'has the inner element')
461
- const value = Number(inner.textContent!.trim())
462
-
463
- assert.isAtLeast(value, 10, 'has the minimum length')
464
- })
465
-
466
- test('has the maximum value', ({ assert }) => {
467
- p1.schema = {
468
- maximum: 10,
469
- }
470
- const result = e1.toExample(mime) as string
471
- assert.typeOf(result, 'string', 'result is a string')
472
-
473
- const dom = new JSDOM(result, { contentType: mime })
474
- const schema = dom.window.document
475
-
476
- const outer = schema.querySelector('e1')!
477
- assert.ok(outer, 'has the outer element')
478
- const inner = outer.querySelector('p1')!
479
- assert.ok(inner, 'has the inner element')
480
- const value = Number(inner.textContent!.trim())
481
-
482
- assert.isAtMost(value, 10, 'has the maximum length')
483
- })
484
-
485
- test('respects both the min and max', ({ assert }) => {
486
- p1.schema = {
487
- minimum: 5,
488
- maximum: 10,
489
- }
490
- const result = e1.toExample(mime) as string
491
- assert.typeOf(result, 'string', 'result is a string')
492
-
493
- const dom = new JSDOM(result, { contentType: mime })
494
- const schema = dom.window.document
495
-
496
- const outer = schema.querySelector('e1')!
497
- assert.ok(outer, 'has the outer element')
498
- const inner = outer.querySelector('p1')!
499
- assert.ok(inner, 'has the inner element')
500
- const value = Number(inner.textContent!.trim())
501
-
502
- assert.isAtLeast(value, 5, 'has the minimum length')
503
- assert.isAtMost(value, 10, 'has the maximum length')
504
- })
505
-
506
- test('generates an integer for an int32 format', ({ assert }) => {
507
- p1.bindings = [
508
- {
509
- type: 'web',
510
- schema: {
511
- format: 'int32',
512
- },
513
- },
514
- ]
515
- const result = e1.toExample(mime) as string
516
- assert.typeOf(result, 'string', 'result is a string')
517
-
518
- const dom = new JSDOM(result, { contentType: mime })
519
- const schema = dom.window.document
520
-
521
- const outer = schema.querySelector('e1')!
522
- assert.ok(outer, 'has the outer element')
523
- const inner = outer.querySelector('p1')!
524
- assert.ok(inner, 'has the inner element')
525
- const value = Number(inner.textContent!.trim())
526
-
527
- const rest = value % 1
528
- assert.equal(rest, 0, 'module is 0')
529
- })
530
-
531
- test('generates an integer for an int64 format', ({ assert }) => {
532
- const result = e1.toExample(mime) as string
533
- assert.typeOf(result, 'string', 'result is a string')
534
-
535
- const dom = new JSDOM(result, { contentType: mime })
536
- const schema = dom.window.document
537
-
538
- const outer = schema.querySelector('e1')!
539
- assert.ok(outer, 'has the outer element')
540
- const inner = outer.querySelector('p1')!
541
- assert.ok(inner, 'has the inner element')
542
- const value = Number(inner.textContent!.trim())
543
-
544
- const rest = value % 1
545
- assert.equal(rest, 0, 'module is 0')
546
- })
547
-
548
- test('returns an array number property when multiple property', ({ assert }) => {
549
- p1.multiple = true
550
- const result = e1.toExample(mime) as string
551
- assert.typeOf(result, 'string', 'result is a string')
552
-
553
- const dom = new JSDOM(result, { contentType: mime })
554
- const schema = dom.window.document
555
-
556
- const outer = schema.querySelector('e1')!
557
- assert.ok(outer, 'has the outer element')
558
- const inner = outer.querySelector('p1')!
559
- assert.ok(inner, 'has the inner element')
560
- const value = Number(inner.textContent!.trim())
561
-
562
- assert.typeOf(value, 'number', 'has a final value correct type')
563
- })
564
-
565
- test('respects the "multipleOf" schema property', ({ assert }) => {
566
- p1.schema = {
567
- multipleOf: 5,
568
- }
569
- const result = e1.toExample(mime) as string
570
- assert.typeOf(result, 'string', 'result is a string')
571
-
572
- const dom = new JSDOM(result, { contentType: mime })
573
- const schema = dom.window.document
574
-
575
- const outer = schema.querySelector('e1')!
576
- assert.ok(outer, 'has the outer element')
577
- const inner = outer.querySelector('p1')!
578
- assert.ok(inner, 'has the inner element')
579
- const value = Number(inner.textContent!.trim())
580
-
581
- assert.equal(value % 5, 0, 'has a value multipliable by 5')
582
- })
583
-
584
- test('returns the example value', ({ assert }) => {
585
- p1.schema = {
586
- examples: ['1', '2', '3'],
587
- }
588
- const result = e1.toExample(mime) as string
589
- assert.typeOf(result, 'string', 'result is a string')
590
-
591
- const dom = new JSDOM(result, { contentType: mime })
592
- const schema = dom.window.document
593
-
594
- const outer = schema.querySelector('e1')!
595
- assert.ok(outer, 'has the outer element')
596
- const inner = outer.querySelector('p1')!
597
- assert.ok(inner, 'has the inner element')
598
- const value = Number(inner.textContent!.trim())
599
-
600
- assert.equal(value, 1, 'has the first example')
601
- })
602
-
603
- test('returns all examples when multiple property', ({ assert }) => {
604
- p1.multiple = true
605
- p1.schema = {
606
- examples: ['1', '2', '3'],
607
- }
608
- const result = e1.toExample(mime) as string
609
- assert.typeOf(result, 'string', 'result is a string')
610
-
611
- const dom = new JSDOM(result, { contentType: mime })
612
- const schema = dom.window.document
613
-
614
- const outer = schema.querySelector('e1')!
615
- assert.ok(outer, 'has the outer element')
616
-
617
- const params = outer.querySelectorAll('p1')
618
- assert.lengthOf(params, 3, 'has all example values')
619
- assert.equal(params[0].textContent!.trim(), '1')
620
- assert.equal(params[1].textContent!.trim(), '2')
621
- assert.equal(params[2].textContent!.trim(), '3')
622
- })
623
-
624
- test('returns the default value', ({ assert }) => {
625
- p1.schema = {
626
- defaultValue: { value: '123', type: 'literal' },
627
- }
628
- const result = e1.toExample(mime) as string
629
- assert.typeOf(result, 'string', 'result is a string')
630
-
631
- const dom = new JSDOM(result, { contentType: mime })
632
- const schema = dom.window.document
633
-
634
- const outer = schema.querySelector('e1')!
635
- assert.ok(outer, 'has the outer element')
636
- const inner = outer.querySelector('p1')!
637
- assert.ok(inner, 'has the inner element')
638
- const value = Number(inner.textContent!.trim())
639
-
640
- assert.deepEqual(value, 123, 'has the first example')
641
- })
642
- })
643
-
644
- test.group('XML DataEntity Generator: date', (group) => {
645
- let e1: DataEntity
646
-
647
- group.each.setup(() => {
648
- const ns = new DataNamespace()
649
- const d1 = ns.addDataModel('d1')
650
- e1 = d1.addEntity('e1')
651
- })
652
-
653
- test('generates an example', ({ assert }) => {
654
- e1.addTypedProperty('date', 'p1')
655
- const result = e1.toExample(mime) as string
656
- assert.typeOf(result, 'string', 'result is a string')
657
-
658
- const dom = new JSDOM(result, { contentType: mime })
659
- const schema = dom.window.document
660
-
661
- const outer = schema.querySelector('e1')!
662
- assert.ok(outer, 'has the outer element')
663
- const inner = outer.querySelector('p1')!
664
- assert.ok(inner, 'has the inner element')
665
- const value = inner.textContent!.trim()
666
-
667
- assert.match(value, dateRe)
668
- })
669
-
670
- test('generates an example with the multiple property', ({ assert }) => {
671
- const p1 = e1.addTypedProperty('date', 'p1')
672
- p1.multiple = true
673
- const result = e1.toExample(mime) as string
674
- assert.typeOf(result, 'string', 'result is a string')
675
-
676
- const dom = new JSDOM(result, { contentType: mime })
677
- const schema = dom.window.document
678
-
679
- const outer = schema.querySelector('e1')!
680
- assert.ok(outer, 'has the outer element')
681
- const inner = outer.querySelector('p1')!
682
- assert.ok(inner, 'has the inner element')
683
- const value = inner.textContent!.trim()
684
-
685
- assert.match(value, dateRe)
686
- })
687
-
688
- test('returns the default value', ({ assert }) => {
689
- const p1 = e1.addTypedProperty('date', 'p1')
690
- p1.schema = {
691
- defaultValue: { value: '2022-08-08', type: 'literal' },
692
- }
693
- const result = e1.toExample(mime) as string
694
- assert.typeOf(result, 'string', 'result is a string')
695
-
696
- const dom = new JSDOM(result, { contentType: mime })
697
- const schema = dom.window.document
698
-
699
- const outer = schema.querySelector('e1')!
700
- assert.ok(outer, 'has the outer element')
701
- const inner = outer.querySelector('p1')!
702
- assert.ok(inner, 'has the inner element')
703
- const value = inner.textContent!.trim()
704
-
705
- assert.equal(value, '2022-08-08')
706
- })
707
-
708
- test('returns the default value as array with multiple property', ({ assert }) => {
709
- const p1 = e1.addTypedProperty('date', 'p1')
710
- p1.multiple = true
711
- p1.schema = {
712
- defaultValue: { value: '2022-08-08', type: 'literal' },
713
- }
714
- const result = e1.toExample(mime) as string
715
- assert.typeOf(result, 'string', 'result is a string')
716
-
717
- const dom = new JSDOM(result, { contentType: mime })
718
- const schema = dom.window.document
719
-
720
- const outer = schema.querySelector('e1')!
721
- assert.ok(outer, 'has the outer element')
722
- const inner = outer.querySelector('p1')!
723
- assert.ok(inner, 'has the inner element')
724
- const value = inner.textContent!.trim()
725
-
726
- assert.equal(value, '2022-08-08')
727
- })
728
-
729
- test('returns the example value', ({ assert }) => {
730
- const p1 = e1.addTypedProperty('date', 'p1')
731
- p1.schema = {
732
- examples: ['2022-08-08', '2022-08-09'],
733
- }
734
- const result = e1.toExample(mime) as string
735
- assert.typeOf(result, 'string', 'result is a string')
736
-
737
- const dom = new JSDOM(result, { contentType: mime })
738
- const schema = dom.window.document
739
-
740
- const outer = schema.querySelector('e1')!
741
- assert.ok(outer, 'has the outer element')
742
- const inner = outer.querySelector('p1')!
743
- assert.ok(inner, 'has the inner element')
744
- const value = inner.textContent!.trim()
745
-
746
- assert.equal(value, '2022-08-08')
747
- })
748
-
749
- test('returns the default value as array with multiple property', ({ assert }) => {
750
- const p1 = e1.addTypedProperty('date', 'p1')
751
- p1.multiple = true
752
- p1.schema = {
753
- examples: ['2022-08-08', '2022-08-09'],
754
- }
755
- const result = e1.toExample(mime) as string
756
- assert.typeOf(result, 'string', 'result is a string')
757
-
758
- const dom = new JSDOM(result, { contentType: mime })
759
- const schema = dom.window.document
760
-
761
- const outer = schema.querySelector('e1')!
762
- assert.ok(outer, 'has the outer element')
763
- const properties = outer.querySelectorAll('p1')
764
- assert.lengthOf(properties, 2, 'has both examples')
765
-
766
- assert.equal(properties[0].textContent!.trim(), '2022-08-08')
767
- assert.equal(properties[1].textContent!.trim(), '2022-08-09')
768
- })
769
- })
770
-
771
- test.group('XML DataEntity Generator: datetime', (group) => {
772
- let e1: DataEntity
773
-
774
- group.each.setup(() => {
775
- const ns = new DataNamespace()
776
- const d1 = ns.addDataModel('d1')
777
- e1 = d1.addEntity('e1')
778
- })
779
-
780
- test('generates an example with default format', ({ assert }) => {
781
- e1.addTypedProperty('datetime', 'p1')
782
- const result = e1.toExample(mime) as string
783
- assert.typeOf(result, 'string', 'result is a string')
784
-
785
- const dom = new JSDOM(result, { contentType: mime })
786
- const schema = dom.window.document
787
-
788
- const outer = schema.querySelector('e1')!
789
- assert.ok(outer, 'has the outer element')
790
- const inner = outer.querySelector('p1')!
791
- assert.ok(inner, 'has the inner element')
792
- const value = inner.textContent!.trim()
793
-
794
- assert.match(value, rfc3339Re)
795
- })
796
-
797
- test('returns the default value', ({ assert }) => {
798
- const p1 = e1.addTypedProperty('datetime', 'p1')
799
- p1.schema = {
800
- defaultValue: { value: '2036-01-04T19:49:30.224Z', type: 'literal' },
801
- }
802
- const result = e1.toExample(mime) as string
803
- assert.typeOf(result, 'string', 'result is a string')
804
-
805
- const dom = new JSDOM(result, { contentType: mime })
806
- const schema = dom.window.document
807
-
808
- const outer = schema.querySelector('e1')!
809
- assert.ok(outer, 'has the outer element')
810
- const inner = outer.querySelector('p1')!
811
- assert.ok(inner, 'has the inner element')
812
- const value = inner.textContent!.trim()
813
-
814
- assert.equal(value, '2036-01-04T19:49:30.224Z')
815
- })
816
-
817
- test('returns the default value as array with multiple property', ({ assert }) => {
818
- const p1 = e1.addTypedProperty('datetime', 'p1')
819
- p1.multiple = true
820
- p1.schema = {
821
- defaultValue: { value: '2036-01-04T19:49:30.224Z', type: 'literal' },
822
- }
823
- const result = e1.toExample(mime) as string
824
- assert.typeOf(result, 'string', 'result is a string')
825
-
826
- const dom = new JSDOM(result, { contentType: mime })
827
- const schema = dom.window.document
828
-
829
- const outer = schema.querySelector('e1')!
830
- assert.ok(outer, 'has the outer element')
831
- const inner = outer.querySelector('p1')!
832
- assert.ok(inner, 'has the inner element')
833
- const value = inner.textContent!.trim()
834
-
835
- assert.equal(value, '2036-01-04T19:49:30.224Z')
836
- })
837
-
838
- test('returns the example value', ({ assert }) => {
839
- const p1 = e1.addTypedProperty('datetime', 'p1')
840
- p1.schema = {
841
- examples: ['2036-01-04T19:49:30.224Z', '2036-01-05T19:49:30.224Z'],
842
- }
843
- const result = e1.toExample(mime) as string
844
- assert.typeOf(result, 'string', 'result is a string')
845
-
846
- const dom = new JSDOM(result, { contentType: mime })
847
- const schema = dom.window.document
848
-
849
- const outer = schema.querySelector('e1')!
850
- assert.ok(outer, 'has the outer element')
851
- const inner = outer.querySelector('p1')!
852
- assert.ok(inner, 'has the inner element')
853
- const value = inner.textContent!.trim()
854
-
855
- assert.equal(value, '2036-01-04T19:49:30.224Z')
856
- })
857
-
858
- test('returns the default value as array with multiple property', ({ assert }) => {
859
- const p1 = e1.addTypedProperty('datetime', 'p1')
860
- p1.multiple = true
861
- p1.schema = {
862
- examples: ['2036-01-04T19:49:30.224Z', '2036-01-05T19:49:30.224Z'],
863
- }
864
- const result = e1.toExample(mime) as string
865
- assert.typeOf(result, 'string', 'result is a string')
866
-
867
- const dom = new JSDOM(result, { contentType: mime })
868
- const schema = dom.window.document
869
-
870
- const outer = schema.querySelector('e1')!
871
- assert.ok(outer, 'has the outer element')
872
- const params = outer.querySelectorAll('p1')
873
- assert.lengthOf(params, 2, 'has both example values')
874
-
875
- assert.deepEqual(params[0].textContent!.trim(), '2036-01-04T19:49:30.224Z')
876
- assert.deepEqual(params[1].textContent!.trim(), '2036-01-05T19:49:30.224Z')
877
- })
878
- })
879
-
880
- test.group('XML DataEntity Generator: time', (group) => {
881
- let e1: DataEntity
882
-
883
- group.each.setup(() => {
884
- const ns = new DataNamespace()
885
- const d1 = ns.addDataModel('d1')
886
- e1 = d1.addEntity('e1')
887
- })
888
-
889
- test('generates an example', ({ assert }) => {
890
- e1.addTypedProperty('time', 'p1')
891
- const result = e1.toExample(mime) as string
892
- assert.typeOf(result, 'string', 'result is a string')
893
-
894
- const dom = new JSDOM(result, { contentType: mime })
895
- const schema = dom.window.document
896
-
897
- const outer = schema.querySelector('e1')!
898
- assert.ok(outer, 'has the outer element')
899
- const inner = outer.querySelector('p1')!
900
- assert.ok(inner, 'has the inner element')
901
- const value = inner.textContent!.trim()
902
-
903
- assert.match(value, timeRe)
904
- })
905
-
906
- test('generates an example with multiple property', ({ assert }) => {
907
- const p1 = e1.addTypedProperty('time', 'p1')
908
- p1.multiple = true
909
- const result = e1.toExample(mime) as string
910
- assert.typeOf(result, 'string', 'result is a string')
911
-
912
- const dom = new JSDOM(result, { contentType: mime })
913
- const schema = dom.window.document
914
-
915
- const outer = schema.querySelector('e1')!
916
- assert.ok(outer, 'has the outer element')
917
- const inner = outer.querySelector('p1')!
918
- assert.ok(inner, 'has the inner element')
919
- const value = inner.textContent!.trim()
920
-
921
- assert.match(value, timeRe)
922
- })
923
-
924
- test('returns the default value', ({ assert }) => {
925
- const p1 = e1.addTypedProperty('time', 'p1')
926
- p1.schema = {
927
- defaultValue: { value: '2080-02-04T09:39:13', type: 'literal' },
928
- }
929
- const result = e1.toExample(mime) as string
930
- assert.typeOf(result, 'string', 'result is a string')
931
-
932
- const dom = new JSDOM(result, { contentType: mime })
933
- const schema = dom.window.document
934
-
935
- const outer = schema.querySelector('e1')!
936
- assert.ok(outer, 'has the outer element')
937
- const inner = outer.querySelector('p1')!
938
- assert.ok(inner, 'has the inner element')
939
- const value = inner.textContent!.trim()
940
-
941
- assert.equal(value, '2080-02-04T09:39:13')
942
- })
943
-
944
- test('returns the default value as array with multiple property', ({ assert }) => {
945
- const p1 = e1.addTypedProperty('time', 'p1')
946
- p1.multiple = true
947
- p1.schema = {
948
- defaultValue: { value: '2080-02-04T09:39:13', type: 'literal' },
949
- }
950
- const result = e1.toExample(mime) as string
951
- assert.typeOf(result, 'string', 'result is a string')
952
-
953
- const dom = new JSDOM(result, { contentType: mime })
954
- const schema = dom.window.document
955
-
956
- const outer = schema.querySelector('e1')!
957
- assert.ok(outer, 'has the outer element')
958
- const inner = outer.querySelector('p1')!
959
- assert.ok(inner, 'has the inner element')
960
- const value = inner.textContent!.trim()
961
-
962
- assert.deepEqual(value, '2080-02-04T09:39:13')
963
- })
964
-
965
- test('returns the example value', ({ assert }) => {
966
- const p1 = e1.addTypedProperty('time', 'p1')
967
- p1.schema = {
968
- examples: ['2080-02-04T09:39:13', '2080-02-05T09:39:13'],
969
- }
970
- const result = e1.toExample(mime) as string
971
- assert.typeOf(result, 'string', 'result is a string')
972
-
973
- const dom = new JSDOM(result, { contentType: mime })
974
- const schema = dom.window.document
975
-
976
- const outer = schema.querySelector('e1')!
977
- assert.ok(outer, 'has the outer element')
978
- const inner = outer.querySelector('p1')!
979
- assert.ok(inner, 'has the inner element')
980
- const value = inner.textContent!.trim()
981
-
982
- assert.equal(value, '2080-02-04T09:39:13')
983
- })
984
-
985
- test('returns the default value as array with multiple property', ({ assert }) => {
986
- const p1 = e1.addTypedProperty('time', 'p1')
987
- p1.multiple = true
988
- p1.schema = {
989
- examples: ['2080-02-04T09:39:13', '2080-02-05T09:39:13'],
990
- }
991
- const result = e1.toExample(mime) as string
992
- assert.typeOf(result, 'string', 'result is a string')
993
-
994
- const dom = new JSDOM(result, { contentType: mime })
995
- const schema = dom.window.document
996
-
997
- const outer = schema.querySelector('e1')!
998
- assert.ok(outer, 'has the outer element')
999
- const params = outer.querySelectorAll('p1')
1000
- assert.lengthOf(params, 2, 'has both example values')
1001
-
1002
- assert.equal(params[0].textContent!.trim(), '2080-02-04T09:39:13')
1003
- assert.equal(params[1].textContent!.trim(), '2080-02-05T09:39:13')
1004
- })
1005
- })
1006
-
1007
- test.group('XML DataEntity Generator: boolean', (group) => {
1008
- let e1: DataEntity
1009
-
1010
- group.each.setup(() => {
1011
- const ns = new DataNamespace()
1012
- const d1 = ns.addDataModel('d1')
1013
- e1 = d1.addEntity('e1')
1014
- })
1015
-
1016
- test('generates an example', ({ assert }) => {
1017
- e1.addTypedProperty('boolean', 'p1')
1018
- const result = e1.toExample(mime) as string
1019
- assert.typeOf(result, 'string', 'result is a string')
1020
-
1021
- const dom = new JSDOM(result, { contentType: mime })
1022
- const schema = dom.window.document
1023
-
1024
- const outer = schema.querySelector('e1')!
1025
- assert.ok(outer, 'has the outer element')
1026
- const inner = outer.querySelector('p1')!
1027
- assert.ok(inner, 'has the inner element')
1028
- const value = inner.textContent!.trim()
1029
-
1030
- assert.match(value, /^true|false$/, 'has the boolean value')
1031
- })
1032
-
1033
- test('generates an example with multiple property', ({ assert }) => {
1034
- const p1 = e1.addTypedProperty('boolean', 'p1')
1035
- p1.multiple = true
1036
- const result = e1.toExample(mime) as string
1037
- assert.typeOf(result, 'string', 'result is a string')
1038
-
1039
- const dom = new JSDOM(result, { contentType: mime })
1040
- const schema = dom.window.document
1041
-
1042
- const outer = schema.querySelector('e1')!
1043
- assert.ok(outer, 'has the outer element')
1044
- const inner = outer.querySelector('p1')!
1045
- assert.ok(inner, 'has the inner element')
1046
- const value = inner.textContent!.trim()
1047
-
1048
- assert.match(value, /^true|false$/, 'has the boolean value')
1049
- })
1050
- })
1051
-
1052
- // test.group('XML DataEntity Generator: nil', (group) => {
1053
- // let e1: DataEntity
1054
-
1055
- // group.each.setup(() => {
1056
- // const ns = new DataNamespace()
1057
- // const d1 = ns.addDataModel('d1')
1058
- // e1 = d1.addEntity('e1')
1059
- // })
1060
-
1061
- // test('generates an example', ({ assert }) => {
1062
- // e1.addTypedProperty('nil', 'p1')
1063
- // const result = e1.toExample(mime) as string
1064
- // assert.typeOf(result, 'string', 'result is a string')
1065
-
1066
- // const dom = new JSDOM(result, { contentType: mime })
1067
- // const schema = dom.window.document
1068
-
1069
- // const outer = schema.querySelector('e1')!
1070
- // assert.ok(outer, 'has the outer element')
1071
- // const inner = outer.querySelector('p1')!
1072
- // assert.ok(inner, 'has the inner element')
1073
- // const value = inner.textContent!.trim()
1074
-
1075
- // assert.isEmpty(value)
1076
- // })
1077
-
1078
- // test('generates an example with multiple property', ({ assert }) => {
1079
- // const p1 = e1.addTypedProperty('nil', 'p1')
1080
- // p1.multiple = true
1081
- // const result = e1.toExample(mime) as string
1082
- // assert.typeOf(result, 'string', 'result is a string')
1083
-
1084
- // const dom = new JSDOM(result, { contentType: mime })
1085
- // const schema = dom.window.document
1086
-
1087
- // const outer = schema.querySelector('e1')!
1088
- // assert.ok(outer, 'has the outer element')
1089
- // const inner = outer.querySelector('p1')!
1090
- // assert.ok(inner, 'has the inner element')
1091
- // const value = inner.textContent!.trim()
1092
-
1093
- // assert.isEmpty(value)
1094
- // })
1095
- // })
1096
-
1097
- test.group('XML DataEntity Generator: associations', (group) => {
1098
- let d1: DataModel
1099
- let e1: DataEntity
1100
- let e2: DataEntity
1101
-
1102
- group.each.setup(() => {
1103
- const ns = new DataNamespace()
1104
- d1 = ns.addDataModel('d1')
1105
- e1 = d1.addEntity('e1')
1106
- e2 = d1.addEntity('e2')
1107
- })
1108
-
1109
- test('creates a property from an association', ({ assert }) => {
1110
- e2.addTypedProperty('number', 'n1')
1111
- e1.addTargetAssociation(e2.key, 'a1')
1112
-
1113
- const result = e1.toExample(mime) as string
1114
-
1115
- const dom = new JSDOM(result, { contentType: mime })
1116
- const schema = dom.window.document
1117
-
1118
- const outer = schema.querySelector('e1')!
1119
- assert.ok(outer, 'has the outer element')
1120
-
1121
- const a1Element = outer.querySelector('a1')!
1122
- assert.ok(a1Element, 'has the association as Element')
1123
-
1124
- const n1Element = a1Element.querySelector('n1')!
1125
- assert.ok(n1Element, 'has the target property as element')
1126
-
1127
- assert.match(n1Element.textContent!.trim(), /^\d+$/, 'has the association properties')
1128
- })
1129
-
1130
- test('creates a deep association', ({ assert }) => {
1131
- const e3 = d1.addEntity('e3')
1132
- e3.addTypedProperty('number', 'i1')
1133
- e2.addTypedProperty('number', 'n1')
1134
- e1.addTargetAssociation(e2.key, 'a1')
1135
- e2.addTargetAssociation(e3.key, 'a2')
1136
-
1137
- const result = e1.toExample(mime) as string
1138
-
1139
- const dom = new JSDOM(result, { contentType: mime })
1140
- const schema = dom.window.document
1141
-
1142
- const outer = schema.querySelector('e1')!
1143
- assert.ok(outer, 'has the outer element')
1144
-
1145
- const a1Element = outer.querySelector('a1')!
1146
- assert.ok(a1Element, 'has the association as Element')
1147
-
1148
- const n1Element = a1Element.querySelector('n1')!
1149
- assert.ok(n1Element, 'has the target property as element')
1150
-
1151
- assert.match(n1Element.textContent!.trim(), /^\d+$/, 'has the association properties')
1152
-
1153
- const a2Element = a1Element.querySelector('a2')!
1154
- assert.ok(a2Element, 'has the deep association as Element')
1155
-
1156
- const i1Element = a2Element.querySelector('i1')!
1157
- assert.ok(i1Element, 'has the deep target property as element')
1158
-
1159
- assert.match(i1Element.textContent!.trim(), /^\d+$/, 'has the association properties')
1160
- })
1161
-
1162
- test('does not make associations to self (recursive #1)', ({ assert }) => {
1163
- e1.addTargetAssociation(e1.key, 'a1')
1164
- const result = e1.toExample(mime) as string
1165
-
1166
- const dom = new JSDOM(result, { contentType: mime })
1167
- const schema = dom.window.document
1168
-
1169
- const elements = schema.querySelectorAll('e1')
1170
- assert.lengthOf(elements, 1)
1171
- })
1172
-
1173
- test('does not make recursive associations (recursive #2)', ({ assert }) => {
1174
- const e3 = d1.addEntity('e3')
1175
- e3.addTypedProperty('number', 'i1')
1176
- e2.addTypedProperty('number', 'n1')
1177
- e1.addTargetAssociation(e2.key, 'a1')
1178
- e2.addTargetAssociation(e3.key, 'a2')
1179
- e3.addTargetAssociation(e1.key, 'a3')
1180
-
1181
- const result = e1.toExample(mime) as string
1182
- assert.typeOf(result, 'string', 'result is a string')
1183
-
1184
- const dom = new JSDOM(result, { contentType: mime })
1185
- const schema = dom.window.document
1186
-
1187
- const a3Element = schema.querySelectorAll('a3')
1188
- assert.lengthOf(a3Element, 0)
1189
- })
1190
-
1191
- test('returns the default union result', ({ assert }) => {
1192
- const e3 = d1.addEntity('e3')
1193
- e3.addTypedProperty('number', 'i1')
1194
- e2.addTypedProperty('string', 's1')
1195
- const a1 = e1.addTargetAssociation(e2.key, 'a1')
1196
- a1.addTarget(e3.key)
1197
-
1198
- const result = e1.toExample(mime) as string
1199
- assert.typeOf(result, 'string', 'result is a string')
1200
-
1201
- const dom = new JSDOM(result, { contentType: mime })
1202
- const schema = dom.window.document
1203
-
1204
- const s1Element = schema.querySelector('e1 a1 s1')
1205
- assert.ok(s1Element)
1206
- })
1207
-
1208
- // test('returns the default union result with multiple', ({ assert }) => {
1209
- // const e3 = d1.addEntity('e3');
1210
- // e3.addTypedProperty('integer', 'i1');
1211
- // e2.addTypedProperty('string', 's1');
1212
- // const a1 = e1.addTargetAssociation(e2.key, 'a1');
1213
- // a1.addTarget(e3.key);
1214
- // a1.multiple = true;
1215
-
1216
- // const result = e1.toExample(mime) as string;
1217
- // assert.typeOf(result, 'string', 'result is a string');
1218
-
1219
- // const dom = new JSDOM(result, { contentType: mime });
1220
- // const schema = dom.window.document;
1221
- // console.log(result);
1222
-
1223
- // const data = JSON.parse(result);
1224
- // assert.typeOf(data.a1, 'array', 'has the association property as an array');
1225
- // const [prop] = data.a1;
1226
- // assert.typeOf(prop, 'object', 'has the item in the array');
1227
- // assert.typeOf(prop.s1, 'string', 'has the association properties');
1228
- // });
1229
-
1230
- test('returns the schema for anyOf union', ({ assert }) => {
1231
- const e3 = d1.addEntity('e3')
1232
-
1233
- e2.addTypedProperty('string', 's1')
1234
- e3.addTypedProperty('number', 'i1')
1235
-
1236
- const a1 = e1.addTargetAssociation(e2.key, 'a1')
1237
- a1.addTarget(e3.key)
1238
-
1239
- a1.schema = { unionType: 'anyOf' }
1240
-
1241
- const result = e1.toExample(mime) as string
1242
- assert.typeOf(result, 'string', 'result is a string')
1243
-
1244
- const dom = new JSDOM(result, { contentType: mime })
1245
- const schema = dom.window.document
1246
-
1247
- const s1Element = schema.querySelector('e1 a1 s1')
1248
- assert.ok(s1Element)
1249
-
1250
- const i1Element = schema.querySelector('e1 a1 i1')
1251
- assert.notOk(i1Element)
1252
- })
1253
-
1254
- test('returns the schema for allOf union', ({ assert }) => {
1255
- const e3 = d1.addEntity('e3')
1256
- e3.addTypedProperty('number', 'i1')
1257
- e2.addTypedProperty('string', 's1')
1258
- const a1 = e1.addTargetAssociation(e2.key, 'a1')
1259
- a1.addTarget(e3.key)
1260
-
1261
- a1.schema = { unionType: 'allOf' }
1262
-
1263
- const result = e1.toExample(mime) as string
1264
- assert.typeOf(result, 'string', 'result is a string')
1265
-
1266
- // const dom = new JSDOM(result, { contentType: mime });
1267
- // const schema = dom.window.document;
1268
- // console.log(result);
1269
-
1270
- // assert.typeOf(data.a1, 'object', 'has the association property');
1271
- // assert.typeOf(data.a1.s1, 'string', 'has the association properties');
1272
- // assert.typeOf(data.a1.i1, 'number', 'has all association targets');
1273
- }).skip()
1274
-
1275
- test('returns the schema for oneOf union', ({ assert }) => {
1276
- const e3 = d1.addEntity('e3')
1277
-
1278
- e2.addTypedProperty('string', 's1')
1279
- e3.addTypedProperty('number', 'i1')
1280
-
1281
- const a1 = e1.addTargetAssociation(e2.key, 'a1')
1282
- a1.addTarget(e3.key)
1283
-
1284
- a1.schema = { unionType: 'oneOf' }
1285
-
1286
- const result = e1.toExample(mime) as string
1287
- assert.typeOf(result, 'string', 'result is a string')
1288
-
1289
- // const dom = new JSDOM(result, { contentType: mime });
1290
- // const schema = dom.window.document;
1291
- // console.log(result);
1292
-
1293
- // assert.typeOf(data.a1, 'object', 'has the association property');
1294
- // assert.typeOf(data.a1.s1, 'string', 'has the association properties');
1295
- // assert.isUndefined(data.a1.i1, 'has no other association target');
1296
- }).skip()
1297
-
1298
- test('returns the schema for oneOf union with selected shape', ({ assert }) => {
1299
- const e3 = d1.addEntity('e3')
1300
-
1301
- e2.addTypedProperty('string', 's1')
1302
- e3.addTypedProperty('number', 'i1')
1303
-
1304
- const a1 = e1.addTargetAssociation(e2.key, 'a1')
1305
- a1.addTarget(e3.key)
1306
-
1307
- a1.schema = { unionType: 'oneOf' }
1308
-
1309
- const result = e1.toExample(mime) as string
1310
- assert.typeOf(result, 'string', 'result is a string')
1311
-
1312
- // const dom = new JSDOM(result, { contentType: mime });
1313
- // const schema = dom.window.document;
1314
- // console.log(result);
1315
-
1316
- // assert.typeOf(data.a1, 'object', 'has the association property');
1317
- // assert.typeOf(data.a1.s1, 'string', 'has the association properties');
1318
- // assert.isUndefined(data.a1.i1, 'has no other association target');
1319
- }).skip()
1320
- })
1321
-
1322
- test.group('XML DataEntity Generator: parents', (group) => {
1323
- let d1: DataModel
1324
- let e1: DataEntity
1325
- let e2: DataEntity
1326
-
1327
- group.each.setup(() => {
1328
- const ns = new DataNamespace()
1329
- d1 = ns.addDataModel('d1')
1330
- e1 = d1.addEntity('e1')
1331
- e2 = d1.addEntity('e2')
1332
- })
1333
-
1334
- test('inherits parent properties', ({ assert }) => {
1335
- e1.addTypedProperty('number', 'p1')
1336
- e2.parents.push(e1.key)
1337
- const result = e2.toExample(mime) as string
1338
- assert.typeOf(result, 'string', 'result is a string')
1339
-
1340
- const dom = new JSDOM(result, { contentType: mime })
1341
- const schema = dom.window.document
1342
-
1343
- const outer = schema.querySelector('e2')!
1344
- const p1Element = outer.querySelector('p1')!
1345
-
1346
- assert.ok(p1Element, 'has the parent property')
1347
- })
1348
-
1349
- test('inherits parent properties and combines with own', ({ assert }) => {
1350
- e1.addTypedProperty('number', 'p1')
1351
- e2.addTypedProperty('string', 'p2')
1352
- e2.parents.push(e1.key)
1353
-
1354
- const result = e2.toExample(mime) as string
1355
- assert.typeOf(result, 'string', 'result is a string')
1356
-
1357
- const dom = new JSDOM(result, { contentType: mime })
1358
- const schema = dom.window.document
1359
-
1360
- const outer = schema.querySelector('e2')!
1361
- const p1Element = outer.querySelector('p1')!
1362
- const p2Element = outer.querySelector('p2')!
1363
-
1364
- assert.ok(p1Element, 'has the parent property')
1365
- assert.ok(p2Element, 'has own property')
1366
-
1367
- // assert.typeOf(data.p1, 'number', 'has the parent property');
1368
- // assert.typeOf(data.p2, 'string', 'has own property');
1369
- })
1370
-
1371
- test('inherits parent properties and combines with own association', ({ assert }) => {
1372
- e1.addTypedProperty('number', 'p1')
1373
- e2.addTypedProperty('string', 'p2')
1374
- e2.parents.push(e1.key)
1375
- const e3 = d1.addEntity('e3')
1376
- e3.addTypedProperty('string', 'p3')
1377
- e2.addTargetAssociation(e3.key, 'a1')
1378
-
1379
- const result = e2.toExample(mime) as string
1380
- assert.typeOf(result, 'string', 'result is a string')
1381
-
1382
- const dom = new JSDOM(result, { contentType: mime })
1383
- const schema = dom.window.document
1384
-
1385
- const outer = schema.querySelector('e2')!
1386
- const p1Element = outer.querySelector('p1')!
1387
- const p2Element = outer.querySelector('p2')!
1388
- const a1Element = outer.querySelector('a1')!
1389
-
1390
- assert.ok(p1Element, 'has the parent property')
1391
- assert.ok(p2Element, 'has own property')
1392
- assert.ok(a1Element, 'has own association')
1393
-
1394
- const p3Element = a1Element.querySelector('p3')
1395
- assert.ok(p3Element, 'has association property')
1396
-
1397
- // assert.typeOf(data.p1, 'number', 'has the parent property');
1398
- // assert.typeOf(data.p2, 'string', 'has own property');
1399
- // assert.typeOf(data.a1, 'object', 'has own association');
1400
- // assert.typeOf(data.a1.p3, 'string', 'has association property');
1401
- })
1402
-
1403
- test('inherits parent properties with parent association', ({ assert }) => {
1404
- e1.addTypedProperty('number', 'p1')
1405
- e2.addTypedProperty('string', 'p2')
1406
- e2.parents.push(e1.key)
1407
- const e3 = d1.addEntity('e3')
1408
- e3.addTypedProperty('string', 'p3')
1409
- e1.addTargetAssociation(e3.key, 'a1')
1410
-
1411
- const result = e2.toExample(mime) as string
1412
- assert.typeOf(result, 'string', 'result is a string')
1413
-
1414
- const dom = new JSDOM(result, { contentType: mime })
1415
- const schema = dom.window.document
1416
-
1417
- const outer = schema.querySelector('e2')!
1418
- const p1Element = outer.querySelector('p1')!
1419
- const p2Element = outer.querySelector('p2')!
1420
- const a1Element = outer.querySelector('a1')!
1421
-
1422
- assert.ok(p1Element, 'has the parent property')
1423
- assert.ok(p2Element, 'has own property')
1424
- assert.ok(a1Element, 'has own association')
1425
-
1426
- const p3Element = a1Element.querySelector('p3')
1427
- assert.ok(p3Element, 'has association property')
1428
-
1429
- // assert.typeOf(data.p1, 'number', 'has the parent property');
1430
- // assert.typeOf(data.p2, 'string', 'has own property');
1431
- // assert.typeOf(data.a1, 'object', 'has own association');
1432
- // assert.typeOf(data.a1.p3, 'string', 'has association property');
1433
- })
1434
-
1435
- test('shadows properties', ({ assert }) => {
1436
- e1.addTypedProperty('number', 'p1')
1437
- e2.addTypedProperty('string', 'p1')
1438
- e2.parents.push(e1.key)
1439
- const result = e2.toExample(mime) as string
1440
- assert.typeOf(result, 'string', 'result is a string')
1441
-
1442
- const dom = new JSDOM(result, { contentType: mime })
1443
- const schema = dom.window.document
1444
-
1445
- const outer = schema.querySelector('e2')!
1446
- const p1Element = outer.querySelector('p1')!
1447
- assert.ok(p1Element, 'has the parent property')
1448
- const value = Number(p1Element.textContent!.trim())
1449
- assert.isNaN(value)
1450
- })
1451
- })