@rvoh/psychic-spec-helpers 0.7.2 → 0.7.3
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/dist/esm/spec/features/setup/hooks.js +2 -2
- package/dist/esm/src/unit/OpenapiSpecRequest.js +342 -21
- package/dist/esm/src/unit/OpenapiSpecSession.js +290 -12
- package/dist/types/src/unit/OpenapiSpecRequest.d.ts +15 -335
- package/dist/types/src/unit/OpenapiSpecSession.d.ts +8 -277
- package/package.json +1 -1
- package/src/unit/OpenapiSpecRequest.ts +98 -831
- package/src/unit/OpenapiSpecSession.ts +82 -696
|
@@ -29,8 +29,8 @@ beforeAll(async () => {
|
|
|
29
29
|
beforeEach(async () => {
|
|
30
30
|
await truncate(DreamApp);
|
|
31
31
|
await visit('/');
|
|
32
|
-
await expect(page).toMatchTextContent('My div');
|
|
33
|
-
});
|
|
32
|
+
await expect(page).toMatchTextContent('My div', { timeout: 10000 });
|
|
33
|
+
}, 15000);
|
|
34
34
|
afterAll(async () => {
|
|
35
35
|
await server.stop();
|
|
36
36
|
});
|
|
@@ -8,36 +8,357 @@ export class OpenapiSpecRequest {
|
|
|
8
8
|
PsychicServer;
|
|
9
9
|
// eslint-disable-next-line
|
|
10
10
|
server;
|
|
11
|
-
//
|
|
12
|
-
async
|
|
11
|
+
// eslint-disable-next-line
|
|
12
|
+
async init(PsychicServer) {
|
|
13
|
+
// eslint-disable-next-line
|
|
14
|
+
this.PsychicServer = PsychicServer;
|
|
15
|
+
this.server ||= await createPsychicServer(PsychicServer);
|
|
16
|
+
}
|
|
17
|
+
async get(
|
|
18
|
+
/**
|
|
19
|
+
* The uri on your background you are trying to hit.
|
|
20
|
+
* This should be a path, like '/users'.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
24
|
+
* const res = await request.get('/posts/{id}', 200, { id: '123' })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
uri,
|
|
28
|
+
/**
|
|
29
|
+
* The response status you are expecting to receive
|
|
30
|
+
* when making this request. It will need to match
|
|
31
|
+
* one of the accepted response statuses for the
|
|
32
|
+
* provided uri in your openapi types
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
36
|
+
* const res = await request.get('/posts/{id}', 200, { id: '123' })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
expectedStatus,
|
|
40
|
+
/**
|
|
41
|
+
* An object containing the path fields required to
|
|
42
|
+
* fill your uri in, as well as any additional GET
|
|
43
|
+
* arguments, like `query`, for example.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
47
|
+
* const res = await request.get(
|
|
48
|
+
* '/posts/{postId}/comments/{id}',
|
|
49
|
+
* 200,
|
|
50
|
+
* {
|
|
51
|
+
* postId: '123',
|
|
52
|
+
* id: '456',
|
|
53
|
+
* query: {
|
|
54
|
+
* ...query params here
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* )
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param opts.query - query params you want to send up. Must match the
|
|
61
|
+
* query params in the openapi document for this uri.
|
|
62
|
+
* (Optional)
|
|
63
|
+
*
|
|
64
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
65
|
+
* (Optional)
|
|
66
|
+
*/
|
|
67
|
+
opts) {
|
|
13
68
|
return (await this.makeRequest('get', fillOpenapiParams(uri, (opts || {})), expectedStatus, opts));
|
|
14
69
|
}
|
|
15
|
-
|
|
16
|
-
|
|
70
|
+
async post(
|
|
71
|
+
/**
|
|
72
|
+
* The uri on your background you are trying to hit.
|
|
73
|
+
* This should be a path, like '/users'.
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
77
|
+
* const res = await request.post('/posts/{id}', 200, { id: '123' })
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
uri,
|
|
81
|
+
/**
|
|
82
|
+
* The response status you are expecting to receive
|
|
83
|
+
* when making this request. It will need to match
|
|
84
|
+
* one of the accepted response statuses for the
|
|
85
|
+
* provided uri in your openapi types
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
89
|
+
* const res = await request.post('/posts/{id}', 200, { id: '123' })
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
expectedStatus,
|
|
93
|
+
/**
|
|
94
|
+
* An object containing the path fields required to
|
|
95
|
+
* fill your uri in, as well as any additional POST
|
|
96
|
+
* arguments, like `data`, for example.
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
100
|
+
* const res = await request.post(
|
|
101
|
+
* '/posts/{postId}/comments/{id}',
|
|
102
|
+
* 200,
|
|
103
|
+
* {
|
|
104
|
+
* postId: '123',
|
|
105
|
+
* commentId: '456',
|
|
106
|
+
* data: {
|
|
107
|
+
* ...request body here
|
|
108
|
+
* },
|
|
109
|
+
* headers: {
|
|
110
|
+
* ...headers here
|
|
111
|
+
* },
|
|
112
|
+
* }
|
|
113
|
+
* )
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
117
|
+
* requestBody shape in the openapi document for this uri.
|
|
118
|
+
* (Optional)
|
|
119
|
+
*
|
|
120
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
121
|
+
* (Optional)
|
|
122
|
+
*/
|
|
123
|
+
opts) {
|
|
17
124
|
return await this.makeRequest('post', uri, expectedStatus, opts);
|
|
18
125
|
}
|
|
19
|
-
|
|
20
|
-
|
|
126
|
+
async put(
|
|
127
|
+
/**
|
|
128
|
+
* The uri on your background you are trying to hit.
|
|
129
|
+
* This should be a path, like '/users'.
|
|
130
|
+
*
|
|
131
|
+
* ```ts
|
|
132
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
133
|
+
* const res = await request.put('/posts/{id}', 200, { id: '123', data: { name: 'new name' }})
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
uri,
|
|
137
|
+
/**
|
|
138
|
+
* The response status you are expecting to receive
|
|
139
|
+
* when making this request. It will need to match
|
|
140
|
+
* one of the accepted response statuses for the
|
|
141
|
+
* provided uri in your openapi types
|
|
142
|
+
*
|
|
143
|
+
* ```ts
|
|
144
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
145
|
+
* const res = await request.put('/posts/{id}', 200, { id: '123', data: { name: 'new name' }})
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
expectedStatus,
|
|
149
|
+
/**
|
|
150
|
+
* An object containing the path fields required to
|
|
151
|
+
* fill your uri in, as well as any additional PUT
|
|
152
|
+
* arguments, like `data`, for example.
|
|
153
|
+
*
|
|
154
|
+
* ```ts
|
|
155
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
156
|
+
* const res = await request.put(
|
|
157
|
+
* '/posts/{id}/comments/{commentId}',
|
|
158
|
+
* 200,
|
|
159
|
+
* {
|
|
160
|
+
* postId: '123',
|
|
161
|
+
* id: '456',
|
|
162
|
+
*
|
|
163
|
+
* data: {
|
|
164
|
+
* ...request body here
|
|
165
|
+
* },
|
|
166
|
+
* headers: {
|
|
167
|
+
* ...headers here
|
|
168
|
+
* },
|
|
169
|
+
* }
|
|
170
|
+
* )
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
174
|
+
* requestBody shape in the openapi document for this uri.
|
|
175
|
+
* (Optional)
|
|
176
|
+
*
|
|
177
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
178
|
+
* (Optional)
|
|
179
|
+
*/
|
|
180
|
+
opts) {
|
|
21
181
|
return await this.makeRequest('put', fillOpenapiParams(uri, opts || {}), expectedStatus, opts);
|
|
22
182
|
}
|
|
23
|
-
|
|
24
|
-
|
|
183
|
+
async patch(
|
|
184
|
+
/**
|
|
185
|
+
* The uri on your background you are trying to hit.
|
|
186
|
+
* This should be a path, like '/posts'.
|
|
187
|
+
*
|
|
188
|
+
* ```ts
|
|
189
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
190
|
+
* const res = await request.patch('/posts/{id}', 200, { data: { name: 'new name' }})
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
uri,
|
|
194
|
+
/**
|
|
195
|
+
* The response status you are expecting to receive
|
|
196
|
+
* when making this request. It will need to match
|
|
197
|
+
* one of the accepted response statuses for the
|
|
198
|
+
* provided uri in your openapi types
|
|
199
|
+
*
|
|
200
|
+
* ```ts
|
|
201
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
202
|
+
* const res = await request.patch('/posts/{id}', 200, { data: { name: 'new name' }})
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
expectedStatus,
|
|
206
|
+
/**
|
|
207
|
+
* An object containing the path fields required to
|
|
208
|
+
* fill your uri in, as well as any additional PATCH
|
|
209
|
+
* arguments, like `data`, for example.
|
|
210
|
+
*
|
|
211
|
+
* ```ts
|
|
212
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
213
|
+
* const res = await request.patch(
|
|
214
|
+
* '/posts/{postId}/comments/{id}',
|
|
215
|
+
* 200,
|
|
216
|
+
* {
|
|
217
|
+
* postId: '123',
|
|
218
|
+
* commentId: '456',
|
|
219
|
+
* data: {
|
|
220
|
+
* ...request body here
|
|
221
|
+
* },
|
|
222
|
+
* headers: {
|
|
223
|
+
* ...headers here
|
|
224
|
+
* },
|
|
225
|
+
* }
|
|
226
|
+
* )
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
230
|
+
* requestBody shape in the openapi document for this uri.
|
|
231
|
+
* (Optional)
|
|
232
|
+
*
|
|
233
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
234
|
+
* (Optional)
|
|
235
|
+
*/
|
|
236
|
+
opts) {
|
|
25
237
|
return await this.makeRequest('patch', fillOpenapiParams(uri, opts), expectedStatus, opts);
|
|
26
238
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
239
|
+
async delete(
|
|
240
|
+
/**
|
|
241
|
+
* The uri on your background you are trying to hit.
|
|
242
|
+
* This should be a path, like '/users'.
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
246
|
+
* const res = await request.delete('/posts/{id}', 200, { id: '123' })
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
uri,
|
|
250
|
+
/**
|
|
251
|
+
* The response status you are expecting to receive
|
|
252
|
+
* when making this request. It will need to match
|
|
253
|
+
* one of the accepted response statuses for the
|
|
254
|
+
* provided uri in your openapi types
|
|
255
|
+
*
|
|
256
|
+
* ```ts
|
|
257
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
258
|
+
* const res = await request.delete('/posts/{id}', 200, { id: '123' })
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
expectedStatus,
|
|
262
|
+
/**
|
|
263
|
+
* An object containing the path fields required to
|
|
264
|
+
* fill your uri in, as well as any additional DELETE
|
|
265
|
+
* arguments, like `data`, for example.
|
|
266
|
+
*
|
|
267
|
+
* ```ts
|
|
268
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
269
|
+
* const res = await request.delete(
|
|
270
|
+
* '/posts/{postId}/comments/{commentId}',
|
|
271
|
+
* 200,
|
|
272
|
+
* {
|
|
273
|
+
* postId: '123',
|
|
274
|
+
* commentId: '456',
|
|
275
|
+
* data: {
|
|
276
|
+
* ...request body here
|
|
277
|
+
* },
|
|
278
|
+
* headers: {
|
|
279
|
+
* ...headers here
|
|
280
|
+
* },
|
|
281
|
+
* }
|
|
282
|
+
* )
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
286
|
+
* requestBody shape in the openapi document for this uri.
|
|
287
|
+
* (Optional)
|
|
288
|
+
*
|
|
289
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
290
|
+
* (Optional)
|
|
291
|
+
*/
|
|
292
|
+
opts) {
|
|
293
|
+
return await this.makeRequest('delete', fillOpenapiParams(uri, opts || {}), expectedStatus, opts);
|
|
36
294
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
295
|
+
async session(httpMethod,
|
|
296
|
+
/**
|
|
297
|
+
* The uri on your background you are trying to hit.
|
|
298
|
+
* This should be a path, like '/users'.
|
|
299
|
+
*
|
|
300
|
+
* ```ts
|
|
301
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
302
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: '123' })
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
uri,
|
|
306
|
+
/**
|
|
307
|
+
* The response status you are expecting to receive
|
|
308
|
+
* when making this request. It will need to match
|
|
309
|
+
* one of the accepted response statuses for the
|
|
310
|
+
* provided uri in your openapi types
|
|
311
|
+
*
|
|
312
|
+
* ```ts
|
|
313
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
314
|
+
* const session = await request.session('post', '/sessions/{token}', 200, { token: '123' })
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
expectedStatus,
|
|
318
|
+
/**
|
|
319
|
+
* An object containing the path fields required to
|
|
320
|
+
* fill your uri in, as well as any additional
|
|
321
|
+
* arguments, for the chosen HTTP verb, like `data`,
|
|
322
|
+
* for example.
|
|
323
|
+
*
|
|
324
|
+
* ```ts
|
|
325
|
+
* const request = new OpenapiSpecRequest<openapiPaths>()
|
|
326
|
+
* const res = await request.session(
|
|
327
|
+
* 'post',
|
|
328
|
+
* '/sessions/{token}',
|
|
329
|
+
* 200,
|
|
330
|
+
* {
|
|
331
|
+
* token: '123',
|
|
332
|
+
*
|
|
333
|
+
* // if non-get
|
|
334
|
+
* data: {
|
|
335
|
+
* ...request body here
|
|
336
|
+
* },
|
|
337
|
+
* // if get
|
|
338
|
+
* query: {
|
|
339
|
+
* ...request body here
|
|
340
|
+
* },
|
|
341
|
+
* headers: {
|
|
342
|
+
* ...headers here
|
|
343
|
+
* },
|
|
344
|
+
* }
|
|
345
|
+
* )
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* @param opts.data - request body data you want to send up. Must match the
|
|
349
|
+
* requestBody shape in the openapi document for this uri.
|
|
350
|
+
* (Optional)
|
|
351
|
+
*
|
|
352
|
+
* @param opts.query - query params you want to send up. Must match the
|
|
353
|
+
* query parameters in the openapi document for this uri.
|
|
354
|
+
* (Optional)
|
|
355
|
+
*
|
|
356
|
+
* @param opts.headers - headers you would like to send with your request.
|
|
357
|
+
* (Optional)
|
|
358
|
+
*/
|
|
359
|
+
opts) {
|
|
360
|
+
const postOpts = (opts || {});
|
|
361
|
+
const getOpts = (opts || {});
|
|
41
362
|
uri = fillOpenapiParams(uri, (opts || {}));
|
|
42
363
|
return await new Promise((accept, reject) => {
|
|
43
364
|
createPsychicServer(this.PsychicServer)
|