@trayio/cdk-runtime 4.29.0 → 4.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationExecutionGateway.unit.test.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionGateway.unit.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OperationExecutionGateway.unit.test.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionGateway.unit.test.ts"],"names":[],"mappings":"AAiCA,OAAO,8BAA8B,CAAC"}
|
|
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
29
|
const stream_1 = require("stream");
|
|
27
30
|
const O = __importStar(require("fp-ts/Option"));
|
|
@@ -29,6 +32,7 @@ const T = __importStar(require("fp-ts/Task"));
|
|
|
29
32
|
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
30
33
|
const querystring = __importStar(require("querystring"));
|
|
31
34
|
const function_1 = require("fp-ts/function");
|
|
35
|
+
const just_permutations_1 = __importDefault(require("just-permutations"));
|
|
32
36
|
const OperationHandlerSetup_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandlerSetup");
|
|
33
37
|
const OperationHandlerTest_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandlerTest");
|
|
34
38
|
const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
|
|
@@ -160,6 +164,25 @@ class TestControllerHttp {
|
|
|
160
164
|
];
|
|
161
165
|
}
|
|
162
166
|
const testHttpController = new ExpressHttpController_1.ExpressHttpController(new TestControllerHttp(), '/tmp', O.none);
|
|
167
|
+
function permutativeTest(configMethods, setupMethod, callback) {
|
|
168
|
+
const configMethodPermutations = (0, just_permutations_1.default)(configMethods);
|
|
169
|
+
configMethodPermutations.forEach((configMethodPermutation) => {
|
|
170
|
+
const configMethodOrderNames = [];
|
|
171
|
+
const operationToExecute = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => {
|
|
172
|
+
let configuredHandler = handler;
|
|
173
|
+
configMethodPermutation.forEach((configMethodPair) => {
|
|
174
|
+
configMethodOrderNames.push(configMethodPair.method);
|
|
175
|
+
configuredHandler = configuredHandler[configMethodPair.method](
|
|
176
|
+
// @ts-ignore: A spread argument must either have a tuple type or be passed to a rest parameter.
|
|
177
|
+
...configMethodPair.input);
|
|
178
|
+
});
|
|
179
|
+
return configuredHandler[setupMethod.method](
|
|
180
|
+
// @ts-ignore: A spread argument must either have a tuple type or be passed to a rest parameter.
|
|
181
|
+
...setupMethod.input);
|
|
182
|
+
});
|
|
183
|
+
callback(operationToExecute, configMethodOrderNames.join('->'));
|
|
184
|
+
});
|
|
185
|
+
}
|
|
163
186
|
describe('OperationExecutionGateway', () => {
|
|
164
187
|
let server;
|
|
165
188
|
beforeAll(() => {
|
|
@@ -200,35 +223,51 @@ describe('OperationExecutionGateway', () => {
|
|
|
200
223
|
});
|
|
201
224
|
describe('set a baseUrl via globalConfig', () => {
|
|
202
225
|
const globalConfig = OperationGlobalConfig_1.OperationGlobalConfigHttp.create().withBaseUrl(() => 'http://localhost:3000');
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
permutativeTest([
|
|
227
|
+
{
|
|
228
|
+
method: 'withGlobalConfiguration',
|
|
229
|
+
input: [globalConfig],
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
method: 'addInputValidation',
|
|
233
|
+
input: [
|
|
234
|
+
(inputValidation) => inputValidation
|
|
235
|
+
.condition((_ctx, input) => input.id > 0)
|
|
236
|
+
.errorMessage(() => 'id must be bigger than zero'),
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
], {
|
|
240
|
+
method: 'usingHttp',
|
|
241
|
+
input: [
|
|
242
|
+
(http) => http
|
|
243
|
+
.get('/posts/:id')
|
|
244
|
+
.handleRequest((_ctx, input, request) => request
|
|
245
|
+
.addPathParameter('id', input.id.toString())
|
|
246
|
+
.withoutBody())
|
|
247
|
+
.handleResponse((_ctx, _input, response) => response.parseWithBodyAsJson()),
|
|
248
|
+
],
|
|
249
|
+
}, (getProductOperation, identifier) => {
|
|
250
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
|
|
251
|
+
.usingHandlerContext('test')
|
|
252
|
+
.nothingBeforeAll()
|
|
253
|
+
.testCase(`should get a product - ${identifier}`, (testCase) => testCase
|
|
254
|
+
.usingHandlerContext('test')
|
|
255
|
+
.givenNothing()
|
|
256
|
+
.when(() => ({ id: 2 }))
|
|
257
|
+
.then(({ output }) => {
|
|
258
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
259
|
+
expect(outputValue.id).toEqual(2);
|
|
260
|
+
})
|
|
261
|
+
.finallyDoNothing())
|
|
262
|
+
.testCase(`should validate id - ${identifier}`, (testCase) => testCase
|
|
263
|
+
.givenNothing()
|
|
264
|
+
.when(() => ({ id: -1 }))
|
|
265
|
+
.then(({ output }) => {
|
|
266
|
+
expect(output.isFailure).toBe(true);
|
|
267
|
+
})
|
|
268
|
+
.finallyDoNothing())
|
|
269
|
+
.nothingAfterAll());
|
|
270
|
+
});
|
|
232
271
|
});
|
|
233
272
|
describe('set a bearer token via globalConfig', () => {
|
|
234
273
|
const globalConfig = OperationGlobalConfig_1.OperationGlobalConfigHttp.create()
|
|
@@ -275,6 +314,55 @@ describe('OperationExecutionGateway', () => {
|
|
|
275
314
|
.finallyDoNothing())
|
|
276
315
|
.nothingAfterAll());
|
|
277
316
|
});
|
|
317
|
+
describe('config method order is agnostic', () => {
|
|
318
|
+
const globalConfig = OperationGlobalConfig_1.OperationGlobalConfigHttp.create().withBaseUrl(() => 'http://localhost:3000');
|
|
319
|
+
permutativeTest([
|
|
320
|
+
{
|
|
321
|
+
method: 'withGlobalConfiguration',
|
|
322
|
+
input: [globalConfig],
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
method: 'addInputValidation',
|
|
326
|
+
input: [
|
|
327
|
+
(inputValidation) => inputValidation
|
|
328
|
+
.condition((_ctx, input) => input.id > 0)
|
|
329
|
+
.errorMessage(() => 'id must be bigger than zero'),
|
|
330
|
+
],
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
method: 'addOutputValidation',
|
|
334
|
+
input: [
|
|
335
|
+
(outputValidation) => outputValidation
|
|
336
|
+
.condition((_ctx, output) => output.id > 0)
|
|
337
|
+
.errorMessage(() => 'id must be bigger than zero'),
|
|
338
|
+
],
|
|
339
|
+
},
|
|
340
|
+
], {
|
|
341
|
+
method: 'usingHttp',
|
|
342
|
+
input: [
|
|
343
|
+
(http) => http
|
|
344
|
+
.get('/posts/:id')
|
|
345
|
+
.handleRequest((_ctx, input, request) => request
|
|
346
|
+
.addPathParameter('id', input.id.toString())
|
|
347
|
+
.withoutBody())
|
|
348
|
+
.handleResponse((_ctx, _input, response) => response.parseWithBodyAsJson()),
|
|
349
|
+
],
|
|
350
|
+
}, (getProductOperation, identifier) => {
|
|
351
|
+
OperationHandlerTest_1.OperationHandlerTestSetup.configureHandlerTest(getProductOperation, (handlerTest) => handlerTest
|
|
352
|
+
.usingHandlerContext('test')
|
|
353
|
+
.nothingBeforeAll()
|
|
354
|
+
.testCase(`should get a product with permutation: ${identifier}`, (testCase) => testCase
|
|
355
|
+
.usingHandlerContext('test')
|
|
356
|
+
.givenNothing()
|
|
357
|
+
.when(() => ({ id: 2 }))
|
|
358
|
+
.then(({ output }) => {
|
|
359
|
+
const outputValue = OperationHandler_1.OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
360
|
+
expect(outputValue.id).toEqual(2);
|
|
361
|
+
})
|
|
362
|
+
.finallyDoNothing())
|
|
363
|
+
.nothingAfterAll());
|
|
364
|
+
});
|
|
365
|
+
});
|
|
278
366
|
describe('get a product as text', () => {
|
|
279
367
|
const getProductOperationAsText = OperationHandlerSetup_1.OperationHandlerSetup.configureHandler((handler) => handler
|
|
280
368
|
.addInputValidation((inputValidation) => inputValidation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/cdk-runtime",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.31.0",
|
|
4
4
|
"description": "A Runtime that executes connector operations defined using the CDK DSL",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"node": ">=18.x"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@trayio/axios": "4.
|
|
18
|
-
"@trayio/cdk-dsl": "4.
|
|
19
|
-
"@trayio/express": "4.
|
|
20
|
-
"@trayio/winston": "4.
|
|
17
|
+
"@trayio/axios": "4.31.0",
|
|
18
|
+
"@trayio/cdk-dsl": "4.31.0",
|
|
19
|
+
"@trayio/express": "4.31.0",
|
|
20
|
+
"@trayio/winston": "4.31.0",
|
|
21
21
|
"mime": "3.0.0",
|
|
22
22
|
"uuid": "9.0.0"
|
|
23
23
|
},
|
|
@@ -31,5 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"/dist"
|
|
34
|
-
]
|
|
34
|
+
],
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"just-permutations": "^2.2.1"
|
|
37
|
+
}
|
|
35
38
|
}
|