@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,1206 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import { Request, IRequest, Kind as RequestKind, updatedSymbol, midnightSymbol } from '../../../src/models/Request.js'
|
|
3
|
+
import { HttpRequest, IHttpRequest, Kind as HttpRequestKind } from '../../../src/models/HttpRequest.js'
|
|
4
|
+
import { ErrorResponse } from '../../../src/models/ErrorResponse.js'
|
|
5
|
+
import { RequestLog, Kind as RequestLogKind } from '../../../src/models/RequestLog.js'
|
|
6
|
+
import { RequestConfig, Kind as RequestConfigKind } from '../../../src/models/RequestConfig.js'
|
|
7
|
+
import { RequestAuthorization, Kind as RequestAuthorizationKind } from '../../../src/models/RequestAuthorization.js'
|
|
8
|
+
import { ARCSavedRequest } from '../../../src/models/legacy/request/ArcRequest.js'
|
|
9
|
+
import { ISafePayload } from '../../../src/lib/transformers/PayloadSerializer.js'
|
|
10
|
+
import { Certificate, Kind as CertificateKind, IP12Certificate } from '../../../src/models/ClientCertificate.js'
|
|
11
|
+
import { SetCookieConfig } from '../../../src/models/legacy/actions/Actions.js'
|
|
12
|
+
import { FlowRequestDataEnum, FlowSourceEnum } from '../../../src/models/http-flows/HttpFlows.js'
|
|
13
|
+
import { ReadDataStep } from '../../../src/models/http-flows/steps/data/ReadDataStep.js'
|
|
14
|
+
import { HttpResponseKind, ThingKind } from '../../../src/models/kinds.js'
|
|
15
|
+
|
|
16
|
+
test.group('Models > Request > Request.fromUrl()', () => {
|
|
17
|
+
const url = 'https://dot.com'
|
|
18
|
+
|
|
19
|
+
test('sets the request data', ({ assert }) => {
|
|
20
|
+
const result = Request.fromUrl(url)
|
|
21
|
+
assert.equal(result.kind, RequestKind)
|
|
22
|
+
assert.typeOf(result.created, 'number')
|
|
23
|
+
assert.typeOf(result.updated, 'number')
|
|
24
|
+
const { expects, info } = result
|
|
25
|
+
assert.typeOf(expects, 'object', 'sets the expects')
|
|
26
|
+
assert.ok(info, 'sets the info')
|
|
27
|
+
|
|
28
|
+
assert.equal(expects.method, 'GET')
|
|
29
|
+
assert.equal(expects.url, url)
|
|
30
|
+
assert.equal(info.name, url)
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test.group('Models > Request > Request.fromName()', () => {
|
|
35
|
+
const name = 'a name'
|
|
36
|
+
|
|
37
|
+
test('sets the request data', ({ assert }) => {
|
|
38
|
+
const result = Request.fromName(name)
|
|
39
|
+
assert.equal(result.kind, RequestKind)
|
|
40
|
+
assert.typeOf(result.created, 'number')
|
|
41
|
+
assert.typeOf(result.updated, 'number')
|
|
42
|
+
const { expects, info } = result
|
|
43
|
+
assert.typeOf(expects, 'object', 'sets the expects')
|
|
44
|
+
assert.ok(info, 'sets the info')
|
|
45
|
+
|
|
46
|
+
assert.equal(expects.method, 'GET')
|
|
47
|
+
assert.equal(expects.url, '')
|
|
48
|
+
assert.equal(info.name, name)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test.group('Models > Request > Request.fromHttpRequest()', () => {
|
|
53
|
+
test('sets the request data', ({ assert }) => {
|
|
54
|
+
const schema: IHttpRequest = {
|
|
55
|
+
kind: HttpRequestKind,
|
|
56
|
+
url: 'https://dot.com',
|
|
57
|
+
headers: 'a: b',
|
|
58
|
+
method: 'PUT',
|
|
59
|
+
payload: 'test',
|
|
60
|
+
}
|
|
61
|
+
const result = Request.fromHttpRequest(schema)
|
|
62
|
+
|
|
63
|
+
assert.equal(result.kind, RequestKind)
|
|
64
|
+
assert.typeOf(result.created, 'number')
|
|
65
|
+
assert.typeOf(result.updated, 'number')
|
|
66
|
+
const { expects, info } = result
|
|
67
|
+
assert.typeOf(expects, 'object', 'sets the expects')
|
|
68
|
+
assert.typeOf(info, 'EventTarget', 'sets the info')
|
|
69
|
+
|
|
70
|
+
assert.equal(expects.url, schema.url)
|
|
71
|
+
assert.equal(expects.method, schema.method)
|
|
72
|
+
assert.equal(expects.headers, schema.headers)
|
|
73
|
+
assert.equal(expects.payload, schema.payload)
|
|
74
|
+
assert.equal(info.name, schema.url)
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test.group('Models > Request > Request.fromLegacy()', () => {
|
|
79
|
+
test('throws when unknown object', async ({ assert }) => {
|
|
80
|
+
let thrown = false
|
|
81
|
+
try {
|
|
82
|
+
// @ts-expect-error Used in testing
|
|
83
|
+
await Request.fromLegacy(undefined)
|
|
84
|
+
} catch {
|
|
85
|
+
thrown = true
|
|
86
|
+
}
|
|
87
|
+
assert.isTrue(thrown)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('sets the created and updated', async ({ assert }) => {
|
|
91
|
+
const instance = await Request.fromLegacy({
|
|
92
|
+
method: 'PUT',
|
|
93
|
+
name: 'test',
|
|
94
|
+
url: 'https://dot.com',
|
|
95
|
+
created: 1234567890,
|
|
96
|
+
updated: 987654321,
|
|
97
|
+
})
|
|
98
|
+
assert.equal(instance.created, 1234567890)
|
|
99
|
+
assert.equal(instance.updated, 987654321)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('sets the default created', async ({ assert }) => {
|
|
103
|
+
const now = Date.now()
|
|
104
|
+
const instance = await Request.fromLegacy({
|
|
105
|
+
method: 'PUT',
|
|
106
|
+
name: 'test',
|
|
107
|
+
url: 'https://dot.com',
|
|
108
|
+
})
|
|
109
|
+
assert.approximately(instance.created, now, 100)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('sets the default updated', async ({ assert }) => {
|
|
113
|
+
const instance = await Request.fromLegacy({
|
|
114
|
+
method: 'PUT',
|
|
115
|
+
name: 'test',
|
|
116
|
+
url: 'https://dot.com',
|
|
117
|
+
})
|
|
118
|
+
assert.equal(instance.updated, instance.created)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('sets the expects object', async ({ assert }) => {
|
|
122
|
+
const instance = await Request.fromLegacy({
|
|
123
|
+
method: 'PUT',
|
|
124
|
+
name: 'test',
|
|
125
|
+
url: 'https://dot.com',
|
|
126
|
+
headers: 'x-a: b',
|
|
127
|
+
payload: 'test-payload',
|
|
128
|
+
})
|
|
129
|
+
const { expects } = instance
|
|
130
|
+
assert.equal(expects.method, 'PUT')
|
|
131
|
+
assert.equal(expects.url, 'https://dot.com')
|
|
132
|
+
assert.equal(expects.headers, 'x-a: b')
|
|
133
|
+
assert.equal(expects.payload, 'test-payload')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('sets the info object', async ({ assert }) => {
|
|
137
|
+
const instance = await Request.fromLegacy({
|
|
138
|
+
method: 'PUT',
|
|
139
|
+
name: 'test',
|
|
140
|
+
url: 'https://dot.com',
|
|
141
|
+
})
|
|
142
|
+
const { info } = instance
|
|
143
|
+
assert.equal(info.name, 'test')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test('sets the payload from a Blob', async ({ assert }) => {
|
|
147
|
+
const instance = await Request.fromLegacy({
|
|
148
|
+
method: 'PUT',
|
|
149
|
+
name: 'test',
|
|
150
|
+
url: 'https://dot.com',
|
|
151
|
+
blob: 'test',
|
|
152
|
+
})
|
|
153
|
+
const { expects } = instance
|
|
154
|
+
assert.ok(expects.payload, 'has the payload')
|
|
155
|
+
const payload = expects.payload as ISafePayload
|
|
156
|
+
assert.equal(payload.type, 'blob')
|
|
157
|
+
assert.deepEqual(payload.data, 'test')
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('sets the payload from a multipart', async ({ assert }) => {
|
|
161
|
+
const instance = await Request.fromLegacy({
|
|
162
|
+
method: 'PUT',
|
|
163
|
+
name: 'test',
|
|
164
|
+
url: 'https://dot.com',
|
|
165
|
+
multipart: [
|
|
166
|
+
{
|
|
167
|
+
name: 'a',
|
|
168
|
+
isFile: false,
|
|
169
|
+
value: 'b',
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
})
|
|
173
|
+
const { expects } = instance
|
|
174
|
+
assert.ok(expects.payload, 'has the payload')
|
|
175
|
+
const payload = expects.payload as ISafePayload
|
|
176
|
+
assert.equal(payload.type, 'formdata')
|
|
177
|
+
assert.deepEqual(payload.data, [
|
|
178
|
+
{
|
|
179
|
+
name: 'a',
|
|
180
|
+
isFile: false,
|
|
181
|
+
value: 'b',
|
|
182
|
+
},
|
|
183
|
+
])
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('sets the payload from an ArrayBuffer', async ({ assert }) => {
|
|
187
|
+
const encoder = new TextEncoder()
|
|
188
|
+
const view = encoder.encode('test')
|
|
189
|
+
|
|
190
|
+
const instance = await Request.fromLegacy({
|
|
191
|
+
method: 'PUT',
|
|
192
|
+
name: 'test',
|
|
193
|
+
url: 'https://dot.com',
|
|
194
|
+
payload: Uint8Array.from(view).buffer,
|
|
195
|
+
})
|
|
196
|
+
const { expects } = instance
|
|
197
|
+
assert.ok(expects.payload, 'has the payload')
|
|
198
|
+
const payload = expects.payload as ISafePayload
|
|
199
|
+
assert.equal(payload.type, 'arraybuffer')
|
|
200
|
+
assert.deepEqual(payload.data, [116, 101, 115, 116])
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('translates the legacy actions object', async ({ assert }) => {
|
|
204
|
+
const instance = await Request.fromLegacy({
|
|
205
|
+
method: 'PUT',
|
|
206
|
+
name: 'test',
|
|
207
|
+
url: 'https://dot.com',
|
|
208
|
+
actions: {
|
|
209
|
+
request: [
|
|
210
|
+
{
|
|
211
|
+
condition: {
|
|
212
|
+
source: 'body',
|
|
213
|
+
alwaysPass: true,
|
|
214
|
+
path: 'a.b.c',
|
|
215
|
+
type: 'request',
|
|
216
|
+
},
|
|
217
|
+
actions: [
|
|
218
|
+
{
|
|
219
|
+
priority: 0,
|
|
220
|
+
type: 'request',
|
|
221
|
+
name: 'set-cookie',
|
|
222
|
+
config: {
|
|
223
|
+
source: {
|
|
224
|
+
source: 'body',
|
|
225
|
+
type: 'request',
|
|
226
|
+
path: 'abc',
|
|
227
|
+
},
|
|
228
|
+
name: 'A name',
|
|
229
|
+
} as SetCookieConfig,
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
enabled: true,
|
|
233
|
+
type: 'request',
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
response: [
|
|
237
|
+
{
|
|
238
|
+
condition: {
|
|
239
|
+
source: 'body',
|
|
240
|
+
alwaysPass: true,
|
|
241
|
+
path: 'a.b.c',
|
|
242
|
+
type: 'response',
|
|
243
|
+
},
|
|
244
|
+
actions: [
|
|
245
|
+
{
|
|
246
|
+
priority: 0,
|
|
247
|
+
type: 'response',
|
|
248
|
+
config: {
|
|
249
|
+
source: {
|
|
250
|
+
source: 'body',
|
|
251
|
+
type: 'request',
|
|
252
|
+
path: 'abc',
|
|
253
|
+
},
|
|
254
|
+
name: 'A name',
|
|
255
|
+
} as SetCookieConfig,
|
|
256
|
+
name: 'set-cookie',
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
enabled: true,
|
|
260
|
+
type: 'response',
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
})
|
|
265
|
+
const { flows } = instance
|
|
266
|
+
assert.ok(flows, 'has flows')
|
|
267
|
+
|
|
268
|
+
assert.lengthOf(flows!, 2, 'has two flows')
|
|
269
|
+
const [f1, f2] = flows!
|
|
270
|
+
|
|
271
|
+
assert.equal(f1.trigger, 'request', 'has the request flow')
|
|
272
|
+
assert.equal(f2.trigger, 'response', 'has the response flow')
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
test('translates the config object', async ({ assert }) => {
|
|
276
|
+
const instance = await Request.fromLegacy({
|
|
277
|
+
method: 'PUT',
|
|
278
|
+
name: 'test',
|
|
279
|
+
url: 'https://dot.com',
|
|
280
|
+
config: {
|
|
281
|
+
enabled: true,
|
|
282
|
+
defaultHeaders: true,
|
|
283
|
+
followRedirects: true,
|
|
284
|
+
hosts: [],
|
|
285
|
+
ignoreSessionCookies: false,
|
|
286
|
+
nativeTransport: true,
|
|
287
|
+
timeout: 500,
|
|
288
|
+
validateCertificates: true,
|
|
289
|
+
variables: [],
|
|
290
|
+
},
|
|
291
|
+
})
|
|
292
|
+
const { config } = instance
|
|
293
|
+
|
|
294
|
+
assert.typeOf(config, 'object', 'has the UI definition')
|
|
295
|
+
assert.equal(config!.kind, RequestConfigKind)
|
|
296
|
+
|
|
297
|
+
assert.isTrue(config!.enabled)
|
|
298
|
+
assert.isTrue(config!.followRedirects)
|
|
299
|
+
assert.isTrue(config!.validateCertificates)
|
|
300
|
+
assert.isTrue(config!.defaultHeaders)
|
|
301
|
+
assert.isFalse(config!.ignoreSessionCookies)
|
|
302
|
+
assert.equal(config!.timeout, 500)
|
|
303
|
+
assert.typeOf(config!.hosts, 'array')
|
|
304
|
+
assert.typeOf(config!.variables, 'array')
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
test('translates the authorization', async ({ assert }) => {
|
|
308
|
+
const instance = await Request.fromLegacy({
|
|
309
|
+
method: 'PUT',
|
|
310
|
+
name: 'test',
|
|
311
|
+
url: 'https://dot.com',
|
|
312
|
+
authorization: [
|
|
313
|
+
{
|
|
314
|
+
enabled: true,
|
|
315
|
+
type: 'oauth 2',
|
|
316
|
+
valid: true,
|
|
317
|
+
config: {},
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
const { authorization } = instance
|
|
323
|
+
assert.typeOf(authorization, 'array')
|
|
324
|
+
const [info] = authorization!
|
|
325
|
+
assert.equal(info.enabled, true)
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
test('creates the log with the request data', async ({ assert }) => {
|
|
329
|
+
const instance = await Request.fromLegacy({
|
|
330
|
+
method: 'PUT',
|
|
331
|
+
name: 'test',
|
|
332
|
+
url: 'https://dot.com',
|
|
333
|
+
transportRequest: {
|
|
334
|
+
endTime: 123456,
|
|
335
|
+
httpMessage: 'test message',
|
|
336
|
+
method: 'PUT',
|
|
337
|
+
startTime: 789456,
|
|
338
|
+
url: 'https://dot.com',
|
|
339
|
+
headers: 'x-a: b',
|
|
340
|
+
payload: 'test-payload',
|
|
341
|
+
},
|
|
342
|
+
})
|
|
343
|
+
const { log } = instance
|
|
344
|
+
assert.ok(log, 'has the log')
|
|
345
|
+
assert.equal(log!.kind, RequestLogKind)
|
|
346
|
+
assert.ok(log!.request, 'has the log.request')
|
|
347
|
+
assert.notOk(log!.response, 'has no log.response')
|
|
348
|
+
assert.notOk(log!.redirects, 'has no log.redirects')
|
|
349
|
+
assert.equal(log!.request!.kind, HttpRequestKind)
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
test('creates the log with the response data', async ({ assert }) => {
|
|
353
|
+
const instance = await Request.fromLegacy({
|
|
354
|
+
method: 'PUT',
|
|
355
|
+
name: 'test',
|
|
356
|
+
url: 'https://dot.com',
|
|
357
|
+
response: {
|
|
358
|
+
loadingTime: 1,
|
|
359
|
+
status: 200,
|
|
360
|
+
},
|
|
361
|
+
})
|
|
362
|
+
const { log } = instance
|
|
363
|
+
assert.ok(log, 'has the log')
|
|
364
|
+
assert.equal(log!.kind, RequestLogKind)
|
|
365
|
+
assert.ok(log!.response, 'has the log.response')
|
|
366
|
+
assert.notOk(log!.request, 'has no log.request')
|
|
367
|
+
assert.notOk(log!.redirects, 'has no log.redirects')
|
|
368
|
+
assert.equal(log!.response!.kind, HttpResponseKind)
|
|
369
|
+
assert.equal(log!.response!.status, 200)
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
test('creates the log with an error response data', async ({ assert }) => {
|
|
373
|
+
const instance = await Request.fromLegacy({
|
|
374
|
+
method: 'PUT',
|
|
375
|
+
name: 'test',
|
|
376
|
+
url: 'https://dot.com',
|
|
377
|
+
response: {
|
|
378
|
+
loadingTime: 1,
|
|
379
|
+
status: 0,
|
|
380
|
+
error: new Error('test'),
|
|
381
|
+
},
|
|
382
|
+
})
|
|
383
|
+
const { log } = instance
|
|
384
|
+
assert.ok(log, 'has the log')
|
|
385
|
+
assert.equal(log!.kind, RequestLogKind)
|
|
386
|
+
assert.ok(log!.response, 'has the log.response')
|
|
387
|
+
assert.notOk(log!.request, 'has no log.request')
|
|
388
|
+
assert.notOk(log!.redirects, 'has no log.redirects')
|
|
389
|
+
assert.equal(log!.response!.kind, HttpResponseKind)
|
|
390
|
+
assert.equal(log!.response!.status, 0)
|
|
391
|
+
const err = log!.response as ErrorResponse
|
|
392
|
+
assert.equal(err.error.message, 'test')
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
test('creates the log with redirects data', async ({ assert }) => {
|
|
396
|
+
const instance = await Request.fromLegacy({
|
|
397
|
+
method: 'PUT',
|
|
398
|
+
name: 'test',
|
|
399
|
+
url: 'https://dot.com',
|
|
400
|
+
response: {
|
|
401
|
+
loadingTime: 1,
|
|
402
|
+
status: 200,
|
|
403
|
+
redirects: [
|
|
404
|
+
{
|
|
405
|
+
endTime: 12345,
|
|
406
|
+
response: {
|
|
407
|
+
status: 307,
|
|
408
|
+
},
|
|
409
|
+
startTime: 9876,
|
|
410
|
+
url: 'https://rdr.com',
|
|
411
|
+
timings: {
|
|
412
|
+
blocked: 1,
|
|
413
|
+
connect: 2,
|
|
414
|
+
dns: 3,
|
|
415
|
+
receive: 4,
|
|
416
|
+
send: 5,
|
|
417
|
+
wait: 6,
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
},
|
|
422
|
+
})
|
|
423
|
+
const { log } = instance
|
|
424
|
+
assert.ok(log, 'has the log')
|
|
425
|
+
const { redirects } = log!
|
|
426
|
+
assert.typeOf(redirects, 'array')
|
|
427
|
+
assert.lengthOf(redirects!, 1)
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
test('creates the log with size data', async ({ assert }) => {
|
|
431
|
+
const instance = await Request.fromLegacy({
|
|
432
|
+
method: 'PUT',
|
|
433
|
+
name: 'test',
|
|
434
|
+
url: 'https://dot.com',
|
|
435
|
+
response: {
|
|
436
|
+
loadingTime: 1,
|
|
437
|
+
status: 200,
|
|
438
|
+
size: {
|
|
439
|
+
request: 200,
|
|
440
|
+
response: 400,
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
})
|
|
444
|
+
const { log } = instance
|
|
445
|
+
assert.ok(log, 'has the log')
|
|
446
|
+
const { size } = log!
|
|
447
|
+
assert.typeOf(size, 'object')
|
|
448
|
+
assert.equal(size!.request, 200)
|
|
449
|
+
assert.equal(size!.response, 400)
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
test('sets the default HTTP method', async ({ assert }) => {
|
|
453
|
+
const info: ARCSavedRequest = {
|
|
454
|
+
method: 'PUT',
|
|
455
|
+
name: 'test',
|
|
456
|
+
url: 'https://dot.com',
|
|
457
|
+
}
|
|
458
|
+
// @ts-expect-error Used in testing
|
|
459
|
+
delete info.method
|
|
460
|
+
const instance = await Request.fromLegacy(info)
|
|
461
|
+
assert.equal(instance.expects.method, 'GET')
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
test('sets the default request url', async ({ assert }) => {
|
|
465
|
+
const info: ARCSavedRequest = {
|
|
466
|
+
method: 'PUT',
|
|
467
|
+
name: 'test',
|
|
468
|
+
url: 'https://dot.com',
|
|
469
|
+
}
|
|
470
|
+
// @ts-expect-error Used in testing
|
|
471
|
+
delete info.url
|
|
472
|
+
const instance = await Request.fromLegacy(info)
|
|
473
|
+
assert.equal(instance.expects.url, '')
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
test('sets the default request name', async ({ assert }) => {
|
|
477
|
+
const info: ARCSavedRequest = {
|
|
478
|
+
method: 'PUT',
|
|
479
|
+
name: 'test',
|
|
480
|
+
url: 'https://dot.com',
|
|
481
|
+
}
|
|
482
|
+
// @ts-expect-error Used in testing
|
|
483
|
+
delete info.name
|
|
484
|
+
const instance = await Request.fromLegacy(info)
|
|
485
|
+
assert.equal(instance.info.name, 'Unnamed request')
|
|
486
|
+
})
|
|
487
|
+
})
|
|
488
|
+
|
|
489
|
+
test.group('Models > Request > #created', () => {
|
|
490
|
+
test('sets the value', ({ assert }) => {
|
|
491
|
+
const instance = new Request()
|
|
492
|
+
instance.created = 1234
|
|
493
|
+
assert.equal(instance.created, 1234)
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
test('sets the current time when value is missing', ({ assert }) => {
|
|
497
|
+
const instance = new Request()
|
|
498
|
+
const now = Date.now()
|
|
499
|
+
instance.created = undefined
|
|
500
|
+
assert.approximately(instance.created, now, 100)
|
|
501
|
+
})
|
|
502
|
+
})
|
|
503
|
+
|
|
504
|
+
test.group('Models > Request > #updated', () => {
|
|
505
|
+
test('sets the value', ({ assert }) => {
|
|
506
|
+
const instance = new Request()
|
|
507
|
+
instance.updated = 1234
|
|
508
|
+
assert.equal(instance.updated, 1234)
|
|
509
|
+
})
|
|
510
|
+
|
|
511
|
+
test('sets the created time when value is missing', ({ assert }) => {
|
|
512
|
+
const instance = new Request()
|
|
513
|
+
instance.updated = undefined
|
|
514
|
+
assert.equal(instance.updated, instance.created)
|
|
515
|
+
})
|
|
516
|
+
|
|
517
|
+
test('sets the midnight value', ({ assert }) => {
|
|
518
|
+
const instance = new Request()
|
|
519
|
+
instance.updated = 1641774295483
|
|
520
|
+
assert.typeOf(instance.midnight, 'number')
|
|
521
|
+
})
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
test.group('Models > Request > #midnight', () => {
|
|
525
|
+
test('sets the value', ({ assert }) => {
|
|
526
|
+
const instance = new Request()
|
|
527
|
+
instance.midnight = 1234
|
|
528
|
+
assert.equal(instance.midnight, 1234)
|
|
529
|
+
})
|
|
530
|
+
|
|
531
|
+
test('sets the default value when the value is missing', ({ assert }) => {
|
|
532
|
+
const instance = new Request()
|
|
533
|
+
instance[updatedSymbol] = 1641774295483
|
|
534
|
+
instance.midnight = undefined
|
|
535
|
+
assert.typeOf(instance.midnight, 'number')
|
|
536
|
+
})
|
|
537
|
+
|
|
538
|
+
test('reads the default value when not set', ({ assert }) => {
|
|
539
|
+
const instance = new Request()
|
|
540
|
+
instance[updatedSymbol] = 1641774295483
|
|
541
|
+
// @ts-expect-error Used in testing
|
|
542
|
+
instance[midnightSymbol] = undefined
|
|
543
|
+
assert.typeOf(instance.midnight, 'number')
|
|
544
|
+
})
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
test.group('Models > Request > constructor()', () => {
|
|
548
|
+
test('creates the default values', ({ assert }) => {
|
|
549
|
+
const now = Date.now()
|
|
550
|
+
const instance = new Request()
|
|
551
|
+
assert.equal(instance.kind, RequestKind)
|
|
552
|
+
|
|
553
|
+
assert.typeOf(instance.created, 'number')
|
|
554
|
+
assert.typeOf(instance.updated, 'number')
|
|
555
|
+
|
|
556
|
+
assert.approximately(instance.created, now, 100)
|
|
557
|
+
assert.approximately(instance.updated, now, 100)
|
|
558
|
+
|
|
559
|
+
const { expects, info } = instance
|
|
560
|
+
assert.typeOf(expects, 'object', 'sets the expects')
|
|
561
|
+
assert.typeOf(info, 'EventTarget', 'sets the info')
|
|
562
|
+
|
|
563
|
+
assert.equal(expects.method, 'GET')
|
|
564
|
+
assert.equal(expects.url, '')
|
|
565
|
+
assert.equal(expects.kind, HttpRequestKind)
|
|
566
|
+
|
|
567
|
+
assert.equal(info.name, '')
|
|
568
|
+
assert.equal(info.kind, ThingKind)
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
test('creates values from the schema', ({ assert }) => {
|
|
572
|
+
const now = Date.now()
|
|
573
|
+
const schema: IRequest = {
|
|
574
|
+
kind: RequestKind,
|
|
575
|
+
created: now,
|
|
576
|
+
updated: now,
|
|
577
|
+
expects: {
|
|
578
|
+
url: 'https://dot.com',
|
|
579
|
+
headers: 'x-test: true',
|
|
580
|
+
method: 'PUT',
|
|
581
|
+
},
|
|
582
|
+
info: {
|
|
583
|
+
name: 'a request',
|
|
584
|
+
kind: ThingKind,
|
|
585
|
+
},
|
|
586
|
+
}
|
|
587
|
+
const instance = new Request(schema)
|
|
588
|
+
|
|
589
|
+
assert.equal(instance.kind, RequestKind)
|
|
590
|
+
assert.equal(instance.created, now)
|
|
591
|
+
assert.equal(instance.updated, now)
|
|
592
|
+
const { expects, info } = instance
|
|
593
|
+
assert.typeOf(expects, 'object', 'sets the expects')
|
|
594
|
+
assert.typeOf(info, 'EventTarget', 'sets the info')
|
|
595
|
+
assert.equal(expects.method, 'PUT')
|
|
596
|
+
assert.equal(expects.url, 'https://dot.com')
|
|
597
|
+
assert.equal(expects.kind, HttpRequestKind)
|
|
598
|
+
|
|
599
|
+
assert.equal(info.name, 'a request')
|
|
600
|
+
assert.equal(info.kind, ThingKind)
|
|
601
|
+
})
|
|
602
|
+
|
|
603
|
+
test('creates values from the JSON schema string', ({ assert }) => {
|
|
604
|
+
const now = Date.now()
|
|
605
|
+
const schema: IRequest = {
|
|
606
|
+
kind: RequestKind,
|
|
607
|
+
created: now,
|
|
608
|
+
updated: now,
|
|
609
|
+
expects: {
|
|
610
|
+
url: 'https://dot.com',
|
|
611
|
+
headers: 'x-test: true',
|
|
612
|
+
method: 'PUT',
|
|
613
|
+
},
|
|
614
|
+
info: {
|
|
615
|
+
name: 'a request',
|
|
616
|
+
kind: ThingKind,
|
|
617
|
+
},
|
|
618
|
+
}
|
|
619
|
+
const instance = new Request(JSON.stringify(schema))
|
|
620
|
+
|
|
621
|
+
assert.equal(instance.kind, RequestKind)
|
|
622
|
+
assert.equal(instance.created, now)
|
|
623
|
+
assert.equal(instance.updated, now)
|
|
624
|
+
const { expects, info } = instance
|
|
625
|
+
assert.typeOf(expects, 'object', 'sets the expects')
|
|
626
|
+
assert.typeOf(info, 'EventTarget', 'sets the info')
|
|
627
|
+
assert.equal(expects.method, 'PUT')
|
|
628
|
+
assert.equal(expects.url, 'https://dot.com')
|
|
629
|
+
assert.equal(expects.kind, HttpRequestKind)
|
|
630
|
+
|
|
631
|
+
assert.equal(info.name, 'a request')
|
|
632
|
+
assert.equal(info.kind, ThingKind)
|
|
633
|
+
})
|
|
634
|
+
})
|
|
635
|
+
|
|
636
|
+
test.group('Models > Request > new()', (group) => {
|
|
637
|
+
let instance: Request
|
|
638
|
+
group.each.setup(() => {
|
|
639
|
+
instance = new Request()
|
|
640
|
+
})
|
|
641
|
+
|
|
642
|
+
test('sets the passed expects', ({ assert }) => {
|
|
643
|
+
const schema = instance.toJSON()
|
|
644
|
+
schema.expects.url = 'https://api.com'
|
|
645
|
+
schema.expects.method = 'PATCH'
|
|
646
|
+
schema.expects.headers = 'x-header: true'
|
|
647
|
+
schema.expects.payload = 'a message'
|
|
648
|
+
instance.new(schema)
|
|
649
|
+
|
|
650
|
+
assert.equal(instance.expects.url, 'https://api.com')
|
|
651
|
+
assert.equal(instance.expects.method, 'PATCH')
|
|
652
|
+
assert.equal(instance.expects.headers, 'x-header: true')
|
|
653
|
+
assert.equal(instance.expects.payload, 'a message')
|
|
654
|
+
})
|
|
655
|
+
|
|
656
|
+
test('sets the default expects', ({ assert }) => {
|
|
657
|
+
const schema = instance.toJSON()
|
|
658
|
+
// @ts-expect-error Used in testing
|
|
659
|
+
delete schema.expects
|
|
660
|
+
instance.new(schema)
|
|
661
|
+
|
|
662
|
+
assert.equal(instance.expects.url, '')
|
|
663
|
+
assert.equal(instance.expects.method, 'GET')
|
|
664
|
+
assert.isUndefined(instance.expects.headers)
|
|
665
|
+
assert.isUndefined(instance.expects.payload)
|
|
666
|
+
})
|
|
667
|
+
|
|
668
|
+
test('sets the passed info', ({ assert }) => {
|
|
669
|
+
const schema = instance.toJSON()
|
|
670
|
+
schema.info.name = 'a'
|
|
671
|
+
schema.info.description = 'b'
|
|
672
|
+
schema.info.version = 'c'
|
|
673
|
+
instance.new(schema)
|
|
674
|
+
|
|
675
|
+
assert.equal(instance.info.name, 'a')
|
|
676
|
+
assert.equal(instance.info.description, 'b')
|
|
677
|
+
assert.equal(instance.info.version, 'c')
|
|
678
|
+
})
|
|
679
|
+
|
|
680
|
+
test('sets the default info', ({ assert }) => {
|
|
681
|
+
const schema = instance.toJSON()
|
|
682
|
+
// @ts-expect-error Used in testing
|
|
683
|
+
delete schema.info
|
|
684
|
+
instance.new(schema)
|
|
685
|
+
|
|
686
|
+
assert.equal(instance.info.name, '')
|
|
687
|
+
assert.isUndefined(instance.info.description)
|
|
688
|
+
assert.isUndefined(instance.info.version)
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
test('sets the passed log', ({ assert }) => {
|
|
692
|
+
const schema = instance.toJSON()
|
|
693
|
+
schema.log = {
|
|
694
|
+
kind: RequestLogKind,
|
|
695
|
+
request: {
|
|
696
|
+
startTime: 1,
|
|
697
|
+
url: 'test',
|
|
698
|
+
},
|
|
699
|
+
}
|
|
700
|
+
instance.new(schema)
|
|
701
|
+
|
|
702
|
+
assert.typeOf(instance.log, 'object')
|
|
703
|
+
assert.equal(instance.log!.kind, RequestLogKind)
|
|
704
|
+
assert.typeOf(instance.log!.request, 'object')
|
|
705
|
+
assert.equal(instance.log!.request!.startTime, 1)
|
|
706
|
+
})
|
|
707
|
+
|
|
708
|
+
test('sets the log to undefined when missing', ({ assert }) => {
|
|
709
|
+
const schema = instance.toJSON()
|
|
710
|
+
schema.log = {
|
|
711
|
+
kind: RequestLogKind,
|
|
712
|
+
request: {
|
|
713
|
+
startTime: 1,
|
|
714
|
+
url: 'test',
|
|
715
|
+
},
|
|
716
|
+
}
|
|
717
|
+
instance.new(schema)
|
|
718
|
+
assert.typeOf(instance.log, 'object')
|
|
719
|
+
// now delete it and re-set.
|
|
720
|
+
delete schema.log
|
|
721
|
+
instance.new(schema)
|
|
722
|
+
assert.isUndefined(instance.log) // Corrected: schema.log was asserted, should be instance.log
|
|
723
|
+
})
|
|
724
|
+
|
|
725
|
+
test('sets the config', ({ assert }) => {
|
|
726
|
+
const schema = instance.toJSON()
|
|
727
|
+
schema.config = {
|
|
728
|
+
enabled: true,
|
|
729
|
+
kind: RequestConfigKind,
|
|
730
|
+
timeout: 10,
|
|
731
|
+
}
|
|
732
|
+
instance.new(schema)
|
|
733
|
+
|
|
734
|
+
assert.typeOf(instance.config, 'object')
|
|
735
|
+
assert.equal(instance.config!.timeout, 10)
|
|
736
|
+
})
|
|
737
|
+
|
|
738
|
+
test('sets the config to undefined when missing', ({ assert }) => {
|
|
739
|
+
const schema = instance.toJSON()
|
|
740
|
+
schema.config = {
|
|
741
|
+
enabled: true,
|
|
742
|
+
kind: RequestConfigKind,
|
|
743
|
+
timeout: 10,
|
|
744
|
+
}
|
|
745
|
+
instance.new(schema)
|
|
746
|
+
delete schema.config
|
|
747
|
+
instance.new(schema)
|
|
748
|
+
assert.isUndefined(instance.config)
|
|
749
|
+
})
|
|
750
|
+
|
|
751
|
+
test('sets the authorization', ({ assert }) => {
|
|
752
|
+
const schema = instance.toJSON()
|
|
753
|
+
schema.authorization = [
|
|
754
|
+
{
|
|
755
|
+
kind: RequestAuthorizationKind,
|
|
756
|
+
enabled: true,
|
|
757
|
+
type: 'oauth 2',
|
|
758
|
+
valid: true,
|
|
759
|
+
config: {},
|
|
760
|
+
},
|
|
761
|
+
]
|
|
762
|
+
instance.new(schema)
|
|
763
|
+
|
|
764
|
+
assert.typeOf(instance.authorization, 'array')
|
|
765
|
+
assert.equal(instance.authorization![0].type, 'oauth 2')
|
|
766
|
+
})
|
|
767
|
+
|
|
768
|
+
test('sets the authorization to undefined when missing', ({ assert }) => {
|
|
769
|
+
const schema = instance.toJSON()
|
|
770
|
+
schema.authorization = [
|
|
771
|
+
{
|
|
772
|
+
kind: RequestAuthorizationKind,
|
|
773
|
+
enabled: true,
|
|
774
|
+
type: 'oauth 2',
|
|
775
|
+
valid: true,
|
|
776
|
+
config: {},
|
|
777
|
+
},
|
|
778
|
+
]
|
|
779
|
+
instance.new(schema)
|
|
780
|
+
delete schema.authorization
|
|
781
|
+
instance.new(schema)
|
|
782
|
+
|
|
783
|
+
assert.isUndefined(instance.authorization)
|
|
784
|
+
})
|
|
785
|
+
|
|
786
|
+
test('sets the created', ({ assert }) => {
|
|
787
|
+
const schema = instance.toJSON()
|
|
788
|
+
schema.created = 1234567
|
|
789
|
+
instance.new(schema)
|
|
790
|
+
assert.equal(instance.created, 1234567)
|
|
791
|
+
})
|
|
792
|
+
|
|
793
|
+
test('sets the created as current time', ({ assert }) => {
|
|
794
|
+
const now = Date.now()
|
|
795
|
+
const schema = instance.toJSON()
|
|
796
|
+
delete schema.created
|
|
797
|
+
instance.new(schema)
|
|
798
|
+
assert.approximately(instance.created, now, 100)
|
|
799
|
+
})
|
|
800
|
+
|
|
801
|
+
test('sets the updated', ({ assert }) => {
|
|
802
|
+
const schema = instance.toJSON()
|
|
803
|
+
schema.updated = 1234567
|
|
804
|
+
instance.new(schema)
|
|
805
|
+
assert.equal(instance.updated, 1234567)
|
|
806
|
+
})
|
|
807
|
+
|
|
808
|
+
test('sets the updated to created when missing', ({ assert }) => {
|
|
809
|
+
const schema = instance.toJSON()
|
|
810
|
+
delete schema.updated
|
|
811
|
+
instance.new(schema)
|
|
812
|
+
assert.equal(instance.updated, instance.created)
|
|
813
|
+
})
|
|
814
|
+
|
|
815
|
+
test('sets the midnight', ({ assert }) => {
|
|
816
|
+
const schema = instance.toJSON()
|
|
817
|
+
schema.midnight = 1234567
|
|
818
|
+
instance.new(schema)
|
|
819
|
+
assert.equal(instance.midnight, 1234567)
|
|
820
|
+
})
|
|
821
|
+
|
|
822
|
+
test('sets the flows', ({ assert }) => {
|
|
823
|
+
const schema = instance.toJSON()
|
|
824
|
+
schema.flows = [
|
|
825
|
+
{
|
|
826
|
+
trigger: 'request',
|
|
827
|
+
condition: {
|
|
828
|
+
steps: [new ReadDataStep(FlowSourceEnum.request, '', FlowRequestDataEnum.body).toJSON()],
|
|
829
|
+
},
|
|
830
|
+
actions: [
|
|
831
|
+
{
|
|
832
|
+
steps: [],
|
|
833
|
+
},
|
|
834
|
+
],
|
|
835
|
+
},
|
|
836
|
+
]
|
|
837
|
+
instance.new(schema)
|
|
838
|
+
|
|
839
|
+
const { flows } = instance
|
|
840
|
+
assert.typeOf(flows, 'array', 'has flows')
|
|
841
|
+
|
|
842
|
+
const [flow] = flows!
|
|
843
|
+
assert.lengthOf(flow.actions, 1)
|
|
844
|
+
})
|
|
845
|
+
|
|
846
|
+
test('sets the flows to undefined when missing', ({ assert }) => {
|
|
847
|
+
const schema = instance.toJSON()
|
|
848
|
+
schema.flows = [
|
|
849
|
+
{
|
|
850
|
+
trigger: 'request',
|
|
851
|
+
condition: {
|
|
852
|
+
steps: [new ReadDataStep(FlowSourceEnum.request, '', FlowRequestDataEnum.body).toJSON()],
|
|
853
|
+
},
|
|
854
|
+
actions: [
|
|
855
|
+
{
|
|
856
|
+
steps: [],
|
|
857
|
+
},
|
|
858
|
+
],
|
|
859
|
+
},
|
|
860
|
+
]
|
|
861
|
+
instance.new(schema)
|
|
862
|
+
delete schema.flows
|
|
863
|
+
instance.new(schema)
|
|
864
|
+
|
|
865
|
+
assert.isUndefined(instance.flows)
|
|
866
|
+
})
|
|
867
|
+
|
|
868
|
+
test('sets the assertions', ({ assert }) => {
|
|
869
|
+
const schema = instance.toJSON()
|
|
870
|
+
schema.assertions = [
|
|
871
|
+
{
|
|
872
|
+
steps: [
|
|
873
|
+
{
|
|
874
|
+
kind: 'test',
|
|
875
|
+
},
|
|
876
|
+
],
|
|
877
|
+
},
|
|
878
|
+
]
|
|
879
|
+
instance.new(schema)
|
|
880
|
+
|
|
881
|
+
const { assertions } = instance
|
|
882
|
+
assert.typeOf(assertions, 'array', 'has assertions')
|
|
883
|
+
|
|
884
|
+
const [assertion] = assertions!
|
|
885
|
+
assert.lengthOf(assertion.steps, 1)
|
|
886
|
+
})
|
|
887
|
+
|
|
888
|
+
test('sets the assertions to undefined when missing', ({ assert }) => {
|
|
889
|
+
const schema = instance.toJSON()
|
|
890
|
+
schema.assertions = [
|
|
891
|
+
{
|
|
892
|
+
steps: [
|
|
893
|
+
{
|
|
894
|
+
kind: 'test',
|
|
895
|
+
},
|
|
896
|
+
],
|
|
897
|
+
},
|
|
898
|
+
]
|
|
899
|
+
instance.new(schema)
|
|
900
|
+
delete schema.assertions
|
|
901
|
+
instance.new(schema)
|
|
902
|
+
|
|
903
|
+
assert.isUndefined(instance.assertions)
|
|
904
|
+
})
|
|
905
|
+
|
|
906
|
+
test('sets the clientCertificate', ({ assert }) => {
|
|
907
|
+
const schema = instance.toJSON()
|
|
908
|
+
const cert: IP12Certificate = {
|
|
909
|
+
cert: { data: 'test' },
|
|
910
|
+
key: '123',
|
|
911
|
+
kind: 'Core#Certificate',
|
|
912
|
+
name: 'name',
|
|
913
|
+
type: 'p12',
|
|
914
|
+
created: 123456,
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
schema.clientCertificate = cert
|
|
918
|
+
instance.new(schema)
|
|
919
|
+
|
|
920
|
+
const { clientCertificate } = instance
|
|
921
|
+
assert.ok(clientCertificate, 'has clientCertificate')
|
|
922
|
+
assert.equal(clientCertificate!.kind, CertificateKind)
|
|
923
|
+
})
|
|
924
|
+
|
|
925
|
+
test('sets the clientCertificate to undefined when missing', ({ assert }) => {
|
|
926
|
+
const schema = instance.toJSON()
|
|
927
|
+
const cert: IP12Certificate = {
|
|
928
|
+
cert: { data: 'test' },
|
|
929
|
+
key: '123',
|
|
930
|
+
kind: 'Core#Certificate',
|
|
931
|
+
name: 'name',
|
|
932
|
+
type: 'p12',
|
|
933
|
+
created: 123456,
|
|
934
|
+
}
|
|
935
|
+
schema.clientCertificate = cert
|
|
936
|
+
instance.new(schema)
|
|
937
|
+
delete schema.clientCertificate
|
|
938
|
+
instance.new(schema)
|
|
939
|
+
|
|
940
|
+
assert.isUndefined(instance.clientCertificate)
|
|
941
|
+
})
|
|
942
|
+
})
|
|
943
|
+
|
|
944
|
+
test.group('Models > Request > toJSON()', (group) => {
|
|
945
|
+
let instance: Request
|
|
946
|
+
group.each.setup(() => {
|
|
947
|
+
instance = new Request()
|
|
948
|
+
})
|
|
949
|
+
|
|
950
|
+
test('sets the expects', ({ assert }) => {
|
|
951
|
+
instance.expects.url = 'https://api.com'
|
|
952
|
+
instance.expects.method = 'PATCH'
|
|
953
|
+
instance.expects.headers = 'x-header: true'
|
|
954
|
+
instance.expects.payload = 'a message'
|
|
955
|
+
|
|
956
|
+
const result = instance.toJSON()
|
|
957
|
+
|
|
958
|
+
assert.equal(result.expects.url, 'https://api.com')
|
|
959
|
+
assert.equal(result.expects.method, 'PATCH')
|
|
960
|
+
assert.equal(result.expects.headers, 'x-header: true')
|
|
961
|
+
assert.equal(result.expects.payload, 'a message')
|
|
962
|
+
})
|
|
963
|
+
|
|
964
|
+
test('sets the info', ({ assert }) => {
|
|
965
|
+
instance.info.name = 'a'
|
|
966
|
+
instance.info.description = 'b'
|
|
967
|
+
instance.info.version = 'c'
|
|
968
|
+
|
|
969
|
+
const result = instance.toJSON()
|
|
970
|
+
|
|
971
|
+
assert.equal(result.info.name, 'a')
|
|
972
|
+
assert.equal(result.info.description, 'b')
|
|
973
|
+
assert.equal(result.info.version, 'c')
|
|
974
|
+
})
|
|
975
|
+
|
|
976
|
+
test('sets the kind', ({ assert }) => {
|
|
977
|
+
const result = instance.toJSON()
|
|
978
|
+
assert.equal(result.kind, RequestKind)
|
|
979
|
+
})
|
|
980
|
+
|
|
981
|
+
test('sets the updated, created, and midnight', ({ assert }) => {
|
|
982
|
+
const now = Date.now()
|
|
983
|
+
instance.created = now
|
|
984
|
+
instance.updated = now
|
|
985
|
+
instance.midnight = 1234
|
|
986
|
+
|
|
987
|
+
const result = instance.toJSON()
|
|
988
|
+
|
|
989
|
+
assert.equal(result.created, now)
|
|
990
|
+
assert.equal(result.updated, now)
|
|
991
|
+
assert.equal(result.midnight, 1234)
|
|
992
|
+
})
|
|
993
|
+
|
|
994
|
+
test('sets the log', ({ assert }) => {
|
|
995
|
+
instance.log = new RequestLog({
|
|
996
|
+
kind: RequestLogKind,
|
|
997
|
+
request: {
|
|
998
|
+
startTime: 1,
|
|
999
|
+
url: 'test',
|
|
1000
|
+
},
|
|
1001
|
+
})
|
|
1002
|
+
|
|
1003
|
+
const result = instance.toJSON()
|
|
1004
|
+
|
|
1005
|
+
assert.typeOf(result.log, 'object')
|
|
1006
|
+
assert.equal(result.log!.kind, RequestLogKind)
|
|
1007
|
+
assert.typeOf(result.log!.request, 'object')
|
|
1008
|
+
assert.equal(result.log!.request!.startTime, 1)
|
|
1009
|
+
})
|
|
1010
|
+
|
|
1011
|
+
test('does not set the log when missing', ({ assert }) => {
|
|
1012
|
+
const result = instance.toJSON()
|
|
1013
|
+
assert.isUndefined(result.log)
|
|
1014
|
+
})
|
|
1015
|
+
|
|
1016
|
+
test('sets the config', ({ assert }) => {
|
|
1017
|
+
instance.config = new RequestConfig({
|
|
1018
|
+
enabled: true,
|
|
1019
|
+
kind: RequestConfigKind,
|
|
1020
|
+
timeout: 10,
|
|
1021
|
+
})
|
|
1022
|
+
const result = instance.toJSON()
|
|
1023
|
+
assert.typeOf(result.config, 'object')
|
|
1024
|
+
assert.equal(result.config!.timeout, 10)
|
|
1025
|
+
})
|
|
1026
|
+
|
|
1027
|
+
test('does not set the config when missing', ({ assert }) => {
|
|
1028
|
+
const result = instance.toJSON()
|
|
1029
|
+
assert.isUndefined(result.config)
|
|
1030
|
+
})
|
|
1031
|
+
|
|
1032
|
+
test('sets the authorization', ({ assert }) => {
|
|
1033
|
+
instance.authorization = [
|
|
1034
|
+
new RequestAuthorization({
|
|
1035
|
+
kind: RequestAuthorizationKind,
|
|
1036
|
+
enabled: true,
|
|
1037
|
+
type: 'oauth 2',
|
|
1038
|
+
valid: true,
|
|
1039
|
+
config: {},
|
|
1040
|
+
}),
|
|
1041
|
+
]
|
|
1042
|
+
const result = instance.toJSON()
|
|
1043
|
+
|
|
1044
|
+
assert.typeOf(result.authorization, 'array')
|
|
1045
|
+
assert.equal(result.authorization![0].type, 'oauth 2')
|
|
1046
|
+
})
|
|
1047
|
+
|
|
1048
|
+
test('does not set the authorization when missing', ({ assert }) => {
|
|
1049
|
+
const result = instance.toJSON()
|
|
1050
|
+
assert.isUndefined(result.authorization)
|
|
1051
|
+
})
|
|
1052
|
+
|
|
1053
|
+
test('sets the flows', ({ assert }) => {
|
|
1054
|
+
instance.flows = [
|
|
1055
|
+
{
|
|
1056
|
+
trigger: 'request',
|
|
1057
|
+
condition: {
|
|
1058
|
+
steps: [new ReadDataStep(FlowSourceEnum.request, '', FlowRequestDataEnum.body).toJSON()],
|
|
1059
|
+
},
|
|
1060
|
+
actions: [
|
|
1061
|
+
{
|
|
1062
|
+
steps: [],
|
|
1063
|
+
},
|
|
1064
|
+
],
|
|
1065
|
+
},
|
|
1066
|
+
]
|
|
1067
|
+
const result = instance.toJSON()
|
|
1068
|
+
const { flows } = result
|
|
1069
|
+
assert.typeOf(flows, 'array', 'has flows')
|
|
1070
|
+
|
|
1071
|
+
const [flow] = flows!
|
|
1072
|
+
assert.lengthOf(flow.actions, 1)
|
|
1073
|
+
})
|
|
1074
|
+
|
|
1075
|
+
test('does not set the flows when missing', ({ assert }) => {
|
|
1076
|
+
const result = instance.toJSON()
|
|
1077
|
+
assert.isUndefined(result.flows)
|
|
1078
|
+
})
|
|
1079
|
+
|
|
1080
|
+
test('sets the clientCertificate', ({ assert }) => {
|
|
1081
|
+
const cert: IP12Certificate = {
|
|
1082
|
+
cert: { data: 'test' },
|
|
1083
|
+
key: '123',
|
|
1084
|
+
kind: 'Core#Certificate',
|
|
1085
|
+
name: 'name',
|
|
1086
|
+
type: 'p12',
|
|
1087
|
+
created: 123456,
|
|
1088
|
+
}
|
|
1089
|
+
instance.clientCertificate = new Certificate(cert)
|
|
1090
|
+
const result = instance.toJSON()
|
|
1091
|
+
const { clientCertificate } = result
|
|
1092
|
+
assert.ok(clientCertificate, 'has clientCertificate')
|
|
1093
|
+
assert.equal(clientCertificate!.key, '123')
|
|
1094
|
+
})
|
|
1095
|
+
|
|
1096
|
+
test('sets the clientCertificate to undefined when missing', ({ assert }) => {
|
|
1097
|
+
const result = instance.toJSON()
|
|
1098
|
+
assert.isUndefined(result.clientCertificate)
|
|
1099
|
+
})
|
|
1100
|
+
})
|
|
1101
|
+
|
|
1102
|
+
test.group('Models > Request > setInfo()', (group) => {
|
|
1103
|
+
let instance: Request
|
|
1104
|
+
group.each.setup(() => {
|
|
1105
|
+
instance = new Request()
|
|
1106
|
+
})
|
|
1107
|
+
|
|
1108
|
+
test('sets the info from the schema', ({ assert }) => {
|
|
1109
|
+
instance.setInfo({
|
|
1110
|
+
kind: ThingKind,
|
|
1111
|
+
name: 'test',
|
|
1112
|
+
})
|
|
1113
|
+
assert.equal(instance.info.name, 'test')
|
|
1114
|
+
})
|
|
1115
|
+
|
|
1116
|
+
test('sets the updated', ({ assert }) => {
|
|
1117
|
+
const now = Date.now()
|
|
1118
|
+
instance.setInfo({
|
|
1119
|
+
kind: ThingKind,
|
|
1120
|
+
name: 'test',
|
|
1121
|
+
})
|
|
1122
|
+
assert.approximately(instance.updated, now, 100)
|
|
1123
|
+
})
|
|
1124
|
+
})
|
|
1125
|
+
|
|
1126
|
+
test.group('Models > Request > getExpects()', (group) => {
|
|
1127
|
+
let instance: Request
|
|
1128
|
+
group.each.setup(() => {
|
|
1129
|
+
instance = new Request()
|
|
1130
|
+
})
|
|
1131
|
+
|
|
1132
|
+
test('sets the expects object when missing', ({ assert }) => {
|
|
1133
|
+
// @ts-expect-error Used in testing
|
|
1134
|
+
delete instance.expects
|
|
1135
|
+
const result = instance.getExpects()
|
|
1136
|
+
assert.typeOf(result, 'object', 'returns an object')
|
|
1137
|
+
assert.deepEqual(result, instance.expects, 'sets the expects on the instance')
|
|
1138
|
+
})
|
|
1139
|
+
|
|
1140
|
+
test('returns the expects object', ({ assert }) => {
|
|
1141
|
+
instance.expects = new HttpRequest({
|
|
1142
|
+
kind: HttpRequestKind,
|
|
1143
|
+
url: 'domain.com',
|
|
1144
|
+
})
|
|
1145
|
+
const result = instance.getExpects()
|
|
1146
|
+
assert.deepEqual(result, instance.expects)
|
|
1147
|
+
})
|
|
1148
|
+
})
|
|
1149
|
+
|
|
1150
|
+
test.group('Models > Request > getConfig()', (group) => {
|
|
1151
|
+
let instance: Request
|
|
1152
|
+
group.each.setup(() => {
|
|
1153
|
+
instance = new Request()
|
|
1154
|
+
})
|
|
1155
|
+
|
|
1156
|
+
test('sets the config object when missing', ({ assert }) => {
|
|
1157
|
+
delete instance.config
|
|
1158
|
+
const result = instance.getConfig()
|
|
1159
|
+
assert.typeOf(result, 'object', 'returns an object')
|
|
1160
|
+
assert.deepEqual(result, instance.config, 'sets the config on the instance')
|
|
1161
|
+
})
|
|
1162
|
+
|
|
1163
|
+
test('returns the config object', ({ assert }) => {
|
|
1164
|
+
instance.config = new RequestConfig({
|
|
1165
|
+
kind: RequestConfigKind,
|
|
1166
|
+
enabled: true,
|
|
1167
|
+
})
|
|
1168
|
+
const result = instance.getConfig()
|
|
1169
|
+
assert.deepEqual(result, instance.config)
|
|
1170
|
+
})
|
|
1171
|
+
})
|
|
1172
|
+
|
|
1173
|
+
test.group('Models > Request > setLog()', (group) => {
|
|
1174
|
+
let instance: Request
|
|
1175
|
+
group.each.setup(() => {
|
|
1176
|
+
instance = new Request()
|
|
1177
|
+
})
|
|
1178
|
+
|
|
1179
|
+
test('sets the log object from the schema', ({ assert }) => {
|
|
1180
|
+
const schema = new RequestLog({
|
|
1181
|
+
kind: RequestLogKind,
|
|
1182
|
+
request: {
|
|
1183
|
+
startTime: 1,
|
|
1184
|
+
url: 'test',
|
|
1185
|
+
},
|
|
1186
|
+
}).toJSON()
|
|
1187
|
+
instance.setLog(schema)
|
|
1188
|
+
|
|
1189
|
+
assert.ok(instance.log, 'has the log')
|
|
1190
|
+
assert.equal(instance.log!.request!.url, 'test')
|
|
1191
|
+
})
|
|
1192
|
+
|
|
1193
|
+
test('sets the updated', ({ assert }) => {
|
|
1194
|
+
const schema = new RequestLog({
|
|
1195
|
+
kind: RequestLogKind,
|
|
1196
|
+
request: {
|
|
1197
|
+
startTime: 1,
|
|
1198
|
+
url: 'test',
|
|
1199
|
+
},
|
|
1200
|
+
}).toJSON()
|
|
1201
|
+
const now = Date.now()
|
|
1202
|
+
instance.setLog(schema)
|
|
1203
|
+
|
|
1204
|
+
assert.approximately(instance.updated, now, 100)
|
|
1205
|
+
})
|
|
1206
|
+
})
|