@trayio/tray-openapi 2.6.0 → 2.8.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.
- package/dist/OpenApiSchemaImporter.d.ts +4 -2
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +49 -22
- package/dist/OpenApiSchemaImporter.test.js +58 -4
- package/dist/OpenApiTypeDescriptors.d.ts +10 -5
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +11 -1
- package/dist/ResolveOptionValues.d.ts +3 -0
- package/dist/ResolveOptionValues.d.ts.map +1 -0
- package/dist/{connector/input/TransformInput.js → ResolveOptionValues.js} +16 -27
- package/dist/ResolveOptionValues.test.d.ts +2 -0
- package/dist/ResolveOptionValues.test.d.ts.map +1 -0
- package/dist/ResolveOptionValues.test.js +91 -0
- package/dist/{GenerateHandler.d.ts → file-generators/GenerateHandler.d.ts} +2 -7
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -0
- package/dist/{GenerateHandler.js → file-generators/GenerateHandler.js} +53 -16
- package/dist/file-generators/GenerateHandler.test.d.ts +2 -0
- package/dist/file-generators/GenerateHandler.test.d.ts.map +1 -0
- package/dist/{GenerateHander.test.js → file-generators/GenerateHandler.test.js} +119 -33
- package/dist/file-generators/GenerateHandlerTest.d.ts +9 -0
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandlerTest.js +76 -0
- package/dist/file-generators/GenerateHandlerTest.test.d.ts +2 -0
- package/dist/file-generators/GenerateHandlerTest.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandlerTest.test.js +355 -0
- package/dist/file-generators/GenerateOperationJson.d.ts +4 -0
- package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -0
- package/dist/file-generators/GenerateOperationJson.js +43 -0
- package/dist/file-generators/GenerateOperationJson.test.d.ts +2 -0
- package/dist/file-generators/GenerateOperationJson.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateOperationJson.test.js +77 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts +4 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -0
- package/dist/{connector/input/ProcessInput.js → file-generators/types/GenerateInputSchema.js} +31 -14
- package/dist/file-generators/types/GenerateInputSchema.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateInputSchema.test.d.ts.map +1 -0
- package/dist/{connector/input/ProcessInput.test.js → file-generators/types/GenerateInputSchema.test.js} +25 -14
- package/dist/file-generators/types/GenerateInputTypes.d.ts +4 -0
- package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputTypes.js +39 -0
- package/dist/file-generators/types/GenerateOutput.d.ts +9 -0
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateOutput.js +54 -0
- package/dist/file-generators/types/GenerateOutput.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateOutput.test.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateOutput.test.js +197 -0
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts.map +1 -0
- package/package.json +4 -2
- package/dist/GenerateHander.test.d.ts +0 -2
- package/dist/GenerateHander.test.d.ts.map +0 -1
- package/dist/GenerateHandler.d.ts.map +0 -1
- package/dist/connector/JsonSchemaToTypescriptOptions.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.d.ts +0 -8
- package/dist/connector/input/GenerateInput.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.js +0 -8
- package/dist/connector/input/GenerateInput.test.d.ts +0 -2
- package/dist/connector/input/GenerateInput.test.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.test.js +0 -133
- package/dist/connector/input/ProcessInput.d.ts +0 -4
- package/dist/connector/input/ProcessInput.d.ts.map +0 -1
- package/dist/connector/input/ProcessInput.test.d.ts +0 -2
- package/dist/connector/input/ProcessInput.test.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.d.ts +0 -4
- package/dist/connector/input/TransformInput.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.test.d.ts +0 -2
- package/dist/connector/input/TransformInput.test.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.test.js +0 -75
- /package/dist/{connector → file-generators/types}/JsonSchemaToTypescriptOptions.d.ts +0 -0
- /package/dist/{connector → file-generators/types}/JsonSchemaToTypescriptOptions.js +0 -0
|
@@ -25,13 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const E = __importStar(require("fp-ts/Either"));
|
|
27
27
|
const GenerateHandler_1 = require("./GenerateHandler");
|
|
28
|
-
const getGenerateHandlerInput = (input) => (Object.assign({ connectorNamePascalCase: 'OpenApiTest', operationNamePascalCase: 'GetPhoto', operationNameCamelCase: 'getPhoto', httpMethod: 'get', baseUrl: 'https://jsonplaceholder.typicode.com
|
|
28
|
+
const getGenerateHandlerInput = (input) => (Object.assign({ connectorNamePascalCase: 'OpenApiTest', operationNamePascalCase: 'GetPhoto', operationNameCamelCase: 'getPhoto', httpMethod: 'get', baseUrl: 'https://jsonplaceholder.typicode.com', input: { properties: {} }, path: '/photos' }, input));
|
|
29
29
|
describe('GenerateHandler', () => {
|
|
30
|
-
it('it should generate a handler', () => {
|
|
30
|
+
it('it should generate a handler with no inputs', () => {
|
|
31
31
|
const payload = getGenerateHandlerInput({});
|
|
32
32
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
33
33
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
34
|
-
import {
|
|
34
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
35
35
|
import { GetPhotoInput } from "./input";
|
|
36
36
|
import { GetPhotoOutput } from "./output";
|
|
37
37
|
|
|
@@ -43,17 +43,25 @@ describe('GenerateHandler', () => {
|
|
|
43
43
|
handler.usingHttp((http) =>
|
|
44
44
|
http
|
|
45
45
|
.get("https://jsonplaceholder.typicode.com/photos")
|
|
46
|
-
.handleRequest((ctx, input, request) => request)
|
|
47
|
-
.handleResponse((response) => response.parseWithBodyAsJson())
|
|
46
|
+
.handleRequest((ctx, input, request) => request.withoutBody())
|
|
47
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
48
48
|
)
|
|
49
49
|
);`)).toEqual(generatedHandler);
|
|
50
50
|
});
|
|
51
51
|
it('it should generate a handler with a path parameter', () => {
|
|
52
|
-
const input =
|
|
53
|
-
|
|
52
|
+
const input = {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: { photoId: { type: 'string', in: 'path' } },
|
|
55
|
+
required: ['photoId'],
|
|
56
|
+
additionalProperties: false,
|
|
57
|
+
};
|
|
58
|
+
const payload = getGenerateHandlerInput({
|
|
59
|
+
input,
|
|
60
|
+
path: '/photos/{photoId}',
|
|
61
|
+
});
|
|
54
62
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
55
63
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
56
|
-
import {
|
|
64
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
57
65
|
import { GetPhotoInput } from "./input";
|
|
58
66
|
import { GetPhotoOutput } from "./output";
|
|
59
67
|
|
|
@@ -65,17 +73,22 @@ describe('GenerateHandler', () => {
|
|
|
65
73
|
handler.usingHttp((http) =>
|
|
66
74
|
http
|
|
67
75
|
.get("https://jsonplaceholder.typicode.com/photos/:photoId")
|
|
68
|
-
.handleRequest((ctx, input, request) => request.addPathParameter("photoId", input.photoId))
|
|
69
|
-
.handleResponse((response) => response.parseWithBodyAsJson())
|
|
76
|
+
.handleRequest((ctx, input, request) => request.addPathParameter("photoId", input.photoId).withoutBody())
|
|
77
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
70
78
|
)
|
|
71
79
|
);`)).toEqual(generatedHandler);
|
|
72
80
|
});
|
|
73
81
|
it('it should generate a handler with a body input as json', () => {
|
|
74
|
-
const input =
|
|
82
|
+
const input = {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: { photoId: { type: 'string', in: 'body' } },
|
|
85
|
+
required: ['photoId'],
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
};
|
|
75
88
|
const payload = getGenerateHandlerInput({ input });
|
|
76
89
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
77
90
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
78
|
-
import {
|
|
91
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
79
92
|
import { GetPhotoInput } from "./input";
|
|
80
93
|
import { GetPhotoOutput } from "./output";
|
|
81
94
|
|
|
@@ -87,17 +100,22 @@ describe('GenerateHandler', () => {
|
|
|
87
100
|
handler.usingHttp((http) =>
|
|
88
101
|
http
|
|
89
102
|
.get("https://jsonplaceholder.typicode.com/photos")
|
|
90
|
-
.handleRequest((ctx, input, request) => request.withBodyAsJson(input))
|
|
91
|
-
.handleResponse((response) => response.parseWithBodyAsJson())
|
|
103
|
+
.handleRequest((ctx, input, request) => request.withBodyAsJson({ photoId: input.photoId }))
|
|
104
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
92
105
|
)
|
|
93
106
|
);`)).toEqual(generatedHandler);
|
|
94
107
|
});
|
|
95
108
|
it('it should generate a handler with a query string input', () => {
|
|
96
|
-
const input =
|
|
109
|
+
const input = {
|
|
110
|
+
type: 'object',
|
|
111
|
+
properties: { id: { type: 'string', in: 'query' } },
|
|
112
|
+
required: ['id'],
|
|
113
|
+
additionalProperties: false,
|
|
114
|
+
};
|
|
97
115
|
const payload = getGenerateHandlerInput({ input });
|
|
98
116
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
99
117
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
100
|
-
import {
|
|
118
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
101
119
|
import { GetPhotoInput } from "./input";
|
|
102
120
|
import { GetPhotoOutput } from "./output";
|
|
103
121
|
|
|
@@ -109,19 +127,22 @@ describe('GenerateHandler', () => {
|
|
|
109
127
|
handler.usingHttp((http) =>
|
|
110
128
|
http
|
|
111
129
|
.get("https://jsonplaceholder.typicode.com/photos")
|
|
112
|
-
.handleRequest((ctx, input, request) => request.addQueryString("id", input.id))
|
|
113
|
-
.handleResponse((response) => response.parseWithBodyAsJson())
|
|
130
|
+
.handleRequest((ctx, input, request) => request.addQueryString("id", input.id).withoutBody())
|
|
131
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
114
132
|
)
|
|
115
133
|
);`)).toEqual(generatedHandler);
|
|
116
134
|
});
|
|
117
135
|
it('it should generate a handler with a header input', () => {
|
|
118
|
-
const input =
|
|
119
|
-
|
|
120
|
-
|
|
136
|
+
const input = {
|
|
137
|
+
type: 'object',
|
|
138
|
+
properties: { 'Content-Type': { type: 'string', in: 'header' } },
|
|
139
|
+
required: ['photoId'],
|
|
140
|
+
additionalProperties: false,
|
|
141
|
+
};
|
|
121
142
|
const payload = getGenerateHandlerInput({ input });
|
|
122
143
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
123
144
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
124
|
-
import {
|
|
145
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
125
146
|
import { GetPhotoInput } from "./input";
|
|
126
147
|
import { GetPhotoOutput } from "./output";
|
|
127
148
|
|
|
@@ -133,21 +154,56 @@ describe('GenerateHandler', () => {
|
|
|
133
154
|
handler.usingHttp((http) =>
|
|
134
155
|
http
|
|
135
156
|
.get("https://jsonplaceholder.typicode.com/photos")
|
|
136
|
-
.handleRequest((ctx, input, request) => request.addHeader("Content-Type", input.Content-Type))
|
|
137
|
-
.handleResponse((response) => response.parseWithBodyAsJson())
|
|
157
|
+
.handleRequest((ctx, input, request) => request.addHeader("Content-Type", input.Content-Type).withoutBody())
|
|
158
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
138
159
|
)
|
|
139
160
|
);`)).toEqual(generatedHandler);
|
|
140
161
|
});
|
|
141
|
-
it('it should generate a handler
|
|
142
|
-
const input =
|
|
143
|
-
|
|
144
|
-
{
|
|
145
|
-
|
|
146
|
-
|
|
162
|
+
it('it should generate a handler and transform number type to string for input', () => {
|
|
163
|
+
const input = {
|
|
164
|
+
type: 'object',
|
|
165
|
+
properties: { 'Content-Type': { type: 'integer', in: 'header' } },
|
|
166
|
+
required: ['photoId'],
|
|
167
|
+
additionalProperties: false,
|
|
168
|
+
};
|
|
147
169
|
const payload = getGenerateHandlerInput({ input });
|
|
148
170
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
149
171
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
150
|
-
import {
|
|
172
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
173
|
+
import { GetPhotoInput } from "./input";
|
|
174
|
+
import { GetPhotoOutput } from "./output";
|
|
175
|
+
|
|
176
|
+
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
177
|
+
OpenApiTestAuth,
|
|
178
|
+
GetPhotoInput,
|
|
179
|
+
GetPhotoOutput
|
|
180
|
+
>((handler) =>
|
|
181
|
+
handler.usingHttp((http) =>
|
|
182
|
+
http
|
|
183
|
+
.get("https://jsonplaceholder.typicode.com/photos")
|
|
184
|
+
.handleRequest((ctx, input, request) => request.addHeader("Content-Type", input.Content-Type.toString()).withoutBody())
|
|
185
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
186
|
+
)
|
|
187
|
+
);`)).toEqual(generatedHandler);
|
|
188
|
+
});
|
|
189
|
+
it('it should generate a handler with a query string and path param input', () => {
|
|
190
|
+
const input = {
|
|
191
|
+
type: 'object',
|
|
192
|
+
properties: {
|
|
193
|
+
id: { type: 'string', in: 'query' },
|
|
194
|
+
photoId: { type: 'string', in: 'path' },
|
|
195
|
+
commentId: { type: 'string', in: 'path' },
|
|
196
|
+
},
|
|
197
|
+
required: ['photoId'],
|
|
198
|
+
additionalProperties: false,
|
|
199
|
+
};
|
|
200
|
+
const payload = getGenerateHandlerInput({
|
|
201
|
+
input,
|
|
202
|
+
path: '/photos/{photoId}/{commentId}',
|
|
203
|
+
});
|
|
204
|
+
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
205
|
+
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
206
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
151
207
|
import { GetPhotoInput } from "./input";
|
|
152
208
|
import { GetPhotoOutput } from "./output";
|
|
153
209
|
|
|
@@ -159,8 +215,38 @@ describe('GenerateHandler', () => {
|
|
|
159
215
|
handler.usingHttp((http) =>
|
|
160
216
|
http
|
|
161
217
|
.get("https://jsonplaceholder.typicode.com/photos/:photoId/:commentId")
|
|
162
|
-
.handleRequest((ctx, input, request) => request.addQueryString("id", input.id).addPathParameter("photoId", input.photoId).addPathParameter("commentId", input.commentId))
|
|
163
|
-
.handleResponse((response) => response.parseWithBodyAsJson())
|
|
218
|
+
.handleRequest((ctx, input, request) => request.addQueryString("id", input.id).addPathParameter("photoId", input.photoId).addPathParameter("commentId", input.commentId).withoutBody())
|
|
219
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
220
|
+
)
|
|
221
|
+
);`)).toEqual(generatedHandler);
|
|
222
|
+
});
|
|
223
|
+
it('it should generate a handler with a query string and body param input', () => {
|
|
224
|
+
const input = {
|
|
225
|
+
type: 'object',
|
|
226
|
+
properties: {
|
|
227
|
+
id: { type: 'string', in: 'query' },
|
|
228
|
+
photoId: { type: 'string', in: 'body' },
|
|
229
|
+
},
|
|
230
|
+
required: ['id', 'photoId'],
|
|
231
|
+
additionalProperties: false,
|
|
232
|
+
};
|
|
233
|
+
const payload = getGenerateHandlerInput({ input });
|
|
234
|
+
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
235
|
+
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
236
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
237
|
+
import { GetPhotoInput } from "./input";
|
|
238
|
+
import { GetPhotoOutput } from "./output";
|
|
239
|
+
|
|
240
|
+
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
241
|
+
OpenApiTestAuth,
|
|
242
|
+
GetPhotoInput,
|
|
243
|
+
GetPhotoOutput
|
|
244
|
+
>((handler) =>
|
|
245
|
+
handler.usingHttp((http) =>
|
|
246
|
+
http
|
|
247
|
+
.get("https://jsonplaceholder.typicode.com/photos")
|
|
248
|
+
.handleRequest((ctx, input, request) => request.addQueryString("id", input.id).withBodyAsJson({ photoId: input.photoId }))
|
|
249
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
164
250
|
)
|
|
165
251
|
);`)).toEqual(generatedHandler);
|
|
166
252
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { JSONSchema4 } from 'json-schema';
|
|
2
|
+
import * as E from 'fp-ts/Either';
|
|
3
|
+
export type GenerateHandlerTestInput = {
|
|
4
|
+
operationNameCamelCase: string;
|
|
5
|
+
input: JSONSchema4;
|
|
6
|
+
output: JSONSchema4;
|
|
7
|
+
};
|
|
8
|
+
export declare const generateHandlerTest: ({ operationNameCamelCase, input, output, }: GenerateHandlerTestInput) => E.Either<Error, string>;
|
|
9
|
+
//# sourceMappingURL=GenerateHandlerTest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateHandlerTest.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandlerTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,MAAM,MAAM,wBAAwB,GAAG;IACtC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;CACpB,CAAC;AAmCF,eAAO,MAAM,mBAAmB,+CAI7B,wBAAwB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CA6BlD,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.generateHandlerTest = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
const getDefaultValue = (prop) => {
|
|
29
|
+
switch (prop.type) {
|
|
30
|
+
case 'string':
|
|
31
|
+
return `'test'`;
|
|
32
|
+
case 'number':
|
|
33
|
+
case 'integer':
|
|
34
|
+
return 2;
|
|
35
|
+
case 'boolean':
|
|
36
|
+
return 'true';
|
|
37
|
+
case 'array':
|
|
38
|
+
return prop.items ? `[${getDefaultValue(prop.items)}]` : '[]';
|
|
39
|
+
case 'object':
|
|
40
|
+
return prop.properties ? handleInput(prop.properties) : '{}';
|
|
41
|
+
default:
|
|
42
|
+
return `'test_value'`;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const handleInput = (inputs) => {
|
|
46
|
+
const populatedTestInputs = Object.entries(inputs).map(([key, prop]) => `${key}: ${getDefaultValue(prop)}`);
|
|
47
|
+
return `{ ${populatedTestInputs.join(', ')} }`;
|
|
48
|
+
};
|
|
49
|
+
const handleOutput = (outputs) => {
|
|
50
|
+
const expectations = Object.entries(outputs).map(([key, prop]) => `expect(outputValue.${key}).toEqual(${getDefaultValue(prop)});`);
|
|
51
|
+
return expectations.join('\n');
|
|
52
|
+
};
|
|
53
|
+
const generateHandlerTest = ({ operationNameCamelCase, input, output, }) => E.tryCatch(() => `import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
54
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
55
|
+
import { ${operationNameCamelCase}Handler } from './handler';
|
|
56
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
57
|
+
|
|
58
|
+
OperationHandlerTestSetup.configureHandlerTest(${operationNameCamelCase}Handler, (handlerTest) =>
|
|
59
|
+
handlerTest
|
|
60
|
+
.usingHandlerContext('test')
|
|
61
|
+
.nothingBeforeAll()
|
|
62
|
+
.testCase('should ${operationNameCamelCase}', (testCase) =>
|
|
63
|
+
testCase
|
|
64
|
+
.givenNothing()
|
|
65
|
+
.when(() => (${input.properties ? handleInput(input.properties) : `{}`}))
|
|
66
|
+
.then(({ output }) => {
|
|
67
|
+
// console.log(output);
|
|
68
|
+
const outputValue =
|
|
69
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
70
|
+
${handleOutput(output.properties || {})}
|
|
71
|
+
})
|
|
72
|
+
.finallyDoNothing()
|
|
73
|
+
)
|
|
74
|
+
.nothingAfterAll()
|
|
75
|
+
);`, (e) => new Error(`Failed to generate handler test: ${e}`));
|
|
76
|
+
exports.generateHandlerTest = generateHandlerTest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateHandlerTest.test.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandlerTest.test.ts"],"names":[],"mappings":""}
|