@api-client/core 0.14.9 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/RELEASE.md +163 -0
  2. package/RELEASE_SETUP.md +235 -0
  3. package/build/src/events/authorization/AuthorizationEvents.d.ts +1 -1
  4. package/build/src/events/authorization/AuthorizationEvents.d.ts.map +1 -1
  5. package/build/src/events/authorization/AuthorizationEvents.js +1 -1
  6. package/build/src/events/authorization/AuthorizationEvents.js.map +1 -1
  7. package/build/src/events/cookies/CookieEvents.d.ts +1 -1
  8. package/build/src/events/cookies/CookieEvents.d.ts.map +1 -1
  9. package/build/src/events/cookies/CookieEvents.js +1 -1
  10. package/build/src/events/cookies/CookieEvents.js.map +1 -1
  11. package/build/src/modeling/DataDomain.d.ts +45 -3
  12. package/build/src/modeling/DataDomain.d.ts.map +1 -1
  13. package/build/src/modeling/DataDomain.js +81 -3
  14. package/build/src/modeling/DataDomain.js.map +1 -1
  15. package/build/src/modeling/DomainElement.d.ts +7 -0
  16. package/build/src/modeling/DomainElement.d.ts.map +1 -1
  17. package/build/src/modeling/DomainElement.js +14 -0
  18. package/build/src/modeling/DomainElement.js.map +1 -1
  19. package/build/src/modeling/DomainImpactAnalysis.d.ts +22 -119
  20. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  21. package/build/src/modeling/DomainImpactAnalysis.js +49 -155
  22. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  23. package/build/src/modeling/DomainValidation.d.ts +8 -0
  24. package/build/src/modeling/DomainValidation.d.ts.map +1 -0
  25. package/build/src/modeling/DomainValidation.js +99 -0
  26. package/build/src/modeling/DomainValidation.js.map +1 -0
  27. package/build/src/modeling/types.d.ts +70 -0
  28. package/build/src/modeling/types.d.ts.map +1 -1
  29. package/build/src/modeling/types.js.map +1 -1
  30. package/build/src/modeling/validation/entity_validation.js +1 -1
  31. package/build/src/modeling/validation/entity_validation.js.map +1 -1
  32. package/build/src/modeling/validation/rules.d.ts +2 -3
  33. package/build/src/modeling/validation/rules.d.ts.map +1 -1
  34. package/build/src/modeling/validation/rules.js.map +1 -1
  35. package/build/src/modeling/validation/semantic_validation.d.ts +31 -0
  36. package/build/src/modeling/validation/semantic_validation.d.ts.map +1 -0
  37. package/build/src/modeling/validation/semantic_validation.js +126 -0
  38. package/build/src/modeling/validation/semantic_validation.js.map +1 -0
  39. package/build/tsconfig.tsbuildinfo +1 -1
  40. package/data/models/example-generator-api.json +12 -12
  41. package/noop.ts +3 -0
  42. package/package.json +9 -4
  43. package/src/events/authorization/AuthorizationEvents.ts +1 -1
  44. package/src/events/cookies/CookieEvents.ts +1 -1
  45. package/src/modeling/DataDomain.ts +84 -3
  46. package/src/modeling/DomainElement.ts +16 -0
  47. package/src/modeling/DomainImpactAnalysis.ts +54 -239
  48. package/src/modeling/DomainValidation.ts +105 -0
  49. package/src/modeling/types.ts +86 -0
  50. package/src/modeling/validation/entity_validation.ts +1 -1
  51. package/src/modeling/validation/rules.ts +2 -4
  52. package/src/modeling/validation/semantic_validation.ts +145 -0
  53. package/tests/unit/events/EventsTestHelpers.ts +16 -0
  54. package/tests/unit/events/amf.spec.ts +151 -0
  55. package/tests/unit/events/authorization.spec.ts +150 -0
  56. package/tests/unit/events/cookie.spec.ts +274 -0
  57. package/tests/unit/events/encryption.spec.ts +108 -0
  58. package/tests/unit/events/events_polyfills.ts +77 -0
  59. package/tests/unit/events/process.spec.ts +120 -0
  60. package/tests/unit/events/reporting.spec.ts +82 -0
  61. package/tests/unit/events/telemetry.spec.ts +224 -0
  62. package/tests/unit/events/transport.spec.ts +139 -0
  63. package/tests/unit/modeling/data_domain_foreign.spec.ts +244 -0
  64. package/tests/unit/modeling/domain_impact_analysis.spec.ts +0 -110
  65. package/tests/unit/modeling/domain_validation.spec.ts +94 -0
  66. package/tests/unit/modeling/validation/semantic_validation.spec.ts +91 -0
  67. package/tests/unit/models/environment.spec.ts +574 -0
  68. package/tests/unit/models/error_response.spec.ts +183 -0
  69. package/tests/unit/models/headers_array.spec.ts +86 -0
  70. package/tests/unit/models/http-actions/assertion/equal_assertion.spec.ts +103 -0
  71. package/tests/unit/models/http-actions/assertion/greater_than_assertion.spec.ts +91 -0
  72. package/tests/unit/models/http-actions/assertion/includes_assertion.spec.ts +71 -0
  73. package/tests/unit/models/http-actions/assertion/less_than_assertion.spec.ts +91 -0
  74. package/tests/unit/models/http-actions/assertion/matches_assertion.spec.ts +71 -0
  75. package/tests/unit/models/http-actions/assertion/matches_schema_assertion.spec.ts +117 -0
  76. package/tests/unit/models/http-actions/assertion/not_equal_assertion.spec.ts +103 -0
  77. package/tests/unit/models/http-actions/assertion/not_includes_assertion.spec.ts +71 -0
  78. package/tests/unit/models/http-actions/assertion/not_ok_assertion.spec.ts +47 -0
  79. package/tests/unit/models/http-actions/assertion/not_to_be_assertion.spec.ts +72 -0
  80. package/tests/unit/models/http-actions/assertion/ok_assertion.spec.ts +44 -0
  81. package/tests/unit/models/http-actions/assertion/to_be_assertion.spec.ts +71 -0
  82. package/tests/unit/models/http-actions/transformation/as_lower_case_step.spec.ts +47 -0
  83. package/tests/unit/models/http-actions/transformation/as_number_step.spec.ts +47 -0
  84. package/tests/unit/models/http-actions/transformation/as_upper_case_step.spec.ts +47 -0
  85. package/tests/unit/models/http-actions/transformation/round_step.spec.ts +69 -0
  86. package/tests/unit/models/http-actions/transformation/substring_step.spec.ts +85 -0
  87. package/tests/unit/models/http-actions/transformation/trim_step.spec.ts +44 -0
  88. package/tests/unit/models/http_cookie.spec.ts +516 -0
  89. package/tests/unit/models/http_history.spec.ts +443 -0
  90. package/tests/unit/models/project_folder.spec.ts +926 -0
  91. package/tests/unit/models/project_item.spec.ts +137 -0
  92. package/tests/unit/models/project_request.spec.ts +1047 -0
  93. package/tests/unit/models/project_schema.spec.ts +236 -0
  94. package/tests/unit/models/property.spec.ts +625 -0
  95. package/tests/unit/models/provider.spec.ts +102 -0
  96. package/tests/unit/models/request.spec.ts +1206 -0
  97. package/tests/unit/models/request_log.spec.ts +308 -0
  98. package/tests/unit/models/request_time.spec.ts +138 -0
  99. package/tests/unit/models/response_redirect.spec.ts +303 -0
  100. package/tests/unit/models/sent_request.spec.ts +206 -0
  101. package/tests/unit/models/server.spec.ts +195 -0
  102. package/tests/unit/models/thing.spec.ts +154 -0
  103. package/build/oauth-popup.html +0 -33
  104. /package/tests/unit/models/{Certificate.spec.ts → certificate.spec.ts} +0 -0
  105. /package/tests/unit/models/{HostRule.spec.ts → host_rule.spec.ts} +0 -0
  106. /package/tests/unit/models/{HttpProject.spec.ts → http_project.spec.ts} +0 -0
  107. /package/tests/unit/models/{HttpRequest.spec.ts → http_request.spec.ts} +0 -0
  108. /package/tests/unit/models/{HttpResponse.spec.ts → http_response.spec.ts} +0 -0
  109. /package/tests/unit/models/{License.spec.ts → license.spec.ts} +0 -0
  110. /package/tests/unit/models/{Response.spec.ts → response.spec.ts} +0 -0
