@api-client/core 0.14.10 → 0.15.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.
- package/RELEASE.md +163 -0
- package/RELEASE_SETUP.md +235 -0
- package/build/src/events/authorization/AuthorizationEvents.d.ts +1 -1
- package/build/src/events/authorization/AuthorizationEvents.d.ts.map +1 -1
- package/build/src/events/authorization/AuthorizationEvents.js +1 -1
- package/build/src/events/authorization/AuthorizationEvents.js.map +1 -1
- package/build/src/events/cookies/CookieEvents.d.ts +1 -1
- package/build/src/events/cookies/CookieEvents.d.ts.map +1 -1
- package/build/src/events/cookies/CookieEvents.js +1 -1
- package/build/src/events/cookies/CookieEvents.js.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.d.ts +22 -119
- package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.js +49 -155
- package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
- package/build/src/modeling/DomainValidation.d.ts +8 -0
- package/build/src/modeling/DomainValidation.d.ts.map +1 -0
- package/build/src/modeling/DomainValidation.js +99 -0
- package/build/src/modeling/DomainValidation.js.map +1 -0
- package/build/src/modeling/types.d.ts +70 -0
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/modeling/validation/rules.d.ts +2 -3
- package/build/src/modeling/validation/rules.d.ts.map +1 -1
- package/build/src/modeling/validation/rules.js.map +1 -1
- package/build/src/modeling/validation/semantic_validation.d.ts +31 -0
- package/build/src/modeling/validation/semantic_validation.d.ts.map +1 -0
- package/build/src/modeling/validation/semantic_validation.js +126 -0
- package/build/src/modeling/validation/semantic_validation.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/noop.ts +3 -0
- package/package.json +9 -4
- package/src/events/authorization/AuthorizationEvents.ts +1 -1
- package/src/events/cookies/CookieEvents.ts +1 -1
- package/src/modeling/DomainImpactAnalysis.ts +54 -239
- package/src/modeling/DomainValidation.ts +105 -0
- package/src/modeling/types.ts +86 -0
- package/src/modeling/validation/rules.ts +2 -4
- package/src/modeling/validation/semantic_validation.ts +145 -0
- package/tests/unit/events/EventsTestHelpers.ts +16 -0
- package/tests/unit/events/amf.spec.ts +151 -0
- package/tests/unit/events/authorization.spec.ts +150 -0
- package/tests/unit/events/cookie.spec.ts +274 -0
- package/tests/unit/events/encryption.spec.ts +108 -0
- package/tests/unit/events/events_polyfills.ts +77 -0
- package/tests/unit/events/process.spec.ts +120 -0
- package/tests/unit/events/reporting.spec.ts +82 -0
- package/tests/unit/events/telemetry.spec.ts +224 -0
- package/tests/unit/events/transport.spec.ts +139 -0
- package/tests/unit/modeling/domain_impact_analysis.spec.ts +0 -110
- package/tests/unit/modeling/domain_validation.spec.ts +94 -0
- package/tests/unit/modeling/validation/semantic_validation.spec.ts +91 -0
- package/tests/unit/models/environment.spec.ts +574 -0
- package/tests/unit/models/error_response.spec.ts +183 -0
- package/tests/unit/models/headers_array.spec.ts +86 -0
- package/tests/unit/models/http-actions/assertion/equal_assertion.spec.ts +103 -0
- package/tests/unit/models/http-actions/assertion/greater_than_assertion.spec.ts +91 -0
- package/tests/unit/models/http-actions/assertion/includes_assertion.spec.ts +71 -0
- package/tests/unit/models/http-actions/assertion/less_than_assertion.spec.ts +91 -0
- package/tests/unit/models/http-actions/assertion/matches_assertion.spec.ts +71 -0
- package/tests/unit/models/http-actions/assertion/matches_schema_assertion.spec.ts +117 -0
- package/tests/unit/models/http-actions/assertion/not_equal_assertion.spec.ts +103 -0
- package/tests/unit/models/http-actions/assertion/not_includes_assertion.spec.ts +71 -0
- package/tests/unit/models/http-actions/assertion/not_ok_assertion.spec.ts +47 -0
- package/tests/unit/models/http-actions/assertion/not_to_be_assertion.spec.ts +72 -0
- package/tests/unit/models/http-actions/assertion/ok_assertion.spec.ts +44 -0
- package/tests/unit/models/http-actions/assertion/to_be_assertion.spec.ts +71 -0
- package/tests/unit/models/http-actions/transformation/as_lower_case_step.spec.ts +47 -0
- package/tests/unit/models/http-actions/transformation/as_number_step.spec.ts +47 -0
- package/tests/unit/models/http-actions/transformation/as_upper_case_step.spec.ts +47 -0
- package/tests/unit/models/http-actions/transformation/round_step.spec.ts +69 -0
- package/tests/unit/models/http-actions/transformation/substring_step.spec.ts +85 -0
- package/tests/unit/models/http-actions/transformation/trim_step.spec.ts +44 -0
- package/tests/unit/models/http_cookie.spec.ts +516 -0
- package/tests/unit/models/http_history.spec.ts +443 -0
- package/tests/unit/models/project_folder.spec.ts +926 -0
- package/tests/unit/models/project_item.spec.ts +137 -0
- package/tests/unit/models/project_request.spec.ts +1047 -0
- package/tests/unit/models/project_schema.spec.ts +236 -0
- package/tests/unit/models/property.spec.ts +625 -0
- package/tests/unit/models/provider.spec.ts +102 -0
- package/tests/unit/models/request.spec.ts +1206 -0
- package/tests/unit/models/request_log.spec.ts +308 -0
- package/tests/unit/models/request_time.spec.ts +138 -0
- package/tests/unit/models/response_redirect.spec.ts +303 -0
- package/tests/unit/models/sent_request.spec.ts +206 -0
- package/tests/unit/models/server.spec.ts +195 -0
- package/tests/unit/models/thing.spec.ts +154 -0
- package/build/oauth-popup.html +0 -33
- /package/tests/unit/models/{Certificate.spec.ts → certificate.spec.ts} +0 -0
- /package/tests/unit/models/{HostRule.spec.ts → host_rule.spec.ts} +0 -0
- /package/tests/unit/models/{HttpProject.spec.ts → http_project.spec.ts} +0 -0
- /package/tests/unit/models/{HttpRequest.spec.ts → http_request.spec.ts} +0 -0
- /package/tests/unit/models/{HttpResponse.spec.ts → http_response.spec.ts} +0 -0
- /package/tests/unit/models/{License.spec.ts → license.spec.ts} +0 -0
- /package/tests/unit/models/{Response.spec.ts → response.spec.ts} +0 -0
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { Property, IProperty, Kind as PropertyKind, PropertyType } from '../../../src/models/Property.js'
|
|
3
|
+
|
|
4
|
+
test.group('Models > Property > Property.fromType()', () => {
|
|
5
|
+
test('creates a type from a boolean value', ({ assert }) => {
|
|
6
|
+
const result = Property.fromType('a', false)
|
|
7
|
+
assert.equal(result.name, 'a')
|
|
8
|
+
assert.equal(result.value, false)
|
|
9
|
+
assert.equal(result.type, 'boolean')
|
|
10
|
+
assert.equal(result.enabled, true)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('creates a type from a boolean value with the enabled flag', ({ assert }) => {
|
|
14
|
+
const result = Property.fromType('a', false, false)
|
|
15
|
+
assert.equal(result.name, 'a')
|
|
16
|
+
assert.equal(result.type, 'boolean')
|
|
17
|
+
assert.equal(result.enabled, false)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('creates a type from an integer value', ({ assert }) => {
|
|
21
|
+
const result = Property.fromType('a', 1)
|
|
22
|
+
assert.equal(result.name, 'a')
|
|
23
|
+
assert.equal(result.value, 1)
|
|
24
|
+
assert.equal(result.type, 'integer')
|
|
25
|
+
assert.equal(result.enabled, true)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('creates a type from an integer value with the enabled flag', ({ assert }) => {
|
|
29
|
+
const result = Property.fromType('a', 2, false)
|
|
30
|
+
assert.equal(result.name, 'a')
|
|
31
|
+
assert.equal(result.value, 2)
|
|
32
|
+
assert.equal(result.type, 'integer')
|
|
33
|
+
assert.equal(result.enabled, false)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('creates a type from a string value', ({ assert }) => {
|
|
37
|
+
const result = Property.fromType('a', 'b')
|
|
38
|
+
assert.equal(result.name, 'a')
|
|
39
|
+
assert.equal(result.value, 'b')
|
|
40
|
+
assert.equal(result.type, 'string')
|
|
41
|
+
assert.equal(result.enabled, true)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('creates a type from a string value with the enabled flag', ({ assert }) => {
|
|
45
|
+
const result = Property.fromType('a', 'b', false)
|
|
46
|
+
assert.equal(result.name, 'a')
|
|
47
|
+
assert.equal(result.value, 'b')
|
|
48
|
+
assert.equal(result.type, 'string')
|
|
49
|
+
assert.equal(result.enabled, false)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test.group('Models > Property > Property.String()', () => {
|
|
54
|
+
test('creates a string property with defaults', ({ assert }) => {
|
|
55
|
+
const result = Property.String('a')
|
|
56
|
+
assert.equal(result.kind, PropertyKind)
|
|
57
|
+
assert.equal(result.name, 'a')
|
|
58
|
+
assert.equal(result.value, '')
|
|
59
|
+
assert.equal(result.enabled, true)
|
|
60
|
+
assert.equal(result.type, 'string')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('creates a string property with a value', ({ assert }) => {
|
|
64
|
+
const result = Property.String('a', 'b')
|
|
65
|
+
assert.equal(result.value, 'b')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('creates a string property with the enabled flag', ({ assert }) => {
|
|
69
|
+
const result = Property.String('a', 'b', false)
|
|
70
|
+
assert.equal(result.enabled, false)
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test.group('Models > Property > Property.Integer()', () => {
|
|
75
|
+
test('creates an integer property with defaults', ({ assert }) => {
|
|
76
|
+
const result = Property.Integer('a')
|
|
77
|
+
assert.equal(result.kind, PropertyKind)
|
|
78
|
+
assert.equal(result.name, 'a')
|
|
79
|
+
assert.equal(result.value, 0)
|
|
80
|
+
assert.equal(result.enabled, true)
|
|
81
|
+
assert.equal(result.type, 'integer')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('creates an integer property with a value', ({ assert }) => {
|
|
85
|
+
const result = Property.Integer('a', 1)
|
|
86
|
+
assert.equal(result.value, 1)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('creates an integer property with the enabled flag', ({ assert }) => {
|
|
90
|
+
const result = Property.Integer('a', 1, false)
|
|
91
|
+
assert.equal(result.enabled, false)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test.group('Models > Property > Property.Int32()', () => {
|
|
96
|
+
test('creates an int32 property with defaults', ({ assert }) => {
|
|
97
|
+
const result = Property.Int32('a')
|
|
98
|
+
assert.equal(result.kind, PropertyKind)
|
|
99
|
+
assert.equal(result.name, 'a')
|
|
100
|
+
assert.equal(result.value, 0)
|
|
101
|
+
assert.equal(result.enabled, true)
|
|
102
|
+
assert.equal(result.type, 'int32')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('creates an int32 property with a value', ({ assert }) => {
|
|
106
|
+
const result = Property.Int32('a', 1)
|
|
107
|
+
assert.equal(result.value, 1)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('creates an int32 property with the enabled flag', ({ assert }) => {
|
|
111
|
+
const result = Property.Int32('a', 1, false)
|
|
112
|
+
assert.equal(result.enabled, false)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test.group('Models > Property > Property.Int64()', () => {
|
|
117
|
+
test('creates an int64 property with defaults', ({ assert }) => {
|
|
118
|
+
const result = Property.Int64('a')
|
|
119
|
+
assert.equal(result.kind, PropertyKind)
|
|
120
|
+
assert.equal(result.name, 'a')
|
|
121
|
+
assert.equal(result.value, 0)
|
|
122
|
+
assert.equal(result.enabled, true)
|
|
123
|
+
assert.equal(result.type, 'int64')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('creates an int64 property with a value', ({ assert }) => {
|
|
127
|
+
const result = Property.Int64('a', 1)
|
|
128
|
+
assert.equal(result.value, 1)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('creates an int64 property with the enabled flag', ({ assert }) => {
|
|
132
|
+
const result = Property.Int64('a', 1, false)
|
|
133
|
+
assert.equal(result.enabled, false)
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test.group('Models > Property > Property.Uint32()', () => {
|
|
138
|
+
test('creates an uint32 property with defaults', ({ assert }) => {
|
|
139
|
+
const result = Property.Uint32('a')
|
|
140
|
+
assert.equal(result.kind, PropertyKind)
|
|
141
|
+
assert.equal(result.name, 'a')
|
|
142
|
+
assert.equal(result.value, 0)
|
|
143
|
+
assert.equal(result.enabled, true)
|
|
144
|
+
assert.equal(result.type, 'uint32')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('creates an uint32 property with a value', ({ assert }) => {
|
|
148
|
+
const result = Property.Uint32('a', 1)
|
|
149
|
+
assert.equal(result.value, 1)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('creates an uint32 property with the enabled flag', ({ assert }) => {
|
|
153
|
+
const result = Property.Uint32('a', 1, false)
|
|
154
|
+
assert.equal(result.enabled, false)
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test.group('Models > Property > Property.Uint64()', () => {
|
|
159
|
+
test('creates an uint64 property with defaults', ({ assert }) => {
|
|
160
|
+
const result = Property.Uint64('a')
|
|
161
|
+
assert.equal(result.kind, PropertyKind)
|
|
162
|
+
assert.equal(result.name, 'a')
|
|
163
|
+
assert.equal(result.value, 0)
|
|
164
|
+
assert.equal(result.enabled, true)
|
|
165
|
+
assert.equal(result.type, 'uint64')
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test('creates an uint64 property with a value', ({ assert }) => {
|
|
169
|
+
const result = Property.Uint64('a', 1)
|
|
170
|
+
assert.equal(result.value, 1)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test('creates an uint64 property with the enabled flag', ({ assert }) => {
|
|
174
|
+
const result = Property.Uint64('a', 1, false)
|
|
175
|
+
assert.equal(result.enabled, false)
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test.group('Models > Property > Property.Sint32()', () => {
|
|
180
|
+
test('creates an sint32 property with defaults', ({ assert }) => {
|
|
181
|
+
const result = Property.Sint32('a')
|
|
182
|
+
assert.equal(result.kind, PropertyKind)
|
|
183
|
+
assert.equal(result.name, 'a')
|
|
184
|
+
assert.equal(result.value, 0)
|
|
185
|
+
assert.equal(result.enabled, true)
|
|
186
|
+
assert.equal(result.type, 'sint32')
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('creates an sint32 property with a value', ({ assert }) => {
|
|
190
|
+
const result = Property.Sint32('a', 1)
|
|
191
|
+
assert.equal(result.value, 1)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('creates an sint32 property with the enabled flag', ({ assert }) => {
|
|
195
|
+
const result = Property.Sint32('a', 1, false)
|
|
196
|
+
assert.equal(result.enabled, false)
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
test.group('Models > Property > Property.Sint64()', () => {
|
|
201
|
+
test('creates an sint64 property with defaults', ({ assert }) => {
|
|
202
|
+
const result = Property.Sint64('a')
|
|
203
|
+
assert.equal(result.kind, PropertyKind)
|
|
204
|
+
assert.equal(result.name, 'a')
|
|
205
|
+
assert.equal(result.value, 0)
|
|
206
|
+
assert.equal(result.enabled, true)
|
|
207
|
+
assert.equal(result.type, 'sint64')
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
test('creates an sint64 property with a value', ({ assert }) => {
|
|
211
|
+
const result = Property.Sint64('a', 1)
|
|
212
|
+
assert.equal(result.value, 1)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test('creates an sint64 property with the enabled flag', ({ assert }) => {
|
|
216
|
+
const result = Property.Sint64('a', 1, false)
|
|
217
|
+
assert.equal(result.enabled, false)
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
test.group('Models > Property > Property.Fixed32()', () => {
|
|
222
|
+
test('creates an fixed32 property with defaults', ({ assert }) => {
|
|
223
|
+
const result = Property.Fixed32('a')
|
|
224
|
+
assert.equal(result.kind, PropertyKind)
|
|
225
|
+
assert.equal(result.name, 'a')
|
|
226
|
+
assert.equal(result.value, 0)
|
|
227
|
+
assert.equal(result.enabled, true)
|
|
228
|
+
assert.equal(result.type, 'fixed32')
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('creates an fixed32 property with a value', ({ assert }) => {
|
|
232
|
+
const result = Property.Fixed32('a', 1)
|
|
233
|
+
assert.equal(result.value, 1)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('creates an fixed32 property with the enabled flag', ({ assert }) => {
|
|
237
|
+
const result = Property.Fixed32('a', 1, false)
|
|
238
|
+
assert.equal(result.enabled, false)
|
|
239
|
+
})
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test.group('Models > Property > Property.Fixed64()', () => {
|
|
243
|
+
test('creates an fixed64 property with defaults', ({ assert }) => {
|
|
244
|
+
const result = Property.Fixed64('a')
|
|
245
|
+
assert.equal(result.kind, PropertyKind)
|
|
246
|
+
assert.equal(result.name, 'a')
|
|
247
|
+
assert.equal(result.value, 0)
|
|
248
|
+
assert.equal(result.enabled, true)
|
|
249
|
+
assert.equal(result.type, 'fixed64')
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
test('creates an fixed64 property with a value', ({ assert }) => {
|
|
253
|
+
const result = Property.Fixed64('a', 1)
|
|
254
|
+
assert.equal(result.value, 1)
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
test('creates an fixed64 property with the enabled flag', ({ assert }) => {
|
|
258
|
+
const result = Property.Fixed64('a', 1, false)
|
|
259
|
+
assert.equal(result.enabled, false)
|
|
260
|
+
})
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
test.group('Models > Property > Property.Sfixed32()', () => {
|
|
264
|
+
test('creates an sfixed32 property with defaults', ({ assert }) => {
|
|
265
|
+
const result = Property.Sfixed32('a')
|
|
266
|
+
assert.equal(result.kind, PropertyKind)
|
|
267
|
+
assert.equal(result.name, 'a')
|
|
268
|
+
assert.equal(result.value, 0)
|
|
269
|
+
assert.equal(result.enabled, true)
|
|
270
|
+
assert.equal(result.type, 'sfixed32')
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
test('creates an sfixed32 property with a value', ({ assert }) => {
|
|
274
|
+
const result = Property.Sfixed32('a', 1)
|
|
275
|
+
assert.equal(result.value, 1)
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
test('creates an sfixed32 property with the enabled flag', ({ assert }) => {
|
|
279
|
+
const result = Property.Sfixed32('a', 1, false)
|
|
280
|
+
assert.equal(result.enabled, false)
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
test.group('Models > Property > Property.Sfixed64()', () => {
|
|
285
|
+
test('creates an sfixed64 property with defaults', ({ assert }) => {
|
|
286
|
+
const result = Property.Sfixed64('a')
|
|
287
|
+
assert.equal(result.kind, PropertyKind)
|
|
288
|
+
assert.equal(result.name, 'a')
|
|
289
|
+
assert.equal(result.value, 0)
|
|
290
|
+
assert.equal(result.enabled, true)
|
|
291
|
+
assert.equal(result.type, 'sfixed64')
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
test('creates an sfixed64 property with a value', ({ assert }) => {
|
|
295
|
+
const result = Property.Sfixed64('a', 1)
|
|
296
|
+
assert.equal(result.value, 1)
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
test('creates an sfixed64 property with the enabled flag', ({ assert }) => {
|
|
300
|
+
const result = Property.Sfixed64('a', 1, false)
|
|
301
|
+
assert.equal(result.enabled, false)
|
|
302
|
+
})
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
test.group('Models > Property > Property.Float()', () => {
|
|
306
|
+
test('creates a float property with defaults', ({ assert }) => {
|
|
307
|
+
const result = Property.Float('a')
|
|
308
|
+
assert.equal(result.kind, PropertyKind)
|
|
309
|
+
assert.equal(result.name, 'a')
|
|
310
|
+
assert.equal(result.value, 0.0)
|
|
311
|
+
assert.equal(result.enabled, true)
|
|
312
|
+
assert.equal(result.type, 'float')
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test('creates a float property with a value', ({ assert }) => {
|
|
316
|
+
const result = Property.Float('a', 1.3)
|
|
317
|
+
assert.equal(result.value, 1.3)
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
test('creates a float property with the enabled flag', ({ assert }) => {
|
|
321
|
+
const result = Property.Float('a', 1.3, false)
|
|
322
|
+
assert.equal(result.enabled, false)
|
|
323
|
+
})
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
test.group('Models > Property > Property.Boolean()', () => {
|
|
327
|
+
test('creates a boolean property with defaults', ({ assert }) => {
|
|
328
|
+
const result = Property.Boolean('a')
|
|
329
|
+
assert.equal(result.kind, PropertyKind)
|
|
330
|
+
assert.equal(result.name, 'a')
|
|
331
|
+
assert.equal(result.value, false)
|
|
332
|
+
assert.equal(result.enabled, true)
|
|
333
|
+
assert.equal(result.type, 'boolean')
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
test('creates a boolean property with a value', ({ assert }) => {
|
|
337
|
+
const result = Property.Boolean('a', false)
|
|
338
|
+
assert.equal(result.value, false)
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
test('creates a boolean property with the enabled flag', ({ assert }) => {
|
|
342
|
+
const result = Property.Boolean('a', true, false)
|
|
343
|
+
assert.equal(result.enabled, false)
|
|
344
|
+
})
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
test.group('Models > Property > Property.Date()', () => {
|
|
348
|
+
test('creates a date property with defaults', ({ assert }) => {
|
|
349
|
+
const result = Property.Date('a')
|
|
350
|
+
assert.equal(result.kind, PropertyKind)
|
|
351
|
+
assert.equal(result.name, 'a')
|
|
352
|
+
assert.equal(result.value, '')
|
|
353
|
+
assert.equal(result.enabled, true)
|
|
354
|
+
assert.equal(result.type, 'date')
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
test.group('Models > Property > Property.Datetime()', () => {
|
|
359
|
+
test('creates a datetime property with defaults', ({ assert }) => {
|
|
360
|
+
const result = Property.Datetime('a')
|
|
361
|
+
assert.equal(result.kind, PropertyKind)
|
|
362
|
+
assert.equal(result.name, 'a')
|
|
363
|
+
assert.equal(result.value, '')
|
|
364
|
+
assert.equal(result.enabled, true)
|
|
365
|
+
assert.equal(result.type, 'datetime')
|
|
366
|
+
})
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
test.group('Models > Property > Property.Time()', () => {
|
|
370
|
+
test('creates a time property with defaults', ({ assert }) => {
|
|
371
|
+
const result = Property.Time('a')
|
|
372
|
+
assert.equal(result.kind, PropertyKind)
|
|
373
|
+
assert.equal(result.name, 'a')
|
|
374
|
+
assert.equal(result.value, '')
|
|
375
|
+
assert.equal(result.enabled, true)
|
|
376
|
+
assert.equal(result.type, 'time')
|
|
377
|
+
})
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
test.group('Models > Property > Property.Bytes()', () => {
|
|
381
|
+
test('creates a bytes property with defaults', ({ assert }) => {
|
|
382
|
+
const result = Property.Bytes('a')
|
|
383
|
+
assert.equal(result.kind, PropertyKind)
|
|
384
|
+
assert.equal(result.name, 'a')
|
|
385
|
+
assert.equal(result.value, '')
|
|
386
|
+
assert.equal(result.enabled, true)
|
|
387
|
+
assert.equal(result.type, 'bytes')
|
|
388
|
+
})
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
test.group('Models > Property > Property.fromTypeDefault()', () => {
|
|
392
|
+
const types = [
|
|
393
|
+
{ type: 'string', value: '' },
|
|
394
|
+
{ type: 'boolean', value: false },
|
|
395
|
+
{ type: 'date', value: '' },
|
|
396
|
+
{ type: 'datetime', value: '' },
|
|
397
|
+
{ type: 'time', value: '' },
|
|
398
|
+
{ type: 'float', value: 0.0 },
|
|
399
|
+
{ type: 'double', value: 0.0 },
|
|
400
|
+
{ type: 'integer', value: 0 },
|
|
401
|
+
{ type: 'int32', value: 0 },
|
|
402
|
+
{ type: 'int64', value: 0 },
|
|
403
|
+
{ type: 'uint32', value: 0 },
|
|
404
|
+
{ type: 'uint64', value: 0 },
|
|
405
|
+
{ type: 'sint32', value: 0 },
|
|
406
|
+
{ type: 'sint64', value: 0 },
|
|
407
|
+
{ type: 'fixed32', value: 0 },
|
|
408
|
+
{ type: 'fixed64', value: 0 },
|
|
409
|
+
{ type: 'sfixed32', value: 0 },
|
|
410
|
+
{ type: 'sfixed64', value: 0 },
|
|
411
|
+
{ type: 'bytes', value: '' },
|
|
412
|
+
]
|
|
413
|
+
|
|
414
|
+
types.forEach(({ type, value }) => {
|
|
415
|
+
test(`creates a ${type} property`, ({ assert }) => {
|
|
416
|
+
const result = Property.fromTypeDefault('a', type as PropertyType)
|
|
417
|
+
assert.equal(result.kind, PropertyKind)
|
|
418
|
+
assert.equal(result.name, 'a')
|
|
419
|
+
assert.equal(result.value, value)
|
|
420
|
+
assert.equal(result.enabled, true)
|
|
421
|
+
assert.equal(result.type, type)
|
|
422
|
+
})
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
test('throws for an unknown type', ({ assert }) => {
|
|
426
|
+
assert.throws(() => {
|
|
427
|
+
// @ts-expect-error Used in testing
|
|
428
|
+
Property.fromTypeDefault('a', 'unknown')
|
|
429
|
+
})
|
|
430
|
+
})
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
test.group('Models > Property > constructor()', () => {
|
|
434
|
+
test('creates a default instance', ({ assert }) => {
|
|
435
|
+
const result = new Property()
|
|
436
|
+
assert.equal(result.kind, PropertyKind)
|
|
437
|
+
assert.equal(result.name, '')
|
|
438
|
+
assert.equal(result.value, '')
|
|
439
|
+
assert.equal(result.type, 'string')
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
test('creates an instance from schema', ({ assert }) => {
|
|
443
|
+
const init: IProperty = {
|
|
444
|
+
kind: PropertyKind,
|
|
445
|
+
name: 'a',
|
|
446
|
+
type: 'string',
|
|
447
|
+
value: '',
|
|
448
|
+
}
|
|
449
|
+
const result = new Property(init)
|
|
450
|
+
assert.equal(result.kind, PropertyKind)
|
|
451
|
+
assert.equal(result.name, 'a')
|
|
452
|
+
assert.equal(result.type, 'string')
|
|
453
|
+
assert.equal(result.value, '')
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
test('creates an instance from JSON schema', ({ assert }) => {
|
|
457
|
+
const init: IProperty = {
|
|
458
|
+
kind: PropertyKind,
|
|
459
|
+
name: 'a',
|
|
460
|
+
type: 'string',
|
|
461
|
+
value: '',
|
|
462
|
+
}
|
|
463
|
+
const result = new Property(JSON.stringify(init))
|
|
464
|
+
assert.equal(result.kind, PropertyKind)
|
|
465
|
+
assert.equal(result.name, 'a')
|
|
466
|
+
assert.equal(result.type, 'string')
|
|
467
|
+
assert.equal(result.value, '')
|
|
468
|
+
})
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
test.group('Models > Property > new()', (group) => {
|
|
472
|
+
let property: Property
|
|
473
|
+
group.each.setup(() => {
|
|
474
|
+
property = Property.String('test-name', 'test-value', false)
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
test('throws when not an IProperty', ({ assert }) => {
|
|
478
|
+
assert.throws(() => {
|
|
479
|
+
// @ts-expect-error Used in testing
|
|
480
|
+
property.new({})
|
|
481
|
+
})
|
|
482
|
+
})
|
|
483
|
+
|
|
484
|
+
const stringProps: (keyof IProperty)[] = ['name', 'value', 'description', 'default']
|
|
485
|
+
stringProps.forEach((prop) => {
|
|
486
|
+
test(`sets the ${prop}`, ({ assert }) => {
|
|
487
|
+
const schema = property.toJSON()
|
|
488
|
+
// @ts-expect-error Used in testing
|
|
489
|
+
schema[prop] = 'updated'
|
|
490
|
+
property.new(schema)
|
|
491
|
+
assert.equal(property[prop], 'updated')
|
|
492
|
+
})
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
const booleanProps: (keyof IProperty)[] = ['enabled', 'required', 'repeated']
|
|
496
|
+
booleanProps.forEach((prop) => {
|
|
497
|
+
test(`sets the ${prop}`, ({ assert }) => {
|
|
498
|
+
const schema = property.toJSON()
|
|
499
|
+
// @ts-expect-error Used in testing
|
|
500
|
+
schema[prop] = true
|
|
501
|
+
property.new(schema)
|
|
502
|
+
assert.equal(property[prop], true)
|
|
503
|
+
})
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
test('sets the enum', ({ assert }) => {
|
|
507
|
+
const schema = property.toJSON()
|
|
508
|
+
schema.enum = ['updated']
|
|
509
|
+
property.new(schema)
|
|
510
|
+
assert.deepEqual(property.enum, ['updated'])
|
|
511
|
+
})
|
|
512
|
+
})
|
|
513
|
+
|
|
514
|
+
test.group('Models > Property > Property.isProperty()', () => {
|
|
515
|
+
test('returns false when no input', ({ assert }) => {
|
|
516
|
+
const result = Property.isProperty(undefined)
|
|
517
|
+
assert.isFalse(result)
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
test('returns false when no name', ({ assert }) => {
|
|
521
|
+
const schema = Property.String('test').toJSON()
|
|
522
|
+
// @ts-expect-error Used in testing
|
|
523
|
+
delete schema.name
|
|
524
|
+
const result = Property.isProperty(schema)
|
|
525
|
+
assert.isFalse(result)
|
|
526
|
+
})
|
|
527
|
+
|
|
528
|
+
test('returns false when no type', ({ assert }) => {
|
|
529
|
+
const schema = Property.String('test').toJSON()
|
|
530
|
+
// @ts-expect-error Used in testing
|
|
531
|
+
delete schema.type
|
|
532
|
+
const result = Property.isProperty(schema)
|
|
533
|
+
assert.isFalse(result)
|
|
534
|
+
})
|
|
535
|
+
|
|
536
|
+
test('returns false when invalid kind', ({ assert }) => {
|
|
537
|
+
const schema = Property.String('test').toJSON()
|
|
538
|
+
// @ts-expect-error Used in testing
|
|
539
|
+
schema.kind = 'test'
|
|
540
|
+
const result = Property.isProperty(schema)
|
|
541
|
+
assert.isFalse(result)
|
|
542
|
+
})
|
|
543
|
+
|
|
544
|
+
test('returns false when unknown type', ({ assert }) => {
|
|
545
|
+
const schema = Property.String('test').toJSON()
|
|
546
|
+
// @ts-expect-error Used in testing
|
|
547
|
+
schema.type = 'test'
|
|
548
|
+
const result = Property.isProperty(schema)
|
|
549
|
+
assert.isFalse(result)
|
|
550
|
+
})
|
|
551
|
+
|
|
552
|
+
test('returns true when a valid property', ({ assert }) => {
|
|
553
|
+
const schema = Property.String('test').toJSON()
|
|
554
|
+
const result = Property.isProperty(schema)
|
|
555
|
+
assert.isTrue(result)
|
|
556
|
+
})
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
test.group('Models > Property > toJSON()', (group) => {
|
|
560
|
+
let instance: Property
|
|
561
|
+
group.each.setup(() => {
|
|
562
|
+
instance = new Property()
|
|
563
|
+
})
|
|
564
|
+
|
|
565
|
+
test('sets the kind', ({ assert }) => {
|
|
566
|
+
const result = Property.String().toJSON()
|
|
567
|
+
assert.equal(result.kind, PropertyKind)
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
test('sets the name', ({ assert }) => {
|
|
571
|
+
const result = Property.String('test').toJSON()
|
|
572
|
+
assert.equal(result.name, 'test')
|
|
573
|
+
})
|
|
574
|
+
|
|
575
|
+
test('sets the value', ({ assert }) => {
|
|
576
|
+
const result = Property.String('', 'test').toJSON()
|
|
577
|
+
assert.equal(result.value, 'test')
|
|
578
|
+
})
|
|
579
|
+
|
|
580
|
+
test('sets the type', ({ assert }) => {
|
|
581
|
+
const result = Property.String().toJSON()
|
|
582
|
+
assert.equal(result.type, 'string')
|
|
583
|
+
})
|
|
584
|
+
|
|
585
|
+
const optionalStringProps: (keyof IProperty)[] = ['description', 'default']
|
|
586
|
+
optionalStringProps.forEach((prop) => {
|
|
587
|
+
test(`does not set the ${prop} when missing`, ({ assert }) => {
|
|
588
|
+
const result = instance.toJSON()
|
|
589
|
+
assert.isUndefined(result[prop])
|
|
590
|
+
})
|
|
591
|
+
|
|
592
|
+
test(`sets the ${prop}`, ({ assert }) => {
|
|
593
|
+
// @ts-expect-error Used in testing
|
|
594
|
+
instance[prop] = 'test'
|
|
595
|
+
const result = instance.toJSON()
|
|
596
|
+
assert.equal(result[prop], 'test')
|
|
597
|
+
})
|
|
598
|
+
})
|
|
599
|
+
|
|
600
|
+
test('does not set the enum when missing', ({ assert }) => {
|
|
601
|
+
const result = instance.toJSON()
|
|
602
|
+
assert.isUndefined(result.enum)
|
|
603
|
+
})
|
|
604
|
+
|
|
605
|
+
test('sets the enum', ({ assert }) => {
|
|
606
|
+
instance.enum = ['test']
|
|
607
|
+
const result = instance.toJSON()
|
|
608
|
+
assert.deepEqual(result.enum, ['test'])
|
|
609
|
+
})
|
|
610
|
+
|
|
611
|
+
const optionalBooleanProps: (keyof IProperty)[] = ['enabled', 'required', 'repeated']
|
|
612
|
+
optionalBooleanProps.forEach((prop) => {
|
|
613
|
+
test(`does not set the ${prop} when missing`, ({ assert }) => {
|
|
614
|
+
const result = instance.toJSON()
|
|
615
|
+
assert.isUndefined(result[prop])
|
|
616
|
+
})
|
|
617
|
+
|
|
618
|
+
test(`sets the ${prop}`, ({ assert }) => {
|
|
619
|
+
// @ts-expect-error Used in testing
|
|
620
|
+
instance[prop] = true
|
|
621
|
+
const result = instance.toJSON()
|
|
622
|
+
assert.isTrue(result[prop])
|
|
623
|
+
})
|
|
624
|
+
})
|
|
625
|
+
})
|