@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.
Files changed (95) 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/DomainImpactAnalysis.d.ts +22 -119
  12. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  13. package/build/src/modeling/DomainImpactAnalysis.js +49 -155
  14. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  15. package/build/src/modeling/DomainValidation.d.ts +8 -0
  16. package/build/src/modeling/DomainValidation.d.ts.map +1 -0
  17. package/build/src/modeling/DomainValidation.js +99 -0
  18. package/build/src/modeling/DomainValidation.js.map +1 -0
  19. package/build/src/modeling/types.d.ts +70 -0
  20. package/build/src/modeling/types.d.ts.map +1 -1
  21. package/build/src/modeling/types.js.map +1 -1
  22. package/build/src/modeling/validation/rules.d.ts +2 -3
  23. package/build/src/modeling/validation/rules.d.ts.map +1 -1
  24. package/build/src/modeling/validation/rules.js.map +1 -1
  25. package/build/src/modeling/validation/semantic_validation.d.ts +31 -0
  26. package/build/src/modeling/validation/semantic_validation.d.ts.map +1 -0
  27. package/build/src/modeling/validation/semantic_validation.js +126 -0
  28. package/build/src/modeling/validation/semantic_validation.js.map +1 -0
  29. package/build/tsconfig.tsbuildinfo +1 -1
  30. package/noop.ts +3 -0
  31. package/package.json +9 -4
  32. package/src/events/authorization/AuthorizationEvents.ts +1 -1
  33. package/src/events/cookies/CookieEvents.ts +1 -1
  34. package/src/modeling/DomainImpactAnalysis.ts +54 -239
  35. package/src/modeling/DomainValidation.ts +105 -0
  36. package/src/modeling/types.ts +86 -0
  37. package/src/modeling/validation/rules.ts +2 -4
  38. package/src/modeling/validation/semantic_validation.ts +145 -0
  39. package/tests/unit/events/EventsTestHelpers.ts +16 -0
  40. package/tests/unit/events/amf.spec.ts +151 -0
  41. package/tests/unit/events/authorization.spec.ts +150 -0
  42. package/tests/unit/events/cookie.spec.ts +274 -0
  43. package/tests/unit/events/encryption.spec.ts +108 -0
  44. package/tests/unit/events/events_polyfills.ts +77 -0
  45. package/tests/unit/events/process.spec.ts +120 -0
  46. package/tests/unit/events/reporting.spec.ts +82 -0
  47. package/tests/unit/events/telemetry.spec.ts +224 -0
  48. package/tests/unit/events/transport.spec.ts +139 -0
  49. package/tests/unit/modeling/domain_impact_analysis.spec.ts +0 -110
  50. package/tests/unit/modeling/domain_validation.spec.ts +94 -0
  51. package/tests/unit/modeling/validation/semantic_validation.spec.ts +91 -0
  52. package/tests/unit/models/environment.spec.ts +574 -0
  53. package/tests/unit/models/error_response.spec.ts +183 -0
  54. package/tests/unit/models/headers_array.spec.ts +86 -0
  55. package/tests/unit/models/http-actions/assertion/equal_assertion.spec.ts +103 -0
  56. package/tests/unit/models/http-actions/assertion/greater_than_assertion.spec.ts +91 -0
  57. package/tests/unit/models/http-actions/assertion/includes_assertion.spec.ts +71 -0
  58. package/tests/unit/models/http-actions/assertion/less_than_assertion.spec.ts +91 -0
  59. package/tests/unit/models/http-actions/assertion/matches_assertion.spec.ts +71 -0
  60. package/tests/unit/models/http-actions/assertion/matches_schema_assertion.spec.ts +117 -0
  61. package/tests/unit/models/http-actions/assertion/not_equal_assertion.spec.ts +103 -0
  62. package/tests/unit/models/http-actions/assertion/not_includes_assertion.spec.ts +71 -0
  63. package/tests/unit/models/http-actions/assertion/not_ok_assertion.spec.ts +47 -0
  64. package/tests/unit/models/http-actions/assertion/not_to_be_assertion.spec.ts +72 -0
  65. package/tests/unit/models/http-actions/assertion/ok_assertion.spec.ts +44 -0
  66. package/tests/unit/models/http-actions/assertion/to_be_assertion.spec.ts +71 -0
  67. package/tests/unit/models/http-actions/transformation/as_lower_case_step.spec.ts +47 -0
  68. package/tests/unit/models/http-actions/transformation/as_number_step.spec.ts +47 -0
  69. package/tests/unit/models/http-actions/transformation/as_upper_case_step.spec.ts +47 -0
  70. package/tests/unit/models/http-actions/transformation/round_step.spec.ts +69 -0
  71. package/tests/unit/models/http-actions/transformation/substring_step.spec.ts +85 -0
  72. package/tests/unit/models/http-actions/transformation/trim_step.spec.ts +44 -0
  73. package/tests/unit/models/http_cookie.spec.ts +516 -0
  74. package/tests/unit/models/http_history.spec.ts +443 -0
  75. package/tests/unit/models/project_folder.spec.ts +926 -0
  76. package/tests/unit/models/project_item.spec.ts +137 -0
  77. package/tests/unit/models/project_request.spec.ts +1047 -0
  78. package/tests/unit/models/project_schema.spec.ts +236 -0
  79. package/tests/unit/models/property.spec.ts +625 -0
  80. package/tests/unit/models/provider.spec.ts +102 -0
  81. package/tests/unit/models/request.spec.ts +1206 -0
  82. package/tests/unit/models/request_log.spec.ts +308 -0
  83. package/tests/unit/models/request_time.spec.ts +138 -0
  84. package/tests/unit/models/response_redirect.spec.ts +303 -0
  85. package/tests/unit/models/sent_request.spec.ts +206 -0
  86. package/tests/unit/models/server.spec.ts +195 -0
  87. package/tests/unit/models/thing.spec.ts +154 -0
  88. package/build/oauth-popup.html +0 -33
  89. /package/tests/unit/models/{Certificate.spec.ts → certificate.spec.ts} +0 -0
  90. /package/tests/unit/models/{HostRule.spec.ts → host_rule.spec.ts} +0 -0
  91. /package/tests/unit/models/{HttpProject.spec.ts → http_project.spec.ts} +0 -0
  92. /package/tests/unit/models/{HttpRequest.spec.ts → http_request.spec.ts} +0 -0
  93. /package/tests/unit/models/{HttpResponse.spec.ts → http_response.spec.ts} +0 -0
  94. /package/tests/unit/models/{License.spec.ts → license.spec.ts} +0 -0
  95. /package/tests/unit/models/{Response.spec.ts → response.spec.ts} +0 -0