@@ -0,0 +1,574 @@
1
+ import { test } from '@japa/runner'
2
+ import { Environment, IEnvironment, Kind as EnvironmentKind } from '../../../src/models/Environment.js'
3
+ import { Server, Kind as ServerKind } from '../../../src/models/Server.js'
4
+ import { Property, Kind as PropertyKind, PropertyType } from '../../../src/models/Property.js'
5
+ import { RequestAuthorization, Kind as RequestAuthorizationKind } from '../../../src/models/RequestAuthorization.js'
6
+ import { ThingKind } from '../../../src/models/kinds.js'
7
+
8
+ test.group('Models > Environment > Initialization', () => {
9
+ test('initializes a default environment', ({ assert }) => {
10
+ const result = new Environment()
11
+ assert.equal(result.kind, EnvironmentKind, 'sets the kind property')
12
+ assert.typeOf(result.key, 'string', 'sets the key property')
13
+
14
+ const { info } = result
15
+ assert.typeOf(info, 'EventTarget', 'sets the default info property')
16
+ assert.equal(info.kind, ThingKind, 'sets the info.kind property')
17
+ assert.equal(info.name, '', 'sets the empty info.name property')
18
+ })
19
+ })
20
+
21
+ test.group('Models > Environment > From schema initialization', (group) => {
22
+ let base: IEnvironment
23
+ group.each.setup(() => {
24
+ base = {
25
+ kind: EnvironmentKind,
26
+ key: 'test1234',
27
+ info: {
28
+ kind: ThingKind,
29
+ name: 'An env',
30
+ },
31
+ variables: [
32
+ {
33
+ kind: PropertyKind,
34
+ name: 'a var',
35
+ type: 'string',
36
+ value: '',
37
+ },
38
+ ],
39
+ encapsulated: true,
40
+ server: {
41
+ kind: ServerKind,
42
+ uri: 'api.com',
43
+ basePath: '/',
44
+ description: 'a server',
45
+ protocol: 'https',
46
+ },
47
+ }
48
+ })
49
+
50
+ test('sets the info', ({ assert }) => {
51
+ const init: IEnvironment = {
52
+ ...base,
53
+ ...{
54
+ info: {
55
+ kind: ThingKind,
56
+ name: 'Test env',
57
+ description: 'Env description',
58
+ version: '1.2.3',
59
+ },
60
+ },
61
+ }
62
+ const result = new Environment(init)
63
+ const { info } = result
64
+ assert.equal(info.kind, ThingKind, 'sets the info.kind property')
65
+ assert.equal(info.name, 'Test env', 'sets the info.name property')
66
+ assert.equal(info.description, 'Env description', 'sets the info.description property')
67
+ assert.equal(info.version, '1.2.3', 'sets the info.version property')
68
+ })
69
+
70
+ test('sets the server', ({ assert }) => {
71
+ const result = new Environment(base)
72
+ const { server } = result
73
+
74
+ assert.equal(server!.uri, 'api.com')
75
+ assert.equal(server!.basePath, '/')
76
+ assert.equal(server!.description, 'a server')
77
+ assert.equal(server!.protocol, 'https')
78
+ })
79
+
80
+ test('sets the passed key', ({ assert }) => {
81
+ const result = new Environment(base)
82
+ assert.equal(result.key, 'test1234')
83
+ })
84
+
85
+ test('sets a new key when the passed key is missing', ({ assert }) => {
86
+ const init: IEnvironment = { ...base }
87
+ // @ts-expect-error Used in testing
88
+ delete init.key
89
+ const result = new Environment(init)
90
+ assert.typeOf(result.key, 'string')
91
+ })
92
+
93
+ test('sets encapsulated to false by default', ({ assert }) => {
94
+ const init: IEnvironment = { ...base }
95
+ delete init.encapsulated
96
+ const result = new Environment(init)
97
+ assert.isFalse(result.encapsulated)
98
+ })
99
+
100
+ test('sets the variables', ({ assert }) => {
101
+ const result = new Environment(base)
102
+ assert.lengthOf(result.variables, 1, 'has the variables')
103
+ const [var1] = result.variables
104
+ assert.equal(var1.kind, PropertyKind)
105
+ assert.equal(var1.name, 'a var')
106
+ assert.equal(var1.type, 'string')
107
+ assert.equal(var1.value, '')
108
+ })
109
+
110
+ test('sets the default variables', ({ assert }) => {
111
+ const init: IEnvironment = { ...base }
112
+ // @ts-expect-error Used in testing
113
+ delete init.variables
114
+ const result = new Environment(init)
115
+ assert.deepEqual(result.variables, [])
116
+ })
117
+ })
118
+
119
+ test.group('Models > Environment > From JSON string initialization', () => {
120
+ test('restores the data from JSON string', ({ assert }) => {
121
+ const env = new Environment()
122
+ env.info.name = 'an environment'
123
+ env.addVariable('test', 123)
124
+ env.addServer('https://api.com')
125
+ const str = JSON.stringify(env)
126
+
127
+ const result = new Environment(str)
128
+
129
+ assert.equal(result.key, env.key, 'restores the key')
130
+ assert.equal(result.info.name, 'an environment', 'restores the info object')
131
+ assert.lengthOf(result.variables, 1, 'restores the variables')
132
+ assert.equal(result.server!.uri, 'https://api.com', 'restores the server')
133
+ })
134
+
135
+ test('throws when invalid folder object', ({ assert }) => {
136
+ const env = new Environment()
137
+ env.info.name = 'an environment'
138
+ const schema = env.toJSON()
139
+ // @ts-expect-error Used in testing
140
+ delete schema.kind
141
+ const str = JSON.stringify(schema)
142
+
143
+ assert.throws(() => {
144
+ new Environment(str)
145
+ })
146
+ })
147
+ })
148
+
149
+ test.group('Models > Environment > Environment.fromName()', () => {
150
+ test('adds the name', ({ assert }) => {
151
+ const result = Environment.fromName('an env')
152
+ assert.equal(result.info.name, 'an env')
153
+ })
154
+
155
+ test('generates the key', ({ assert }) => {
156
+ const result = Environment.fromName('an env')
157
+ assert.typeOf(result.key, 'string')
158
+ })
159
+
160
+ test('adds empty variables', ({ assert }) => {
161
+ const result = Environment.fromName('an env')
162
+ assert.deepEqual(result.variables, [])
163
+ })
164
+ })
165
+
166
+ test.group('Models > Environment > Environment.fromLegacyVariables()', () => {
167
+ test('adds the name', ({ assert }) => {
168
+ const result = Environment.fromLegacyVariables('an env', [])
169
+ assert.equal(result.info.name, 'an env')
170
+ })
171
+
172
+ test('generates the key', ({ assert }) => {
173
+ const result = Environment.fromLegacyVariables('an env', [])
174
+ assert.typeOf(result.key, 'string')
175
+ })
176
+
177
+ test('adds the variable', ({ assert }) => {
178
+ const result = Environment.fromLegacyVariables('an env', [
179
+ {
180
+ environment: 'any',
181
+ name: 'n1',
182
+ value: 'v1',
183
+ },
184
+ ])
185
+ assert.lengthOf(result.variables, 1, 'has the variable')
186
+ const [v1] = result.variables
187
+ assert.equal(v1.kind, PropertyKind)
188
+ assert.equal(v1.name, 'n1')
189
+ assert.equal(v1.value, 'v1')
190
+ assert.equal(v1.type, 'string')
191
+ })
192
+ })
193
+
194
+ test.group('Models > Environment > new()', () => {
195
+ test('adds default info', ({ assert }) => {
196
+ const env = Environment.fromName('a')
197
+ const schema = env.toJSON()
198
+ // @ts-expect-error Used in testing
199
+ delete schema.info
200
+ env.new(schema)
201
+
202
+ assert.typeOf(env.info, 'EventTarget', 'sets the info object')
203
+ assert.equal(env.info.name, '', 'sets the empty name')
204
+ })
205
+
206
+ test('removes the server when not defined in the schema', ({ assert }) => {
207
+ const env = Environment.fromName('a')
208
+ env.server = Server.fromUri('https://api.com')
209
+ const schema = env.toJSON()
210
+ delete schema.server
211
+ env.new(schema)
212
+
213
+ assert.isUndefined(env.server, 'sets the server')
214
+ })
215
+
216
+ test('sets the passed server', ({ assert }) => {
217
+ const env = Environment.fromName('a')
218
+ const schema = env.toJSON()
219
+ schema.server = {
220
+ kind: ServerKind,
221
+ uri: 'abc',
222
+ }
223
+ env.new(schema)
224
+
225
+ assert.typeOf(env.server, 'object', 'sets the server')
226
+ assert.equal(env.server!.uri, 'abc')
227
+ })
228
+
229
+ test('clears the variables when not defined in the schema', ({ assert }) => {
230
+ const env = Environment.fromName('a')
231
+ env.addVariable('a', 'b')
232
+ const schema = env.toJSON()
233
+ // @ts-expect-error Used in testing
234
+ delete schema.variables
235
+ env.new(schema)
236
+
237
+ assert.deepEqual(env.variables, [])
238
+ })
239
+
240
+ test('sets the passed variables', ({ assert }) => {
241
+ const env = Environment.fromName('a')
242
+ const schema = env.toJSON()
243
+ schema.variables = [
244
+ {
245
+ kind: PropertyKind,
246
+ name: 'a',
247
+ value: 'b',
248
+ type: 'string',
249
+ },
250
+ ]
251
+ env.new(schema)
252
+
253
+ assert.lengthOf(env.variables, 1, 'has a variable')
254
+ assert.equal(env.variables[0].name, 'a')
255
+ })
256
+
257
+ test('re-sets the kind', ({ assert }) => {
258
+ const env = Environment.fromName('a')
259
+ env.kind = 'test'
260
+ const schema = env.toJSON()
261
+ env.new(schema)
262
+
263
+ assert.equal(env.kind, EnvironmentKind)
264
+ })
265
+
266
+ test('sets the key', ({ assert }) => {
267
+ const env = Environment.fromName('a')
268
+ const schema = env.toJSON()
269
+ schema.key = '1234'
270
+ env.new(schema)
271
+
272
+ assert.equal(env.key, '1234')
273
+ })
274
+
275
+ test('generates a new key', ({ assert }) => {
276
+ const env = Environment.fromName('a')
277
+ const schema = env.toJSON()
278
+ // @ts-expect-error Used in testing
279
+ delete schema.key
280
+ env.new(schema)
281
+
282
+ assert.typeOf(env.key, 'string')
283
+ })
284
+
285
+ test('sets default "encapsulated"', ({ assert }) => {
286
+ const env = Environment.fromName('a')
287
+ const schema = env.toJSON()
288
+ delete schema.encapsulated
289
+ env.new(schema)
290
+
291
+ assert.isFalse(env.encapsulated)
292
+ })
293
+
294
+ test('sets the "encapsulated"', ({ assert }) => {
295
+ const env = Environment.fromName('a')
296
+ const schema = env.toJSON()
297
+ schema.encapsulated = true
298
+ env.new(schema)
299
+
300
+ assert.isTrue(env.encapsulated)
301
+ })
302
+
303
+ test('sets the authorization', ({ assert }) => {
304
+ const instance = new Environment()
305
+ const schema = instance.toJSON()
306
+ schema.authorization = [
307
+ {
308
+ kind: RequestAuthorizationKind,
309
+ enabled: true,
310
+ type: 'oauth 2',
311
+ valid: true,
312
+ config: {},
313
+ },
314
+ ]
315
+ instance.new(schema)
316
+
317
+ assert.typeOf(instance.authorization, 'array')
318
+ assert.equal(instance.authorization![0].type, 'oauth 2')
319
+ })
320
+
321
+ test('sets the authorization to undefined when missing', ({ assert }) => {
322
+ const instance = new Environment()
323
+ const schema = instance.toJSON()
324
+ schema.authorization = [
325
+ {
326
+ kind: RequestAuthorizationKind,
327
+ enabled: true,
328
+ type: 'oauth 2',
329
+ valid: true,
330
+ config: {},
331
+ },
332
+ ]
333
+ instance.new(schema)
334
+ delete schema.authorization
335
+ instance.new(schema)
336
+
337
+ assert.isUndefined(instance.authorization)
338
+ })
339
+ })
340
+
341
+ test.group('Models > Environment > toJSON()', (group) => {
342
+ let base: IEnvironment
343
+ group.each.setup(() => {
344
+ base = {
345
+ kind: EnvironmentKind,
346
+ key: 'test1234',
347
+ info: {
348
+ kind: ThingKind,
349
+ name: 'An env',
350
+ },
351
+ variables: [
352
+ {
353
+ kind: PropertyKind,
354
+ name: 'a var',
355
+ type: 'string',
356
+ value: '',
357
+ },
358
+ ],
359
+ encapsulated: true,
360
+ server: {
361
+ kind: ServerKind,
362
+ uri: 'api.com',
363
+ basePath: '/',
364
+ description: 'a server',
365
+ protocol: 'https',
366
+ },
367
+ }
368
+ })
369
+
370
+ test('sets the info', ({ assert }) => {
371
+ const init: IEnvironment = {
372
+ ...base,
373
+ ...{
374
+ info: {
375
+ kind: ThingKind,
376
+ name: 'Test env',
377
+ description: 'Env description',
378
+ version: '1.2.3',
379
+ },
380
+ },
381
+ }
382
+ const env = new Environment(init)
383
+ const result = env.toJSON()
384
+ const { info } = result
385
+ assert.equal(info.kind, ThingKind, 'sets the info.kind property')
386
+ assert.equal(info.name, 'Test env', 'sets the info.name property')
387
+ assert.equal(info.description, 'Env description', 'sets the info.description property')
388
+ assert.equal(info.version, '1.2.3', 'sets the info.version property')
389
+ })
390
+
391
+ test('serializes the key', ({ assert }) => {
392
+ const init: IEnvironment = { ...base }
393
+ const env = new Environment(init)
394
+ const result = env.toJSON()
395
+ assert.equal(result.key, init.key)
396
+ })
397
+
398
+ test('serializes the encapsulated', ({ assert }) => {
399
+ const init: IEnvironment = { ...base }
400
+ const env = new Environment(init)
401
+ const result = env.toJSON()
402
+ assert.isTrue(result.encapsulated)
403
+ })
404
+
405
+ test('serializes the server', ({ assert }) => {
406
+ const init: IEnvironment = { ...base }
407
+ const env = new Environment(init)
408
+ const result = env.toJSON()
409
+ const { server } = result
410
+ assert.equal(server!.kind, ServerKind)
411
+ assert.equal(server!.uri, 'api.com')
412
+ assert.equal(server!.basePath, '/')
413
+ assert.equal(server!.description, 'a server')
414
+ assert.equal(server!.protocol, 'https')
415
+ })
416
+
417
+ test('serializes variables', ({ assert }) => {
418
+ const init: IEnvironment = { ...base }
419
+ const env = new Environment(init)
420
+ const result = env.toJSON()
421
+ const { variables } = result
422
+ assert.lengthOf(variables, 1, 'has the variable')
423
+ const [v1] = variables
424
+
425
+ assert.equal(v1.name, 'a var')
426
+ assert.equal(v1.type, 'string')
427
+ assert.equal(v1.value, '')
428
+ })
429
+
430
+ test('sets the authorization', ({ assert }) => {
431
+ const instance = new Environment()
432
+ instance.authorization = [
433
+ new RequestAuthorization({
434
+ kind: RequestAuthorizationKind,
435
+ enabled: true,
436
+ type: 'oauth 2',
437
+ valid: true,
438
+ config: {},
439
+ }),
440
+ ]
441
+ const result = instance.toJSON()
442
+
443
+ assert.typeOf(result.authorization, 'array')
444
+ assert.equal(result.authorization![0].type, 'oauth 2')
445
+ })
446
+
447
+ test('does not set the authorization when missing', ({ assert }) => {
448
+ const instance = new Environment()
449
+ const result = instance.toJSON()
450
+ assert.isUndefined(result.authorization)
451
+ })
452
+ })
453
+
454
+ test.group('Models > Environment > addVariable()', () => {
455
+ test('adds variable by name and value', ({ assert }) => {
456
+ const env = new Environment()
457
+ const result = env.addVariable('a', 'b')
458
+
459
+ assert.typeOf(result, 'object', 'returns the created property')
460
+ assert.equal(result.name, 'a', 'the created property has the name')
461
+ assert.equal(result.value, 'b', 'the created property has the value')
462
+ assert.equal(result.type, 'string' as PropertyType, 'the created property has the type')
463
+ assert.lengthOf(env.variables, 1, 'has the variable')
464
+ assert.deepEqual(env.variables[0], result, 'inserted variable is the created property')
465
+ })
466
+
467
+ test('adds variable by property schema', ({ assert }) => {
468
+ const env = new Environment()
469
+ const prop = Property.Integer('a', 1)
470
+ const result = env.addVariable(prop.toJSON())
471
+
472
+ assert.typeOf(result, 'object', 'returns the created property')
473
+ assert.equal(result.name, 'a', 'the created property has the name')
474
+ assert.equal(result.value, 1, 'the created property has the value')
475
+ assert.equal(result.type, 'integer' as PropertyType, 'the created property has the type')
476
+ assert.lengthOf(env.variables, 1, 'has the variable')
477
+ assert.deepEqual(env.variables[0], prop, 'inserted variable is the created property')
478
+ })
479
+
480
+ test('creates variables array when missing', ({ assert }) => {
481
+ const env = new Environment()
482
+ // @ts-expect-error Used in testing
483
+ delete env.variables
484
+ env.addVariable('a', 'b')
485
+ assert.typeOf(env.variables, 'array')
486
+ assert.lengthOf(env.variables, 1)
487
+ })
488
+
489
+ test('should set default variable type to string', ({ assert }) => {
490
+ const env = new Environment()
491
+ const property = env.addVariable('test', 'value')
492
+ assert.equal(property.type, 'string' as PropertyType)
493
+ })
494
+ })
495
+
496
+ test.group('Models > Environment > getServer()', () => {
497
+ test('returns undefined when no server', ({ assert }) => {
498
+ const env = new Environment()
499
+ const result = env.getServer()
500
+ assert.isUndefined(result)
501
+ })
502
+
503
+ test('returns the default server when forced', ({ assert }) => {
504
+ const env = new Environment()
505
+ const result = env.getServer(true)!
506
+ assert.typeOf(result, 'object', 'has the server')
507
+ assert.equal(result.readUri(), '', 'has the default URI')
508
+ })
509
+
510
+ test('returns existing server', ({ assert }) => {
511
+ const env = new Environment()
512
+ env.addServer('https://api.com')
513
+ const result = env.getServer()!
514
+ assert.typeOf(result, 'object', 'has the server')
515
+ assert.equal(result.readUri(), 'https://api.com')
516
+ })
517
+ })
518
+
519
+ test.group('Models > Environment > addServer()', () => {
520
+ test('adds a server by URI', ({ assert }) => {
521
+ const env = new Environment()
522
+ env.addServer('https://happy.server')
523
+
524
+ assert.equal(env.getServer()!.uri, 'https://happy.server')
525
+ })
526
+
527
+ test('adds a server from schema', ({ assert }) => {
528
+ const env = new Environment()
529
+ const srv = new Server()
530
+ srv.uri = 'https://happy.server'
531
+ env.addServer(srv.toJSON())
532
+
533
+ assert.equal(env.getServer()!.uri, 'https://happy.server')
534
+ })
535
+ })
536
+
537
+ test.group('Models > Environment > clone()', () => {
538
+ test('makes a copy of the environment', ({ assert }) => {
539
+ const src = Environment.fromName('abc')
540
+ const copy = src.clone()
541
+ assert.equal(copy.info.name, 'abc')
542
+ })
543
+
544
+ test('regenerates the key by default', ({ assert }) => {
545
+ const src = Environment.fromName('abc')
546
+ const copy = src.clone()
547
+ assert.notEqual(copy.key, src.key)
548
+ assert.typeOf(copy.key, 'string')
549
+ })
550
+
551
+ test('skips key regeneration when configured', ({ assert }) => {
552
+ const src = Environment.fromName('abc')
553
+ const copy = src.clone({ withoutRevalidate: true })
554
+ assert.equal(copy.key, src.key)
555
+ })
556
+ })
557
+
558
+ test.group('Models > Environment > uniqueProperties()', () => {
559
+ test('returns all properties', ({ assert }) => {
560
+ const e1 = Environment.fromName('e1')
561
+ const v1 = e1.addVariable('v1', 'v1')
562
+ const v2 = e1.addVariable('v2', 'v2')
563
+ const result = e1.uniqueProperties()
564
+ assert.deepEqual(result, [v1, v2])
565
+ })
566
+
567
+ test('returns only unique properties', ({ assert }) => {
568
+ const e1 = Environment.fromName('e1')
569
+ e1.addVariable('v1', 'v1')
570
+ const v2 = e1.addVariable('v1', 'v2')
571
+ const result = e1.uniqueProperties()
572
+ assert.deepEqual(result, [v2])
573
+ })
574
+ })