@@ -0,0 +1,303 @@
1
+ import { test } from '@japa/runner'
2
+ import {
3
+ ResponseRedirect,
4
+ IResponseRedirect,
5
+ Kind as ResponseRedirectKind,
6
+ } from '../../../src/models/ResponseRedirect.js'
7
+ import { HttpResponse, IHttpResponse } from '../../../src/models/HttpResponse.js'
8
+ import { Kind as RequestTimeKind } from '../../../src/models/RequestTime.js'
9
+ import { ResponseRedirect as LegacyRedirect } from '../../../src/models/legacy/request/ArcResponse.js'
10
+ import { HttpResponseKind } from '../../../src/models/kinds.js'
11
+
12
+ test.group('Models > ResponseRedirect > ResponseRedirect.fromValues()', (group) => {
13
+ let response: IHttpResponse
14
+ group.each.setup(() => {
15
+ response = HttpResponse.fromValues(200, 'OK', 'content-type: text/plain').toJSON()
16
+ })
17
+
18
+ test('sets the kind', ({ assert }) => {
19
+ const result = ResponseRedirect.fromValues('https://dot.com', response)
20
+ assert.equal(result.kind, ResponseRedirectKind)
21
+ })
22
+
23
+ test('sets the url', ({ assert }) => {
24
+ const result = ResponseRedirect.fromValues('https://dot.com', response)
25
+ assert.equal(result.url, 'https://dot.com')
26
+ })
27
+
28
+ test('sets the response', ({ assert }) => {
29
+ const result = ResponseRedirect.fromValues('https://dot.com', response)
30
+ assert.typeOf(result.response, 'object', 'has the response')
31
+ assert.isTrue(result.response instanceof HttpResponse, 'has the HttpResponse instance')
32
+ })
33
+
34
+ test('sets the default startTime', ({ assert }) => {
35
+ const result = ResponseRedirect.fromValues('https://dot.com', response)
36
+ assert.equal(result.startTime, 0)
37
+ })
38
+
39
+ test('sets the default endTime', ({ assert }) => {
40
+ const result = ResponseRedirect.fromValues('https://dot.com', response)
41
+ assert.equal(result.endTime, 0)
42
+ })
43
+
44
+ test('sets the startTime', ({ assert }) => {
45
+ const result = ResponseRedirect.fromValues('https://dot.com', response, 1234)
46
+ assert.equal(result.startTime, 1234)
47
+ })
48
+
49
+ test('sets the endTime', ({ assert }) => {
50
+ const result = ResponseRedirect.fromValues('https://dot.com', response, 1234, 5678)
51
+ assert.equal(result.endTime, 5678)
52
+ })
53
+ })
54
+
55
+ test.group('Models > ResponseRedirect > ResponseRedirect.fromLegacy()', (group) => {
56
+ let schema: LegacyRedirect
57
+ group.each.setup(() => {
58
+ schema = {
59
+ startTime: 1234,
60
+ endTime: 5678,
61
+ url: 'https://rdr.com',
62
+ timings: {
63
+ blocked: 1,
64
+ connect: 2,
65
+ dns: 3,
66
+ receive: 4,
67
+ send: 5,
68
+ wait: 6,
69
+ ssl: 7,
70
+ },
71
+ response: {
72
+ status: 307,
73
+ statusText: 'Moved.',
74
+ headers: 'location: https://rdr.com',
75
+ payload: 'I am in a different location.',
76
+ },
77
+ }
78
+ })
79
+
80
+ test('sets the kind', async ({ assert }) => {
81
+ const result = await ResponseRedirect.fromLegacy(schema)
82
+ assert.equal(result.kind, ResponseRedirectKind)
83
+ })
84
+
85
+ test('sets the startTime', async ({ assert }) => {
86
+ const result = await ResponseRedirect.fromLegacy(schema)
87
+ assert.equal(result.startTime, schema.startTime)
88
+ })
89
+
90
+ test('sets the default startTime', async ({ assert }) => {
91
+ // @ts-expect-error Used in testing
92
+ delete schema.startTime
93
+ const result = await ResponseRedirect.fromLegacy(schema)
94
+ assert.equal(result.startTime, 0)
95
+ })
96
+
97
+ test('sets the endTime', async ({ assert }) => {
98
+ const result = await ResponseRedirect.fromLegacy(schema)
99
+ assert.equal(result.endTime, schema.endTime)
100
+ })
101
+
102
+ test('sets the default endTime', async ({ assert }) => {
103
+ // @ts-expect-error Used in testing
104
+ delete schema.endTime
105
+ const result = await ResponseRedirect.fromLegacy(schema)
106
+ assert.equal(result.endTime, 0)
107
+ })
108
+
109
+ test('sets the url', async ({ assert }) => {
110
+ const result = await ResponseRedirect.fromLegacy(schema)
111
+ assert.equal(result.url, schema.url)
112
+ })
113
+
114
+ test('sets the default url', async ({ assert }) => {
115
+ // @ts-expect-error Used in testing
116
+ delete schema.url
117
+ const result = await ResponseRedirect.fromLegacy(schema)
118
+ assert.equal(result.url, '')
119
+ })
120
+
121
+ test('sets the response', async ({ assert }) => {
122
+ const result = await ResponseRedirect.fromLegacy(schema)
123
+ const { response } = result
124
+ assert.typeOf(response, 'object')
125
+ assert.equal(response!.status, schema.response.status)
126
+ assert.equal(response!.statusText, schema.response.statusText)
127
+ assert.equal(response!.headers, schema.response.headers)
128
+ assert.equal(response!.payload, 'I am in a different location.')
129
+ })
130
+
131
+ test('sets the default response', async ({ assert }) => {
132
+ // @ts-expect-error Used in testing
133
+ delete schema.response
134
+ const result = await ResponseRedirect.fromLegacy(schema)
135
+ const { response } = result
136
+ assert.typeOf(response, 'object')
137
+ assert.equal(response!.status, 0)
138
+ })
139
+
140
+ test('sets the timings', async ({ assert }) => {
141
+ const result = await ResponseRedirect.fromLegacy(schema)
142
+ const { timings } = result
143
+ assert.typeOf(timings, 'object')
144
+ assert.equal(timings!.blocked, schema.timings!.blocked)
145
+ assert.equal(timings!.connect, schema.timings!.connect)
146
+ assert.equal(timings!.dns, schema.timings!.dns)
147
+ assert.equal(timings!.receive, schema.timings!.receive)
148
+ assert.equal(timings!.send, schema.timings!.send)
149
+ assert.equal(timings!.wait, schema.timings!.wait)
150
+ })
151
+ })
152
+
153
+ test.group('Models > ResponseRedirect > constructor()', () => {
154
+ test('creates a default instance', ({ assert }) => {
155
+ const result = new ResponseRedirect()
156
+ assert.equal(result.kind, ResponseRedirectKind)
157
+ assert.equal(result.endTime, 0)
158
+ assert.equal(result.startTime, 0)
159
+ assert.equal(result.url, '')
160
+ assert.equal(result.response!.status, 0)
161
+ })
162
+
163
+ test('creates an instance from the schema', ({ assert }) => {
164
+ const schema: IResponseRedirect = {
165
+ kind: ResponseRedirectKind,
166
+ startTime: 1234,
167
+ endTime: 5678,
168
+ url: 'https://dot.com',
169
+ response: {
170
+ status: 200,
171
+ statusText: 'OK',
172
+ },
173
+ timings: {
174
+ blocked: 1,
175
+ connect: 2,
176
+ dns: 3,
177
+ receive: 4,
178
+ send: 5,
179
+ wait: 6,
180
+ ssl: 7,
181
+ },
182
+ }
183
+ const result = new ResponseRedirect(schema)
184
+ assert.equal(result.kind, ResponseRedirectKind)
185
+ assert.equal(result.startTime, 1234)
186
+ assert.equal(result.endTime, 5678)
187
+ assert.equal(result.url, 'https://dot.com')
188
+ assert.equal(result.response!.status, 200)
189
+ assert.equal(result.response!.statusText, 'OK')
190
+ assert.equal(result.timings!.blocked, schema.timings!.blocked)
191
+ assert.equal(result.timings!.connect, schema.timings!.connect)
192
+ })
193
+
194
+ test('the timings is optional', ({ assert }) => {
195
+ const schema: IResponseRedirect = {
196
+ kind: ResponseRedirectKind,
197
+ startTime: 1234,
198
+ endTime: 5678,
199
+ url: 'https://dot.com',
200
+ response: {
201
+ status: 200,
202
+ statusText: 'OK',
203
+ },
204
+ }
205
+ const result = new ResponseRedirect(schema)
206
+ assert.isUndefined(result.timings)
207
+ })
208
+
209
+ test('creates an instance from the JSON schema string', ({ assert }) => {
210
+ const schema: IResponseRedirect = {
211
+ kind: ResponseRedirectKind,
212
+ startTime: 1234,
213
+ endTime: 5678,
214
+ url: 'https://dot.com',
215
+ response: {
216
+ status: 200,
217
+ statusText: 'OK',
218
+ },
219
+ }
220
+ const result = new ResponseRedirect(JSON.stringify(schema))
221
+ assert.equal(result.kind, ResponseRedirectKind)
222
+ assert.equal(result.startTime, 1234)
223
+ assert.equal(result.endTime, 5678)
224
+ assert.equal(result.url, 'https://dot.com')
225
+ assert.equal(result.response!.status, 200)
226
+ assert.equal(result.response!.statusText, 'OK')
227
+ })
228
+ })
229
+
230
+ test.group('Models > ResponseRedirect > toJSON()', (group) => {
231
+ let schema: IResponseRedirect
232
+ let instance: ResponseRedirect
233
+ group.each.setup(() => {
234
+ schema = {
235
+ kind: ResponseRedirectKind,
236
+ startTime: 1234,
237
+ endTime: 5678,
238
+ url: 'https://dot.com',
239
+ response: {
240
+ kind: HttpResponseKind,
241
+ status: 200,
242
+ statusText: 'OK',
243
+ },
244
+ timings: {
245
+ kind: RequestTimeKind, // Added kind for timings as it's likely a typed object
246
+ blocked: 1,
247
+ connect: 2,
248
+ dns: 3,
249
+ receive: 4,
250
+ send: 5,
251
+ wait: 6,
252
+ ssl: 7,
253
+ },
254
+ }
255
+ instance = new ResponseRedirect(schema)
256
+ })
257
+
258
+ test('serializes the kind', ({ assert }) => {
259
+ const result = instance.toJSON()
260
+ assert.equal(result.kind, ResponseRedirectKind)
261
+ })
262
+
263
+ test('serializes the startTime', ({ assert }) => {
264
+ const result = instance.toJSON()
265
+ assert.equal(result.startTime, schema.startTime)
266
+ })
267
+
268
+ test('serializes the endTime', ({ assert }) => {
269
+ const result = instance.toJSON()
270
+ assert.equal(result.endTime, schema.endTime)
271
+ })
272
+
273
+ test('serializes the url', ({ assert }) => {
274
+ const result = instance.toJSON()
275
+ assert.equal(result.url, schema.url)
276
+ })
277
+
278
+ test('serializes the response', ({ assert }) => {
279
+ const result = instance.toJSON()
280
+ assert.deepEqual(result.response, schema.response)
281
+ })
282
+
283
+ test('serializes the default response', ({ assert }) => {
284
+ delete instance.response
285
+ const result = instance.toJSON()
286
+ assert.deepEqual(result.response, {
287
+ kind: HttpResponseKind,
288
+ status: 0,
289
+ })
290
+ })
291
+
292
+ test('serializes the timings', ({ assert }) => {
293
+ const result = instance.toJSON()
294
+ // Assuming timings in schema also includes kind after serialization by RequestTime model
295
+ assert.deepEqual(result.timings, schema.timings)
296
+ })
297
+
298
+ test('does not serialize the timings when missing', ({ assert }) => {
299
+ delete instance.timings
300
+ const result = instance.toJSON()
301
+ assert.isUndefined(result.timings)
302
+ })
303
+ })
@@ -0,0 +1,206 @@
1
+ import { test } from '@japa/runner'
2
+ import { SentRequest, ISentRequest, IBaseSentRequest } from '../../../src/models/SentRequest.js'
3
+ import { Kind as HttpRequestKind } from '../../../src/models/HttpRequest.js'
4
+ import { TransportRequest as LegacyTransportRequest } from '../../../src/models/legacy/request/ArcRequest.js'
5
+
6
+ test.group('Models > SentRequest > SentRequest.fromBaseValues()', (group) => {
7
+ let base: IBaseSentRequest
8
+ group.each.setup(() => {
9
+ base = {
10
+ startTime: 1234,
11
+ url: 'https://dot.com',
12
+ endTime: 5678,
13
+ headers: 'x-test: true',
14
+ httpMessage: 'GET / HTTP 1/1\n\n',
15
+ method: 'GET',
16
+ payload: 'test',
17
+ }
18
+ })
19
+
20
+ test('sets the kind', ({ assert }) => {
21
+ const result = SentRequest.fromBaseValues(base)
22
+ assert.equal(result.kind, HttpRequestKind)
23
+ })
24
+
25
+ // Note: The original test had a duplicate "sets the kind" test. I'm keeping one.
26
+ // If the second was intended to test something else, it should be adjusted.
27
+
28
+ test('sets the httpMessage', ({ assert }) => {
29
+ const result = SentRequest.fromBaseValues(base)
30
+ assert.equal(result.httpMessage, base.httpMessage)
31
+ })
32
+
33
+ test('sets the startTime', ({ assert }) => {
34
+ const result = SentRequest.fromBaseValues(base)
35
+ assert.equal(result.startTime, base.startTime)
36
+ })
37
+
38
+ test('sets the endTime', ({ assert }) => {
39
+ const result = SentRequest.fromBaseValues(base)
40
+ assert.equal(result.endTime, base.endTime)
41
+ })
42
+ })
43
+
44
+ test.group('Models > SentRequest > SentRequest.fromLegacy()', (group) => {
45
+ let base: LegacyTransportRequest
46
+ group.each.setup(() => {
47
+ base = {
48
+ startTime: 1234,
49
+ url: 'https://dot.com',
50
+ endTime: 5678,
51
+ httpMessage: 'GET / HTTP 1/1\n\n',
52
+ method: 'GET',
53
+ headers: 'x-test: true',
54
+ payload: 'test',
55
+ }
56
+ })
57
+
58
+ test('sets the kind', async ({ assert }) => {
59
+ const result = await SentRequest.fromLegacy(base)
60
+ assert.equal(result.kind, HttpRequestKind)
61
+ })
62
+
63
+ test('sets the url', async ({ assert }) => {
64
+ const result = await SentRequest.fromLegacy(base)
65
+ assert.equal(result.url, base.url)
66
+ })
67
+
68
+ test('sets the default url when missing', async ({ assert }) => {
69
+ // @ts-expect-error Used in testing
70
+ delete base.url
71
+ const result = await SentRequest.fromLegacy(base)
72
+ assert.equal(result.url, '')
73
+ })
74
+
75
+ test('sets the startTime', async ({ assert }) => {
76
+ const result = await SentRequest.fromLegacy(base)
77
+ assert.equal(result.startTime, base.startTime)
78
+ })
79
+
80
+ test('sets the default startTime', async ({ assert }) => {
81
+ // @ts-expect-error Used in testing
82
+ delete base.startTime
83
+ const result = await SentRequest.fromLegacy(base)
84
+ assert.equal(result.startTime, 0)
85
+ })
86
+
87
+ test('sets the endTime', async ({ assert }) => {
88
+ const result = await SentRequest.fromLegacy(base)
89
+ assert.equal(result.endTime, base.endTime)
90
+ })
91
+
92
+ test('sets the default endTime when missing', async ({ assert }) => {
93
+ // @ts-expect-error Used in testing
94
+ delete base.endTime
95
+ const result = await SentRequest.fromLegacy(base)
96
+ assert.equal(result.endTime, 0)
97
+ })
98
+
99
+ test('sets the httpMessage', async ({ assert }) => {
100
+ const result = await SentRequest.fromLegacy(base)
101
+ assert.equal(result.httpMessage, base.httpMessage)
102
+ })
103
+
104
+ test('does not set the httpMessage when missing', async ({ assert }) => {
105
+ // @ts-expect-error Used in testing
106
+ delete base.httpMessage
107
+ const result = await SentRequest.fromLegacy(base)
108
+ assert.isUndefined(result.httpMessage)
109
+ })
110
+
111
+ test('sets the method', async ({ assert }) => {
112
+ const result = await SentRequest.fromLegacy(base)
113
+ assert.equal(result.method, base.method)
114
+ })
115
+
116
+ test('sets the default method when missing', async ({ assert }) => {
117
+ // @ts-expect-error Used in testing
118
+ delete base.method
119
+ const result = await SentRequest.fromLegacy(base)
120
+ assert.equal(result.method, 'GET')
121
+ })
122
+
123
+ test('sets the headers', async ({ assert }) => {
124
+ const result = await SentRequest.fromLegacy(base)
125
+ assert.equal(result.headers, base.headers)
126
+ })
127
+
128
+ test('does not set the headers when missing', async ({ assert }) => {
129
+ delete base.headers
130
+ const result = await SentRequest.fromLegacy(base)
131
+ assert.isUndefined(result.headers)
132
+ })
133
+
134
+ test('sets the payload', async ({ assert }) => {
135
+ const result = await SentRequest.fromLegacy(base)
136
+ assert.equal(result.payload, 'test')
137
+ })
138
+
139
+ test('does not set the payload when missing', async ({ assert }) => {
140
+ delete base.payload
141
+ const result = await SentRequest.fromLegacy(base)
142
+ assert.isUndefined(result.payload)
143
+ })
144
+ })
145
+
146
+ test.group('Models > SentRequest > constructor()', () => {
147
+ test('creates a default instance', ({ assert }) => {
148
+ const result = new SentRequest()
149
+ assert.equal(result.kind, HttpRequestKind)
150
+ assert.equal(result.url, '')
151
+ assert.equal(result.startTime, 0)
152
+ })
153
+
154
+ test('creates an instance from schema', ({ assert }) => {
155
+ const schema: ISentRequest = {
156
+ kind: HttpRequestKind,
157
+ startTime: 1234,
158
+ url: 'https://dot.com',
159
+ endTime: 56789,
160
+ httpMessage: 'GET / HTTP 1/1\n\n',
161
+ method: 'GET',
162
+ headers: 'x-test: true',
163
+ payload: 'test',
164
+ }
165
+ const result = new SentRequest(schema)
166
+ assert.deepEqual(result.toJSON(), schema)
167
+ })
168
+
169
+ test('creates an instance from a JSON schema string', ({ assert }) => {
170
+ const schema: ISentRequest = {
171
+ kind: HttpRequestKind,
172
+ startTime: 1234,
173
+ url: 'https://dot.com',
174
+ endTime: 56789,
175
+ httpMessage: 'GET / HTTP 1/1\n\n',
176
+ method: 'GET',
177
+ headers: 'x-test: true',
178
+ payload: 'test',
179
+ }
180
+ const result = new SentRequest(JSON.stringify(schema))
181
+ assert.deepEqual(result.toJSON(), schema)
182
+ })
183
+ })
184
+
185
+ test.group('Models > SentRequest > toJSON()', (group) => {
186
+ let schema: ISentRequest
187
+ let instance: SentRequest
188
+ group.each.setup(() => {
189
+ schema = {
190
+ kind: HttpRequestKind,
191
+ startTime: 1234,
192
+ url: 'https://dot.com',
193
+ endTime: 56789,
194
+ httpMessage: 'GET / HTTP 1/1\n\n',
195
+ method: 'GET',
196
+ headers: 'x-test: true',
197
+ payload: 'test',
198
+ }
199
+ instance = new SentRequest(schema)
200
+ })
201
+
202
+ test('serializes all properties from schema', ({ assert }) => {
203
+ const result = instance.toJSON()
204
+ assert.deepEqual(result, schema)
205
+ })
206
+ })
@@ -0,0 +1,195 @@
1
+ import { test } from '@japa/runner'
2
+ import { Server, IServer, Kind as ServerKind } from '../../../src/models/Server.js'
3
+ import { Property } from '../../../src/models/Property.js'
4
+
5
+ test.group('Models > Server > Server.fromUri()', () => {
6
+ test('sets the kind', ({ assert }) => {
7
+ const result = Server.fromUri('https://dot.com')
8
+ assert.equal(result.kind, ServerKind)
9
+ })
10
+
11
+ test('sets the uri', ({ assert }) => {
12
+ const result = Server.fromUri('https://dot.com')
13
+ assert.equal(result.uri, 'https://dot.com')
14
+ })
15
+ })
16
+
17
+ test.group('Models > Server > constructor()', () => {
18
+ test('creates an empty Server', ({ assert }) => {
19
+ const result = new Server()
20
+ assert.equal(result.kind, ServerKind)
21
+ assert.equal(result.uri, '')
22
+ assert.isUndefined(result.description)
23
+ assert.isUndefined(result.protocol)
24
+ assert.isUndefined(result.basePath)
25
+ })
26
+
27
+ test('creates a Server from the schema values', ({ assert }) => {
28
+ const schema: IServer = {
29
+ kind: ServerKind,
30
+ uri: 'dot.com',
31
+ description: 'a desc',
32
+ protocol: 'https:',
33
+ basePath: '/api',
34
+ }
35
+ const result = new Server(schema)
36
+ assert.equal(result.kind, ServerKind)
37
+ assert.equal(result.uri, 'dot.com')
38
+ assert.equal(result.description, 'a desc')
39
+ assert.equal(result.protocol, 'https:')
40
+ assert.equal(result.basePath, '/api')
41
+ })
42
+
43
+ test('creates a Server from the JSON schema string', ({ assert }) => {
44
+ const schema: IServer = {
45
+ kind: ServerKind,
46
+ uri: 'dot.com',
47
+ description: 'a desc',
48
+ protocol: 'https:',
49
+ basePath: '/api',
50
+ }
51
+ const result = new Server(JSON.stringify(schema))
52
+ assert.equal(result.kind, ServerKind)
53
+ assert.equal(result.uri, 'dot.com')
54
+ assert.equal(result.description, 'a desc')
55
+ assert.equal(result.protocol, 'https:')
56
+ assert.equal(result.basePath, '/api')
57
+ })
58
+
59
+ test('throws when invalid schema', ({ assert }) => {
60
+ assert.throws(() => {
61
+ new Server(
62
+ JSON.stringify({
63
+ name: 'a name', // Invalid, Server expects 'uri' not 'name' for primary identifier
64
+ })
65
+ )
66
+ })
67
+ })
68
+ })
69
+
70
+ test.group('Models > Server > toJSON()', (group) => {
71
+ let server: Server
72
+ group.each.setup(() => {
73
+ server = new Server()
74
+ })
75
+
76
+ test('serializes the kind', ({ assert }) => {
77
+ const result = server.toJSON()
78
+ assert.equal(result.kind, ServerKind)
79
+ })
80
+
81
+ test('serializes the uri', ({ assert }) => {
82
+ server.uri = 'dot.com'
83
+ const result = server.toJSON()
84
+ assert.equal(result.uri, 'dot.com')
85
+ })
86
+
87
+ test('serializes the description', ({ assert }) => {
88
+ server.description = 'a description'
89
+ const result = server.toJSON()
90
+ assert.equal(result.description, 'a description')
91
+ })
92
+
93
+ test('does not serialize description when missing', ({ assert }) => {
94
+ const result = server.toJSON()
95
+ assert.isUndefined(result.description)
96
+ })
97
+
98
+ test('serializes the protocol', ({ assert }) => {
99
+ server.protocol = 'a protocol'
100
+ const result = server.toJSON()
101
+ assert.equal(result.protocol, 'a protocol')
102
+ })
103
+
104
+ test('does not serialize protocol when missing', ({ assert }) => {
105
+ const result = server.toJSON()
106
+ assert.isUndefined(result.protocol)
107
+ })
108
+
109
+ test('serializes the basePath', ({ assert }) => {
110
+ server.basePath = 'a basePath'
111
+ const result = server.toJSON()
112
+ assert.equal(result.basePath, 'a basePath')
113
+ })
114
+
115
+ test('does not serialize basePath when missing', ({ assert }) => {
116
+ const result = server.toJSON()
117
+ assert.isUndefined(result.basePath)
118
+ })
119
+ })
120
+
121
+ test.group('Models > Server > readUri()', () => {
122
+ test('returns empty string when no data', ({ assert }) => {
123
+ const info = new Server()
124
+ const result = info.readUri()
125
+ assert.equal(result, '')
126
+ })
127
+
128
+ test('returns the uri value', ({ assert }) => {
129
+ const info = new Server()
130
+ info.uri = 'dot.com'
131
+ const result = info.readUri()
132
+ assert.equal(result, 'dot.com')
133
+ })
134
+
135
+ test('adds the protocol when missing', ({ assert }) => {
136
+ const info = new Server()
137
+ info.uri = 'dot.com'
138
+ info.protocol = 'http:'
139
+ const result = info.readUri()
140
+ assert.equal(result, 'http://dot.com')
141
+ })
142
+
143
+ test('ignores the protocol when not missing', ({ assert }) => {
144
+ const info = new Server()
145
+ info.uri = 'https://dot.com'
146
+ info.protocol = 'http:'
147
+ const result = info.readUri()
148
+ assert.equal(result, 'https://dot.com')
149
+ })
150
+
151
+ test('adds the base path', ({ assert }) => {
152
+ const info = new Server()
153
+ info.uri = 'dot.com'
154
+ info.basePath = '/api'
155
+ const result = info.readUri()
156
+ assert.equal(result, 'dot.com/api')
157
+ })
158
+
159
+ test('clears the base uri before adding the base path', ({ assert }) => {
160
+ const info = new Server()
161
+ info.uri = 'dot.com/'
162
+ info.basePath = '/api'
163
+ const result = info.readUri()
164
+ assert.equal(result, 'dot.com/api')
165
+ })
166
+
167
+ test('normalizes the base path', ({ assert }) => {
168
+ const info = new Server()
169
+ info.uri = 'dot.com'
170
+ info.basePath = 'api'
171
+ const result = info.readUri()
172
+ assert.equal(result, 'dot.com/api')
173
+ })
174
+
175
+ test('evaluates the uri when no variables', ({ assert }) => {
176
+ const info = Server.fromUri('https://api.com')
177
+ const p1 = Property.String('a', 'b')
178
+ const result = info.readUri([p1])
179
+ assert.equal(result, 'https://api.com')
180
+ })
181
+
182
+ test('evaluates the uri', ({ assert }) => {
183
+ const info = Server.fromUri('https://{a}.com')
184
+ const p1 = Property.String('a', 'b')
185
+ const result = info.readUri([p1])
186
+ assert.equal(result, 'https://b.com')
187
+ })
188
+
189
+ test('evaluates the uri when no property', ({ assert }) => {
190
+ const info = Server.fromUri('https://{a}.com')
191
+ const p1 = Property.String('c', 'b')
192
+ const result = info.readUri([p1])
193
+ assert.equal(result, 'https://{a}.com')
194
+ })
195
+ })