@ondc/automation-mock-runner 0.0.8 → 0.1.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/lib/MockRunner.d.ts +4 -1
- package/dist/lib/MockRunner.js +97 -2
- package/dist/lib/configHelper.d.ts +1 -0
- package/dist/lib/configHelper.js +32 -76
- package/dist/test/BrowserRunner.test.js +12 -13
- package/dist/test/helper-config.test.d.ts +1 -0
- package/dist/test/helper-config.test.js +686 -0
- package/package.json +1 -1
- package/dist/test/CrossEnvironment.d.ts +0 -0
- package/dist/test/CrossEnvironment.js +0 -193
package/dist/lib/MockRunner.d.ts
CHANGED
|
@@ -12,8 +12,11 @@ export declare class MockRunner {
|
|
|
12
12
|
errors?: import("zod/v4/core").$ZodIssue[];
|
|
13
13
|
};
|
|
14
14
|
runGeneratePayload(actionId: string, inputs?: any): Promise<ExecutionResult>;
|
|
15
|
+
runGeneratePayloadWithSession(actionId: string, sessionData: any): Promise<ExecutionResult>;
|
|
15
16
|
runValidatePayload(actionId: string, targetPayload: any): Promise<ExecutionResult>;
|
|
16
|
-
|
|
17
|
+
runValidatePayloadWithSession(actionId: string, targetPayload: any, sessionData: any): Promise<ExecutionResult>;
|
|
18
|
+
runMeetRequirements(actionId: string): Promise<ExecutionResult>;
|
|
19
|
+
runMeetRequirementsWithSession(actionId: string, sessionData: any): Promise<ExecutionResult>;
|
|
17
20
|
getDefaultStep(api: string, actionId: string): MockPlaygroundConfigType["steps"][0];
|
|
18
21
|
generateContext(actionId: string, action: string): any;
|
|
19
22
|
getSessionDataUpToStep(index: number): Record<string, any>;
|
package/dist/lib/MockRunner.js
CHANGED
|
@@ -103,6 +103,53 @@ class MockRunner {
|
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
async runGeneratePayloadWithSession(actionId, sessionData) {
|
|
107
|
+
const executionId = this.logger.createExecutionContext(actionId);
|
|
108
|
+
const startTime = Date.now();
|
|
109
|
+
try {
|
|
110
|
+
this.logger.logExecution(executionId, "Starting payload generation with session data", {
|
|
111
|
+
actionId,
|
|
112
|
+
sessionKeys: Object.keys(sessionData),
|
|
113
|
+
});
|
|
114
|
+
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
115
|
+
if (!step) {
|
|
116
|
+
const availableActions = this.config.steps.map((s) => s.action_id);
|
|
117
|
+
throw new errors_1.ActionNotFoundError(actionId, availableActions);
|
|
118
|
+
}
|
|
119
|
+
const index = this.config.steps.findIndex((s) => s.action_id === actionId);
|
|
120
|
+
// Deep clone to avoid mutations
|
|
121
|
+
const defaultPayload = JSON.parse(JSON.stringify(step.mock.defaultPayload));
|
|
122
|
+
const context = this.generateContext(step.action_id, step.api);
|
|
123
|
+
defaultPayload.context = context;
|
|
124
|
+
const schema = (0, function_registry_1.getFunctionSchema)("generate");
|
|
125
|
+
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.generate), schema, [defaultPayload, sessionData]);
|
|
126
|
+
const executionTime = Date.now() - startTime;
|
|
127
|
+
this.logger.logExecution(executionId, "Payload generation with session data completed", {
|
|
128
|
+
actionId,
|
|
129
|
+
success: result.success,
|
|
130
|
+
output: result.result,
|
|
131
|
+
executionTime,
|
|
132
|
+
});
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const executionTime = Date.now() - startTime;
|
|
137
|
+
this.logger.error("Payload generation with session data failed", { actionId, executionTime }, error);
|
|
138
|
+
return {
|
|
139
|
+
timestamp: new Date().toISOString(),
|
|
140
|
+
success: false,
|
|
141
|
+
error: {
|
|
142
|
+
name: error instanceof Error
|
|
143
|
+
? error.constructor.name
|
|
144
|
+
: "PayloadGenerationError",
|
|
145
|
+
message: error.message || "Unknown error",
|
|
146
|
+
},
|
|
147
|
+
logs: [],
|
|
148
|
+
executionTime,
|
|
149
|
+
validation: { isValid: false, errors: [], warnings: [] },
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
106
153
|
async runValidatePayload(actionId, targetPayload) {
|
|
107
154
|
try {
|
|
108
155
|
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
@@ -129,7 +176,31 @@ class MockRunner {
|
|
|
129
176
|
};
|
|
130
177
|
}
|
|
131
178
|
}
|
|
132
|
-
async
|
|
179
|
+
async runValidatePayloadWithSession(actionId, targetPayload, sessionData) {
|
|
180
|
+
try {
|
|
181
|
+
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
182
|
+
if (!step) {
|
|
183
|
+
throw new Error(`Action step with ID ${actionId} not found.`);
|
|
184
|
+
}
|
|
185
|
+
const schema = (0, function_registry_1.getFunctionSchema)("validate");
|
|
186
|
+
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.validate), schema, [targetPayload, sessionData]);
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return {
|
|
191
|
+
timestamp: new Date().toISOString(),
|
|
192
|
+
success: false,
|
|
193
|
+
error: {
|
|
194
|
+
name: "PayloadValidationError",
|
|
195
|
+
message: error.message || "Unknown error",
|
|
196
|
+
},
|
|
197
|
+
logs: [],
|
|
198
|
+
executionTime: 0,
|
|
199
|
+
validation: { isValid: false, errors: [], warnings: [] },
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async runMeetRequirements(actionId) {
|
|
133
204
|
try {
|
|
134
205
|
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
135
206
|
if (!step) {
|
|
@@ -138,7 +209,31 @@ class MockRunner {
|
|
|
138
209
|
const index = this.config.steps.findIndex((s) => s.action_id === actionId);
|
|
139
210
|
const schema = (0, function_registry_1.getFunctionSchema)("meetsRequirements");
|
|
140
211
|
const sessionData = this.getSessionDataUpToStep(index);
|
|
141
|
-
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.requirements), schema, [
|
|
212
|
+
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.requirements), schema, [sessionData]);
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
return {
|
|
217
|
+
timestamp: new Date().toISOString(),
|
|
218
|
+
success: false,
|
|
219
|
+
error: {
|
|
220
|
+
name: "MeetRequirementsError",
|
|
221
|
+
message: error.message || "Unknown error",
|
|
222
|
+
},
|
|
223
|
+
logs: [],
|
|
224
|
+
executionTime: 0,
|
|
225
|
+
validation: { isValid: false, errors: [], warnings: [] },
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async runMeetRequirementsWithSession(actionId, sessionData) {
|
|
230
|
+
try {
|
|
231
|
+
const step = this.config.steps.find((s) => s.action_id === actionId);
|
|
232
|
+
if (!step) {
|
|
233
|
+
throw new Error(`Action step with ID ${actionId} not found.`);
|
|
234
|
+
}
|
|
235
|
+
const schema = (0, function_registry_1.getFunctionSchema)("meetsRequirements");
|
|
236
|
+
const result = await this.getRunnerInstance().execute(MockRunner.decodeBase64(step.mock.requirements), schema, [sessionData]);
|
|
142
237
|
return result;
|
|
143
238
|
}
|
|
144
239
|
catch (error) {
|
package/dist/lib/configHelper.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createInitialMockConfig = createInitialMockConfig;
|
|
4
|
+
exports.convertToFlowConfig = convertToFlowConfig;
|
|
4
5
|
const uuid_1 = require("uuid");
|
|
5
6
|
function createInitialMockConfig(domain, version, flowId) {
|
|
6
7
|
return {
|
|
@@ -23,79 +24,34 @@ function createInitialMockConfig(domain, version, flowId) {
|
|
|
23
24
|
helperLib: "",
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// inputs: JSON.stringify(
|
|
58
|
-
// {
|
|
59
|
-
// id: "ExampleInputId",
|
|
60
|
-
// jsonSchema: {
|
|
61
|
-
// $schema: "http://json-schema.org/draft-07/schema#",
|
|
62
|
-
// type: "object",
|
|
63
|
-
// properties: {
|
|
64
|
-
// email: {
|
|
65
|
-
// type: "string",
|
|
66
|
-
// format: "email",
|
|
67
|
-
// minLength: 5,
|
|
68
|
-
// maxLength: 50,
|
|
69
|
-
// description: "User's email address",
|
|
70
|
-
// },
|
|
71
|
-
// age: {
|
|
72
|
-
// type: "integer",
|
|
73
|
-
// minimum: 18,
|
|
74
|
-
// maximum: 120,
|
|
75
|
-
// description: "User's age",
|
|
76
|
-
// },
|
|
77
|
-
// password: {
|
|
78
|
-
// type: "string",
|
|
79
|
-
// minLength: 8,
|
|
80
|
-
// pattern: "^(?=.*[A-Z])(?=.*[0-9]).+$",
|
|
81
|
-
// description: "Must contain uppercase and number",
|
|
82
|
-
// },
|
|
83
|
-
// website: {
|
|
84
|
-
// type: "string",
|
|
85
|
-
// format: "uri",
|
|
86
|
-
// },
|
|
87
|
-
// country: {
|
|
88
|
-
// type: "string",
|
|
89
|
-
// enum: ["US", "UK", "CA", "AU"],
|
|
90
|
-
// },
|
|
91
|
-
// },
|
|
92
|
-
// required: ["email", "password"],
|
|
93
|
-
// additionalProperties: false,
|
|
94
|
-
// },
|
|
95
|
-
// },
|
|
96
|
-
// null,
|
|
97
|
-
// 2
|
|
98
|
-
// ),
|
|
99
|
-
// },
|
|
100
|
-
// };
|
|
101
|
-
// }
|
|
27
|
+
function convertToFlowConfig(config) {
|
|
28
|
+
const flowConfig = {};
|
|
29
|
+
flowConfig.id = config.meta.flowId;
|
|
30
|
+
flowConfig.description = "";
|
|
31
|
+
flowConfig.sequence = [];
|
|
32
|
+
let index = 0;
|
|
33
|
+
for (const step of config.steps) {
|
|
34
|
+
const pair = config.steps.find((s) => s.responseFor === step.action_id)?.action_id ||
|
|
35
|
+
null;
|
|
36
|
+
const flowStep = {
|
|
37
|
+
key: step.action_id,
|
|
38
|
+
type: step.api,
|
|
39
|
+
owner: step.owner,
|
|
40
|
+
description: step.description || "",
|
|
41
|
+
expect: index === 0 ? true : false,
|
|
42
|
+
unsolicited: step.unsolicited,
|
|
43
|
+
pair: pair,
|
|
44
|
+
};
|
|
45
|
+
if (step.mock.inputs !== undefined &&
|
|
46
|
+
step.mock.inputs !== null &&
|
|
47
|
+
Object.keys(step.mock.inputs).length > 0) {
|
|
48
|
+
flowStep.input = {
|
|
49
|
+
name: step.mock.inputs.id,
|
|
50
|
+
schema: step.mock.inputs.jsonSchema,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
flowConfig.sequence.push(flowStep);
|
|
54
|
+
index++;
|
|
55
|
+
}
|
|
56
|
+
return flowConfig;
|
|
57
|
+
}
|
|
@@ -46,7 +46,6 @@ describe("BrowserRunner", () => {
|
|
|
46
46
|
const result = await browserRunner.execute(functionCode, schema, args);
|
|
47
47
|
expect(result.success).toBe(true);
|
|
48
48
|
expect(result.result).toBeDefined();
|
|
49
|
-
console.log(result.result, "result");
|
|
50
49
|
expect(result.result.message.test).toBe("browser-execution");
|
|
51
50
|
expect(result.timestamp).toBeDefined();
|
|
52
51
|
expect(typeof result.executionTime).toBe("number");
|
|
@@ -67,18 +66,18 @@ describe("BrowserRunner", () => {
|
|
|
67
66
|
expect(result.result.valid).toBe(true);
|
|
68
67
|
expect(result.result.code).toBe(200);
|
|
69
68
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
it("should execute requirements function", async () => {
|
|
70
|
+
const functionCode = `
|
|
71
|
+
function meetsRequirements(sessionData) {
|
|
72
|
+
return { valid: true, code: 200, description: 'Requirements met' };
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
const schema = (0, function_registry_1.getFunctionSchema)("meetsRequirements");
|
|
76
|
+
const args = [{}];
|
|
77
|
+
const result = await browserRunner.execute(functionCode, schema, args);
|
|
78
|
+
expect(result.success).toBe(true);
|
|
79
|
+
expect(result.result.valid).toBe(true);
|
|
80
|
+
});
|
|
82
81
|
});
|
|
83
82
|
// describe("Error Handling", () => {
|
|
84
83
|
// it("should handle syntax errors", async () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const configHelper_1 = require("../lib/configHelper");
|
|
4
|
+
// Mock UUID to get predictable test results
|
|
5
|
+
jest.mock("uuid", () => ({
|
|
6
|
+
v4: jest.fn(() => "test-uuid-1234"),
|
|
7
|
+
}));
|
|
8
|
+
const testMockConfig = {
|
|
9
|
+
meta: {
|
|
10
|
+
domain: "ONDC:TRV14",
|
|
11
|
+
version: "2.0.0",
|
|
12
|
+
flowId: "test",
|
|
13
|
+
},
|
|
14
|
+
transaction_data: {
|
|
15
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
16
|
+
latest_timestamp: "1970-01-01T00:00:00.000Z",
|
|
17
|
+
bap_id: "sample-bap-id",
|
|
18
|
+
bap_uri: "https://bap.example.com",
|
|
19
|
+
bpp_id: "sample-bpp-id",
|
|
20
|
+
bpp_uri: "https://bpp.example.com",
|
|
21
|
+
},
|
|
22
|
+
steps: [
|
|
23
|
+
{
|
|
24
|
+
api: "search",
|
|
25
|
+
action_id: "test",
|
|
26
|
+
owner: "BAP",
|
|
27
|
+
responseFor: null,
|
|
28
|
+
unsolicited: false,
|
|
29
|
+
description: "please add relevant description",
|
|
30
|
+
mock: {
|
|
31
|
+
generate: "LyoqCiAqIEdlbmVyYXRlcyB0aGUgbW9jayBwYXlsb2FkIGZvciBhbiBBUEkgY2FsbCBpbiB0aGUgdHJhbnNhY3Rpb24gZmxvdy4KICogVGhpcyBmdW5jdGlvbiBhbGxvd3MgY3VzdG9taXphdGlvbiBvZiB0aGUgZGVmYXVsdCBwYXlsb2FkIHVzaW5nIHNlc3Npb24gZGF0YQogKiBmcm9tIHByZXZpb3VzIHN0ZXBzIGFuZCB1c2VyIGlucHV0cy4KICogCiAqIEBwYXJhbSB7T2JqZWN0fSBkZWZhdWx0UGF5bG9hZCAtIFRoZSBiYXNlIHBheWxvYWQgb2JqZWN0IHdpdGggY29udGV4dCBhbHJlYWR5IHBvcHVsYXRlZC4KICogQHBhcmFtIHtPYmplY3R9IHNlc3Npb25EYXRhIC0gRGF0YSBjb2xsZWN0ZWQgZnJvbSBwcmV2aW91cyB0cmFuc2FjdGlvbiBzdGVwcy4KICogQHBhcmFtIHtPYmplY3R9IHNlc3Npb25EYXRhLnVzZXJfaW5wdXRzIC0gVXNlci1wcm92aWRlZCBpbnB1dCB2YWx1ZXMgZm9yIHRoaXMgc3RlcC4KICogQHBhcmFtIHsqfSBzZXNzaW9uRGF0YS5ba2V5XSAtIEFueSBzYXZlZCBkYXRhIGZyb20gcHJldmlvdXMgc3RlcHMgKGRlZmluZWQgaW4gc2F2ZURhdGEgY29uZmlnKS4KICogCiAqIEByZXR1cm5zIHtPYmplY3R9IFRoZSBnZW5lcmF0ZWQgcGF5bG9hZCBvYmplY3QgdG8gYmUgc2VudCBpbiB0aGUgQVBJIHJlcXVlc3QuCiAqLwphc3luYyBmdW5jdGlvbiBnZW5lcmF0ZShkZWZhdWx0UGF5bG9hZCwgc2Vzc2lvbkRhdGEpIHsKICByZXR1cm4gZGVmYX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JpcHRpb246ICJSZXF1aXJlbWVudHMgbWV0IiB9Owp9",
|
|
34
|
+
defaultPayload: {
|
|
35
|
+
context: {
|
|
36
|
+
domain: "ONDC:TRV14",
|
|
37
|
+
action: "search",
|
|
38
|
+
timestamp: "2025-10-14T06:46:29.913Z",
|
|
39
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
40
|
+
message_id: "f43510e7-9b7b-4dfe-a449-e6a2f9df86dc",
|
|
41
|
+
bap_id: "sample-bap-id",
|
|
42
|
+
bap_uri: "https://bap.example.com",
|
|
43
|
+
ttl: "PT30S",
|
|
44
|
+
version: "2.0.0",
|
|
45
|
+
location: {
|
|
46
|
+
country: {
|
|
47
|
+
code: "IND",
|
|
48
|
+
},
|
|
49
|
+
city: {
|
|
50
|
+
code: "*",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
message: {},
|
|
55
|
+
},
|
|
56
|
+
saveData: {
|
|
57
|
+
latestMessage_id: "$.context.message_id",
|
|
58
|
+
latestTimestamp: "$.context.timestamp",
|
|
59
|
+
bapId: "$.context.bap_id",
|
|
60
|
+
bapUri: "$.context.bap_uri",
|
|
61
|
+
bppId: "$.context.bpp_id",
|
|
62
|
+
bppUri: "$.context.bpp_uri",
|
|
63
|
+
},
|
|
64
|
+
inputs: {},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
api: "on_search",
|
|
69
|
+
action_id: "on_search_test",
|
|
70
|
+
owner: "BPP",
|
|
71
|
+
responseFor: "test",
|
|
72
|
+
unsolicited: false,
|
|
73
|
+
description: "please add relevant description",
|
|
74
|
+
mock: {
|
|
75
|
+
generate: "LyoqCiAqIEdlbmVyYXRlcyB0aGUgbW9jayBwYXlsb2FkIGZvciBhbiBBUEkgY2FsbCBpbiB0aGUgdHJhbnNhY3Rpb24gZmxvdy4KICogVGhpcyBmdW5jdGlvbiBhbGxvd3MgY3VzdG9taXphdGlvbiBvZiB0aGUg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
|
79
|
+
context: {
|
|
80
|
+
domain: "ONDC:TRV14",
|
|
81
|
+
action: "on_search",
|
|
82
|
+
timestamp: "2025-10-14T08:57:21.699Z",
|
|
83
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
84
|
+
message_id: "b70244ad-b3df-4910-96d1-0d04a4a1df5d",
|
|
85
|
+
bap_id: "sample-bap-id",
|
|
86
|
+
bap_uri: "https://bap.example.com",
|
|
87
|
+
ttl: "PT30S",
|
|
88
|
+
bpp_id: "sample-bpp-id",
|
|
89
|
+
bpp_uri: "https://bpp.example.com",
|
|
90
|
+
version: "2.0.0",
|
|
91
|
+
location: {
|
|
92
|
+
country: {
|
|
93
|
+
code: "IND",
|
|
94
|
+
},
|
|
95
|
+
city: {
|
|
96
|
+
code: "*",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
message: {},
|
|
101
|
+
},
|
|
102
|
+
saveData: {
|
|
103
|
+
latestMessage_id: "$.context.message_id",
|
|
104
|
+
latestTimestamp: "$.context.timestamp",
|
|
105
|
+
bapId: "$.context.bap_id",
|
|
106
|
+
bapUri: "$.context.bap_uri",
|
|
107
|
+
bppId: "$.context.bpp_id",
|
|
108
|
+
bppUri: "$.context.bpp_uri",
|
|
109
|
+
},
|
|
110
|
+
inputs: {
|
|
111
|
+
id: "ExampleInputId",
|
|
112
|
+
jsonSchema: {
|
|
113
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: {
|
|
116
|
+
item_id: {
|
|
117
|
+
type: "string",
|
|
118
|
+
description: "item id",
|
|
119
|
+
},
|
|
120
|
+
item_count: {
|
|
121
|
+
type: "integer",
|
|
122
|
+
minimum: 0,
|
|
123
|
+
maximum: 12,
|
|
124
|
+
description: "item count",
|
|
125
|
+
},
|
|
126
|
+
required: ["item_id", "item_count"],
|
|
127
|
+
additionalProperties: false,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
api: "select",
|
|
135
|
+
action_id: "select_1",
|
|
136
|
+
owner: "BAP",
|
|
137
|
+
responseFor: null,
|
|
138
|
+
unsolicited: false,
|
|
139
|
+
description: "please add relevant description",
|
|
140
|
+
mock: {
|
|
141
|
+
generate: "LyoqCiAqIEdlbmVyYXRlcyB0aGUgbW9jayBwYXlsb2FkIGZvciBhbiBBUEkgY2FsbCBpbiB0aGUgdHJhbnNhY3Rpb24gZmxvdy4KICogVGhpcyBmdW5jdGlvbiBhbGxvd3MgY3VzdG9taXphdGlvbiBvZiB0aGUgZGVmYXVsdCBwYXlsb2FkIHVzaW5nIHNlc3Npb24gZGF0YQogKiBmcm9tIHByZXZpb3VzIHN0ZXBzIGFuZCB1c2VyIGlucHV0cy4KICogCiAqIEBwYXJhbSB7T2JqZWN0fSBkZWZhdWx0UGF5bG9hZCAtIFRoZSBiYXNlIHBheWxvYWQgb2JqZWN0IHdpdGggY29udGV4dCBhbHJlYWR5IHBvcHVsYXRlZC4KICogQHBhcmFtIHtPYmplY3R9IHNlc3Npb25EYXRhIC0gRGF0YSBjb2xsZWN0ZWQgZnJvbSBwcmV2aW91cyB0cmFuc2FjdGlvbiBzdGVwcy4KICogQHBhcmFtIHtPYmplY3R9IHNlc3Npb25EYXRhLnVzZXJfaW5wdXRzIC0gVXNlci1wcm92aWRlZCBpbnB1dCB2YWx1ZXMgZm9yIHRoaXMgc3RlcC4KICogQHBhcmFtIHsqfSBzZXNzaW9uRGF0YS5ba2V5XSAtIEFueSBzYXZlZCBkYXRhIGZyb20gcHJldmlvdXMgc3RlcHMgKGRlZmluZWQgaW4gc2F2ZURhdGEgY29uZmlnKS4KICogCiAqIEByZXR1cm5zIHtPYmplY3R9IFRoZSBnZW5lcmF0ZWQgcGF5bG9hZCBvYmplY3QgdG8gYmUgc2VudCBpbiB0aGUgQVBJIHJlcXVlc3QuCiAqLwphc3luYyBmdW5jdGlvb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XRzUmVxdWlyZW1lbnRzKHNlc3Npb25EYXRhKSB7CiAgcmV0dXJuIHsgdmFsaWQ6IHRydWUsIGNvZGU6IDIwMCwgZGVzY3JpcHRpb246ICJSZXF1aXJlbWVudHMgbWV0IiB9Owp9",
|
|
144
|
+
defaultPayload: {
|
|
145
|
+
context: {
|
|
146
|
+
domain: "ONDC:TRV14",
|
|
147
|
+
action: "select",
|
|
148
|
+
timestamp: "2025-10-14T08:58:23.363Z",
|
|
149
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
150
|
+
message_id: "22b94f0a-6bee-4af6-aafd-e401d4b38bf6",
|
|
151
|
+
bap_id: "sample-bap-id",
|
|
152
|
+
bap_uri: "https://bap.example.com",
|
|
153
|
+
ttl: "PT30S",
|
|
154
|
+
bpp_id: "sample-bpp-id",
|
|
155
|
+
bpp_uri: "https://bpp.example.com",
|
|
156
|
+
version: "2.0.0",
|
|
157
|
+
location: {
|
|
158
|
+
country: {
|
|
159
|
+
code: "IND",
|
|
160
|
+
},
|
|
161
|
+
city: {
|
|
162
|
+
code: "*",
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
message: {},
|
|
167
|
+
},
|
|
168
|
+
saveData: {
|
|
169
|
+
latestMessage_id: "$.context.message_id",
|
|
170
|
+
latestTimestamp: "$.context.timestamp",
|
|
171
|
+
bapId: "$.context.bap_id",
|
|
172
|
+
bapUri: "$.context.bap_uri",
|
|
173
|
+
bppId: "$.context.bpp_id",
|
|
174
|
+
bppUri: "$.context.bpp_uri",
|
|
175
|
+
},
|
|
176
|
+
inputs: {},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
api: "on_select",
|
|
181
|
+
action_id: "on_select_1",
|
|
182
|
+
owner: "BPP",
|
|
183
|
+
responseFor: "select_1",
|
|
184
|
+
unsolicited: false,
|
|
185
|
+
description: "please add relevant description",
|
|
186
|
+
mock: {
|
|
187
|
+
generate: "LyoqC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RV14",
|
|
193
|
+
action: "on_select",
|
|
194
|
+
timestamp: "2025-10-14T09:14:46.748Z",
|
|
195
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
196
|
+
message_id: "54b847b2-58e0-4edc-b7bc-801865f14e1f",
|
|
197
|
+
bap_id: "sample-bap-id",
|
|
198
|
+
bap_uri: "https://bap.example.com",
|
|
199
|
+
ttl: "PT30S",
|
|
200
|
+
bpp_id: "sample-bpp-id",
|
|
201
|
+
bpp_uri: "https://bpp.example.com",
|
|
202
|
+
version: "2.0.0",
|
|
203
|
+
location: {
|
|
204
|
+
country: {
|
|
205
|
+
code: "IND",
|
|
206
|
+
},
|
|
207
|
+
city: {
|
|
208
|
+
code: "*",
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
message: {},
|
|
213
|
+
},
|
|
214
|
+
saveData: {
|
|
215
|
+
latestMessage_id: "$.context.message_id",
|
|
216
|
+
latestTimestamp: "$.context.timestamp",
|
|
217
|
+
bapId: "$.context.bap_id",
|
|
218
|
+
bapUri: "$.context.bap_uri",
|
|
219
|
+
bppId: "$.context.bpp_id",
|
|
220
|
+
bppUri: "$.context.bpp_uri",
|
|
221
|
+
},
|
|
222
|
+
inputs: {},
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
api: "on_status",
|
|
227
|
+
action_id: "on_status_test",
|
|
228
|
+
owner: "BPP",
|
|
229
|
+
responseFor: null,
|
|
230
|
+
unsolicited: true,
|
|
231
|
+
description: "please add relevant description",
|
|
232
|
+
mock: {
|
|
233
|
+
generate: "LyoqCiAqIEdlbmVyYXRlcyB0aGUgbW9jayBwYXlsb2FkIGZvciBhbiBBUEkgY2FsbCBpbiB0aGUgdHJhbnNhY3Rpb24gZmxvdy4KICogVGhpcyBmdW5jdGlvbiBhbGxvd3MgY3VzdG9taXphdGlvbiBvZiB0aGUgZGVmYXVsdCBwYXlsb2FkIHVzaW5nIHNlc3Npb24gZ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sZWN0ZWQgZnJvbSBwcmV2aW91cyB0cmFuc2FjdGlvbiBzdGVwcy4KICogCiAqIEByZXR1cm5zIHtPYmplY3R9IHsgdmFsaWQ6IGJvb2xlYW4sIGNvZGU6IG51bWJlciwgZGVzY3JpcHRpb246IHN0cmluZyB9CiAqLwpmdW5jdGlvbiB2YWxpZGF0ZSh0YXJnZXRQYXlsb2FkLCBzZXNzaW9uRGF0YSkgewogIHJldHVybiB7IHZhbGlkOiB0cnVlLCBjb2RlOiAyMDAsIGRlc2NyaXB0aW9uOiAiVmFsaWQgcmVxdWVzdCIgfTsKfQ==",
|
|
235
|
+
requirements: "LyoqCiAqIENoZWNrcyBpZiB0aGUgcmVxdWlyZW1lbnRzIGZvciBwcm9jZWVkaW5nIHdpdGggdGhlIEFQSSBjYWxsIGFyZSBtZXQuCiAqIAogKiBAcGFyYW0ge09iamVjdH0gc2Vzc2lvbkRhdGEgLSBEYXRhIGNvbGxlY3RlZCBmcm9tIHByZXZpb3VzIHRyYW5zYWN0aW9uIHN0ZXBzLgogKiAKICogQHJldHVybnMge09iamVjdH0geyB2YWxpZDogYm9vbGVhbiwgY29kZTogbnVtYmVyLCBkZXNjcmlwdGlvbjogc3RyaW5nIH0KICovCmZ1bmN0aW9uIG1lZXRzUmVxdWlyZW1lbnRzKHNlc3Npb25EYXRhKSB7CiAgcmV0dXJuIHsgdmFsaWQ6IHRydWUsIGNvZGU6IDIwMCwgZGVzY3JpcHRpb246ICJSZXF1aXJlbWVudHMgbWV0IiB9Owp9",
|
|
236
|
+
defaultPayload: {
|
|
237
|
+
context: {
|
|
238
|
+
domain: "ONDC:TRV14",
|
|
239
|
+
action: "on_status",
|
|
240
|
+
timestamp: "2025-10-14T09:15:35.787Z",
|
|
241
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
242
|
+
message_id: "81c96976-4635-4755-bb07-50235c21e583",
|
|
243
|
+
bap_id: "sample-bap-id",
|
|
244
|
+
bap_uri: "https://bap.example.com",
|
|
245
|
+
ttl: "PT30S",
|
|
246
|
+
bpp_id: "sample-bpp-id",
|
|
247
|
+
bpp_uri: "https://bpp.example.com",
|
|
248
|
+
version: "2.0.0",
|
|
249
|
+
location: {
|
|
250
|
+
country: {
|
|
251
|
+
code: "IND",
|
|
252
|
+
},
|
|
253
|
+
city: {
|
|
254
|
+
code: "*",
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
message: {},
|
|
259
|
+
},
|
|
260
|
+
saveData: {
|
|
261
|
+
latestMessage_id: "$.context.message_id",
|
|
262
|
+
latestTimestamp: "$.context.timestamp",
|
|
263
|
+
bapId: "$.context.bap_id",
|
|
264
|
+
bapUri: "$.context.bap_uri",
|
|
265
|
+
bppId: "$.context.bpp_id",
|
|
266
|
+
bppUri: "$.context.bpp_uri",
|
|
267
|
+
},
|
|
268
|
+
inputs: {},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
transaction_history: [
|
|
273
|
+
{
|
|
274
|
+
action_id: "test",
|
|
275
|
+
payload: {
|
|
276
|
+
context: {
|
|
277
|
+
domain: "ONDC:TRV14",
|
|
278
|
+
action: "search",
|
|
279
|
+
timestamp: "2025-10-14T08:55:45.145Z",
|
|
280
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
281
|
+
message_id: "519503eb-6437-4d73-82d4-c05345747d73",
|
|
282
|
+
bap_id: "sample-bap-id",
|
|
283
|
+
bap_uri: "https://bap.example.com",
|
|
284
|
+
ttl: "PT30S",
|
|
285
|
+
version: "2.0.0",
|
|
286
|
+
location: {
|
|
287
|
+
country: {
|
|
288
|
+
code: "IND",
|
|
289
|
+
},
|
|
290
|
+
city: {
|
|
291
|
+
code: "*",
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
message: {},
|
|
296
|
+
},
|
|
297
|
+
saved_info: {},
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
action_id: "on_search_test",
|
|
301
|
+
payload: {
|
|
302
|
+
context: {
|
|
303
|
+
domain: "ONDC:TRV14",
|
|
304
|
+
action: "on_search",
|
|
305
|
+
timestamp: "2025-10-14T09:01:18.725Z",
|
|
306
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
307
|
+
message_id: "237884ab-a783-407a-a94e-e854a650ed58",
|
|
308
|
+
bap_id: "sample-bap-id",
|
|
309
|
+
bap_uri: "https://bap.example.com",
|
|
310
|
+
ttl: "PT30S",
|
|
311
|
+
bpp_id: "sample-bpp-id",
|
|
312
|
+
bpp_uri: "https://bpp.example.com",
|
|
313
|
+
version: "2.0.0",
|
|
314
|
+
location: {
|
|
315
|
+
country: {
|
|
316
|
+
code: "IND",
|
|
317
|
+
},
|
|
318
|
+
city: {
|
|
319
|
+
code: "*",
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
message: {
|
|
324
|
+
item_id: "i1",
|
|
325
|
+
item_count: 3,
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
saved_info: {},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
action_id: "select_1",
|
|
332
|
+
payload: {
|
|
333
|
+
context: {
|
|
334
|
+
domain: "ONDC:TRV14",
|
|
335
|
+
action: "select",
|
|
336
|
+
timestamp: "2025-10-14T09:04:04.826Z",
|
|
337
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
338
|
+
message_id: "f68bf884-39b4-4a00-8919-07d68661290c",
|
|
339
|
+
bap_id: "sample-bap-id",
|
|
340
|
+
bap_uri: "https://bap.example.com",
|
|
341
|
+
ttl: "PT30S",
|
|
342
|
+
bpp_id: "sample-bpp-id",
|
|
343
|
+
bpp_uri: "https://bpp.example.com",
|
|
344
|
+
version: "2.0.0",
|
|
345
|
+
location: {
|
|
346
|
+
country: {
|
|
347
|
+
code: "IND",
|
|
348
|
+
},
|
|
349
|
+
city: {
|
|
350
|
+
code: "*",
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
message: {},
|
|
355
|
+
},
|
|
356
|
+
saved_info: {},
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
action_id: "on_select_1",
|
|
360
|
+
payload: {
|
|
361
|
+
context: {
|
|
362
|
+
domain: "ONDC:TRV14",
|
|
363
|
+
action: "on_select",
|
|
364
|
+
timestamp: "2025-10-14T09:16:39.479Z",
|
|
365
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
366
|
+
message_id: "f68bf884-39b4-4a00-8919-07d68661290c",
|
|
367
|
+
bap_id: "sample-bap-id",
|
|
368
|
+
bap_uri: "https://bap.example.com",
|
|
369
|
+
ttl: "PT30S",
|
|
370
|
+
bpp_id: "sample-bpp-id",
|
|
371
|
+
bpp_uri: "https://bpp.example.com",
|
|
372
|
+
version: "2.0.0",
|
|
373
|
+
location: {
|
|
374
|
+
country: {
|
|
375
|
+
code: "IND",
|
|
376
|
+
},
|
|
377
|
+
city: {
|
|
378
|
+
code: "*",
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
message: {},
|
|
383
|
+
},
|
|
384
|
+
saved_info: {},
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
action_id: "on_status_test",
|
|
388
|
+
payload: {
|
|
389
|
+
context: {
|
|
390
|
+
domain: "ONDC:TRV14",
|
|
391
|
+
action: "on_status",
|
|
392
|
+
timestamp: "2025-10-14T09:16:39.931Z",
|
|
393
|
+
transaction_id: "a1855c22-0489-419d-a85f-5953e009890e",
|
|
394
|
+
message_id: "18634bf4-b6b7-4f94-9f33-ddfe95a65963",
|
|
395
|
+
bap_id: "sample-bap-id",
|
|
396
|
+
bap_uri: "https://bap.example.com",
|
|
397
|
+
ttl: "PT30S",
|
|
398
|
+
bpp_id: "sample-bpp-id",
|
|
399
|
+
bpp_uri: "https://bpp.example.com",
|
|
400
|
+
version: "2.0.0",
|
|
401
|
+
location: {
|
|
402
|
+
country: {
|
|
403
|
+
code: "IND",
|
|
404
|
+
},
|
|
405
|
+
city: {
|
|
406
|
+
code: "*",
|
|
407
|
+
},
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
message: {},
|
|
411
|
+
},
|
|
412
|
+
saved_info: {},
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
validationLib: "",
|
|
416
|
+
helperLib: "",
|
|
417
|
+
};
|
|
418
|
+
describe("configHelper", () => {
|
|
419
|
+
describe("createInitialMockConfig", () => {
|
|
420
|
+
it("should create a basic mock config with correct structure", () => {
|
|
421
|
+
const domain = "ONDC:RET10";
|
|
422
|
+
const version = "1.2.0";
|
|
423
|
+
const flowId = "retail-flow";
|
|
424
|
+
const result = (0, configHelper_1.createInitialMockConfig)(domain, version, flowId);
|
|
425
|
+
expect(result).toHaveProperty("meta");
|
|
426
|
+
expect(result).toHaveProperty("transaction_data");
|
|
427
|
+
expect(result).toHaveProperty("steps");
|
|
428
|
+
expect(result).toHaveProperty("transaction_history");
|
|
429
|
+
expect(result).toHaveProperty("validationLib");
|
|
430
|
+
expect(result).toHaveProperty("helperLib");
|
|
431
|
+
});
|
|
432
|
+
it("should set meta fields correctly", () => {
|
|
433
|
+
const domain = "ONDC:TRV14";
|
|
434
|
+
const version = "2.0.0";
|
|
435
|
+
const flowId = "test-flow";
|
|
436
|
+
const result = (0, configHelper_1.createInitialMockConfig)(domain, version, flowId);
|
|
437
|
+
expect(result.meta).toEqual({
|
|
438
|
+
domain: "ONDC:TRV14",
|
|
439
|
+
version: "2.0.0",
|
|
440
|
+
flowId: "test-flow",
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
it("should generate a UUID for transaction_id", () => {
|
|
444
|
+
const result = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "1.0.0", "test");
|
|
445
|
+
expect(result.transaction_data.transaction_id).toBe("test-uuid-1234");
|
|
446
|
+
});
|
|
447
|
+
it("should set transaction_data with default values", () => {
|
|
448
|
+
const result = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "1.0.0", "test");
|
|
449
|
+
expect(result.transaction_data).toEqual({
|
|
450
|
+
transaction_id: "test-uuid-1234",
|
|
451
|
+
latest_timestamp: "1970-01-01T00:00:00.000Z",
|
|
452
|
+
bap_id: "sample-bap-id",
|
|
453
|
+
bap_uri: "https://bap.example.com",
|
|
454
|
+
bpp_id: "sample-bpp-id",
|
|
455
|
+
bpp_uri: "https://bpp.example.com",
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
it("should initialize empty arrays and strings", () => {
|
|
459
|
+
const result = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "1.0.0", "test");
|
|
460
|
+
expect(result.steps).toEqual([]);
|
|
461
|
+
expect(result.transaction_history).toEqual([]);
|
|
462
|
+
expect(result.validationLib).toBe("");
|
|
463
|
+
expect(result.helperLib).toBe("");
|
|
464
|
+
});
|
|
465
|
+
it("should handle different domain formats", () => {
|
|
466
|
+
const result1 = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "1.0.0", "test");
|
|
467
|
+
const result2 = (0, configHelper_1.createInitialMockConfig)("ONDC:TRV14", "2.0.0", "test");
|
|
468
|
+
const result3 = (0, configHelper_1.createInitialMockConfig)("ONDC:FIS12", "1.1.0", "test");
|
|
469
|
+
expect(result1.meta.domain).toBe("ONDC:RET10");
|
|
470
|
+
expect(result2.meta.domain).toBe("ONDC:TRV14");
|
|
471
|
+
expect(result3.meta.domain).toBe("ONDC:FIS12");
|
|
472
|
+
});
|
|
473
|
+
it("should handle different version formats", () => {
|
|
474
|
+
const result1 = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "1.0.0", "test");
|
|
475
|
+
const result2 = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "2.1.5", "test");
|
|
476
|
+
const result3 = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "0.9.0-beta", "test");
|
|
477
|
+
expect(result1.meta.version).toBe("1.0.0");
|
|
478
|
+
expect(result2.meta.version).toBe("2.1.5");
|
|
479
|
+
expect(result3.meta.version).toBe("0.9.0-beta");
|
|
480
|
+
});
|
|
481
|
+
it("should handle special characters in flowId", () => {
|
|
482
|
+
const result = (0, configHelper_1.createInitialMockConfig)("ONDC:RET10", "1.0.0", "test-flow_v1.0");
|
|
483
|
+
expect(result.meta.flowId).toBe("test-flow_v1.0");
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
describe("convertToFlowConfig", () => {
|
|
487
|
+
it("should convert mock config to flow config with correct structure", () => {
|
|
488
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
489
|
+
expect(result).toHaveProperty("id");
|
|
490
|
+
expect(result).toHaveProperty("description");
|
|
491
|
+
expect(result).toHaveProperty("sequence");
|
|
492
|
+
expect(Array.isArray(result.sequence)).toBe(true);
|
|
493
|
+
});
|
|
494
|
+
it("should set flow id from meta.flowId", () => {
|
|
495
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
496
|
+
expect(result.id).toBe("test");
|
|
497
|
+
});
|
|
498
|
+
it("should initialize description as empty string", () => {
|
|
499
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
500
|
+
expect(result.description).toBe("");
|
|
501
|
+
});
|
|
502
|
+
it("should create sequence array with correct length", () => {
|
|
503
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
504
|
+
expect(result.sequence).toHaveLength(testMockConfig.steps.length);
|
|
505
|
+
});
|
|
506
|
+
it("should map step properties correctly", () => {
|
|
507
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
508
|
+
const firstStep = result.sequence[0];
|
|
509
|
+
expect(firstStep).toEqual({
|
|
510
|
+
key: "test",
|
|
511
|
+
type: "search",
|
|
512
|
+
owner: "BAP",
|
|
513
|
+
description: "please add relevant description",
|
|
514
|
+
expect: true, // First step should have expect: true
|
|
515
|
+
unsolicited: false,
|
|
516
|
+
pair: "on_search_test", // Should find the matching response
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
it("should set expect: true only for the first step", () => {
|
|
520
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
521
|
+
expect(result.sequence[0].expect).toBe(true);
|
|
522
|
+
expect(result.sequence[1].expect).toBe(false);
|
|
523
|
+
expect(result.sequence[2].expect).toBe(false);
|
|
524
|
+
});
|
|
525
|
+
it("should find correct response pairs", () => {
|
|
526
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
527
|
+
// "test" step should be paired with "on_search_test"
|
|
528
|
+
const searchStep = result.sequence.find((s) => s.key === "test");
|
|
529
|
+
expect(searchStep.pair).toBe("on_search_test");
|
|
530
|
+
// "select_1" step should be paired with "on_select_1"
|
|
531
|
+
const selectStep = result.sequence.find((s) => s.key === "select_1");
|
|
532
|
+
expect(selectStep.pair).toBe("on_select_1");
|
|
533
|
+
});
|
|
534
|
+
it("should handle steps without response pairs", () => {
|
|
535
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
536
|
+
// "on_search_test" doesn't have a pair (it IS a response)
|
|
537
|
+
const onSearchStep = result.sequence.find((s) => s.key === "on_search_test");
|
|
538
|
+
expect(onSearchStep.pair).toBeNull();
|
|
539
|
+
// "on_status_test" is unsolicited and doesn't have a pair
|
|
540
|
+
const onStatusStep = result.sequence.find((s) => s.key === "on_status_test");
|
|
541
|
+
expect(onStatusStep.pair).toBeNull();
|
|
542
|
+
});
|
|
543
|
+
it("should preserve step properties", () => {
|
|
544
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
545
|
+
result.sequence.forEach((flowStep, index) => {
|
|
546
|
+
const originalStep = testMockConfig.steps[index];
|
|
547
|
+
expect(flowStep.key).toBe(originalStep.action_id);
|
|
548
|
+
expect(flowStep.type).toBe(originalStep.api);
|
|
549
|
+
expect(flowStep.owner).toBe(originalStep.owner);
|
|
550
|
+
expect(flowStep.description).toBe(originalStep.description);
|
|
551
|
+
expect(flowStep.unsolicited).toBe(originalStep.unsolicited);
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
it("should handle steps with inputs", () => {
|
|
555
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
556
|
+
// Find the step with inputs (on_search_test)
|
|
557
|
+
const stepWithInputs = result.sequence.find((s) => s.key === "on_search_test");
|
|
558
|
+
expect(stepWithInputs.input).toEqual({
|
|
559
|
+
name: "ExampleInputId",
|
|
560
|
+
schema: {
|
|
561
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
562
|
+
type: "object",
|
|
563
|
+
properties: {
|
|
564
|
+
item_id: {
|
|
565
|
+
type: "string",
|
|
566
|
+
description: "item id",
|
|
567
|
+
},
|
|
568
|
+
item_count: {
|
|
569
|
+
type: "integer",
|
|
570
|
+
minimum: 0,
|
|
571
|
+
maximum: 12,
|
|
572
|
+
description: "item count",
|
|
573
|
+
},
|
|
574
|
+
required: ["item_id", "item_count"],
|
|
575
|
+
additionalProperties: false,
|
|
576
|
+
},
|
|
577
|
+
},
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
it("should handle steps without inputs", () => {
|
|
581
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
582
|
+
// Find steps without inputs
|
|
583
|
+
const stepsWithoutInputs = result.sequence.filter((s) => s.key !== "on_search_test");
|
|
584
|
+
stepsWithoutInputs.forEach((step) => {
|
|
585
|
+
expect(step.input).toBeUndefined();
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
it("should handle empty steps array", () => {
|
|
589
|
+
const emptyConfig = {
|
|
590
|
+
...testMockConfig,
|
|
591
|
+
steps: [],
|
|
592
|
+
};
|
|
593
|
+
const result = (0, configHelper_1.convertToFlowConfig)(emptyConfig);
|
|
594
|
+
expect(result.sequence).toEqual([]);
|
|
595
|
+
});
|
|
596
|
+
it("should handle config with single step", () => {
|
|
597
|
+
const singleStepConfig = {
|
|
598
|
+
...testMockConfig,
|
|
599
|
+
steps: [testMockConfig.steps[0]],
|
|
600
|
+
};
|
|
601
|
+
const result = (0, configHelper_1.convertToFlowConfig)(singleStepConfig);
|
|
602
|
+
expect(result.sequence).toHaveLength(1);
|
|
603
|
+
expect(result.sequence[0].expect).toBe(true);
|
|
604
|
+
expect(result.sequence[0].pair).toBeNull(); // No pair available
|
|
605
|
+
});
|
|
606
|
+
it("should handle unsolicited steps correctly", () => {
|
|
607
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
608
|
+
const unsolicitedStep = result.sequence.find((s) => s.key === "on_status_test");
|
|
609
|
+
expect(unsolicitedStep.unsolicited).toBe(true);
|
|
610
|
+
expect(unsolicitedStep.pair).toBeNull();
|
|
611
|
+
});
|
|
612
|
+
it("should maintain correct order of steps", () => {
|
|
613
|
+
const result = (0, configHelper_1.convertToFlowConfig)(testMockConfig);
|
|
614
|
+
const expectedOrder = [
|
|
615
|
+
"test",
|
|
616
|
+
"on_search_test",
|
|
617
|
+
"select_1",
|
|
618
|
+
"on_select_1",
|
|
619
|
+
"on_status_test",
|
|
620
|
+
];
|
|
621
|
+
result.sequence.forEach((step, index) => {
|
|
622
|
+
expect(step.key).toBe(expectedOrder[index]);
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
describe("Edge Cases", () => {
|
|
627
|
+
it("should handle config with missing description", () => {
|
|
628
|
+
const configWithoutDesc = {
|
|
629
|
+
...testMockConfig,
|
|
630
|
+
steps: [
|
|
631
|
+
{
|
|
632
|
+
...testMockConfig.steps[0],
|
|
633
|
+
description: undefined,
|
|
634
|
+
},
|
|
635
|
+
],
|
|
636
|
+
};
|
|
637
|
+
const result = (0, configHelper_1.convertToFlowConfig)(configWithoutDesc);
|
|
638
|
+
expect(result.sequence[0].description).toBe("");
|
|
639
|
+
});
|
|
640
|
+
it("should handle config with null responseFor", () => {
|
|
641
|
+
const configWithNull = {
|
|
642
|
+
...testMockConfig,
|
|
643
|
+
steps: [
|
|
644
|
+
{
|
|
645
|
+
...testMockConfig.steps[0],
|
|
646
|
+
responseFor: null,
|
|
647
|
+
},
|
|
648
|
+
],
|
|
649
|
+
};
|
|
650
|
+
const result = (0, configHelper_1.convertToFlowConfig)(configWithNull);
|
|
651
|
+
expect(result.sequence[0].pair).toBeNull();
|
|
652
|
+
});
|
|
653
|
+
it("should handle config with complex input schemas", () => {
|
|
654
|
+
const configWithComplexInputs = {
|
|
655
|
+
...testMockConfig,
|
|
656
|
+
steps: [
|
|
657
|
+
{
|
|
658
|
+
...testMockConfig.steps[1], // Use the step with inputs
|
|
659
|
+
mock: {
|
|
660
|
+
...testMockConfig.steps[1].mock,
|
|
661
|
+
inputs: {
|
|
662
|
+
id: "ComplexInputId",
|
|
663
|
+
jsonSchema: {
|
|
664
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
665
|
+
type: "object",
|
|
666
|
+
properties: {
|
|
667
|
+
nested: {
|
|
668
|
+
type: "object",
|
|
669
|
+
properties: {
|
|
670
|
+
value: { type: "string" },
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
},
|
|
674
|
+
required: ["nested"],
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
},
|
|
679
|
+
],
|
|
680
|
+
};
|
|
681
|
+
const result = (0, configHelper_1.convertToFlowConfig)(configWithComplexInputs);
|
|
682
|
+
expect(result.sequence[0].input.name).toBe("ComplexInputId");
|
|
683
|
+
expect(result.sequence[0].input.schema.properties.nested).toBeDefined();
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
});
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// /**
|
|
3
|
-
// * Cross-environment integration tests for both Node and Browser runners
|
|
4
|
-
// * These tests ensure both runners produce consistent results
|
|
5
|
-
// */
|
|
6
|
-
// import { NodeRunner } from "../lib/runners/node-runner";
|
|
7
|
-
// import { BrowserRunner } from "../lib/runners/browser-runner";
|
|
8
|
-
// import { getFunctionSchema } from "../lib/constants/function-registry";
|
|
9
|
-
// import { mockBrowserGlobals } from "./__mocks__/browser-globals";
|
|
10
|
-
// import { BaseCodeRunner } from "../lib/runners/base-runner";
|
|
11
|
-
// // Setup mock browser environment for BrowserRunner tests
|
|
12
|
-
// const browserMocks = mockBrowserGlobals();
|
|
13
|
-
// Object.assign(global, {
|
|
14
|
-
// Worker: browserMocks.Worker,
|
|
15
|
-
// Blob: browserMocks.Blob,
|
|
16
|
-
// URL: browserMocks.URL,
|
|
17
|
-
// window: browserMocks.window,
|
|
18
|
-
// document: browserMocks.document,
|
|
19
|
-
// performance: browserMocks.performance,
|
|
20
|
-
// });
|
|
21
|
-
// describe("Cross-Environment Runner Tests", () => {
|
|
22
|
-
// let nodeRunner: NodeRunner;
|
|
23
|
-
// let browserRunner: BrowserRunner;
|
|
24
|
-
// beforeEach(() => {
|
|
25
|
-
// nodeRunner = new NodeRunner();
|
|
26
|
-
// browserRunner = new BrowserRunner();
|
|
27
|
-
// });
|
|
28
|
-
// afterEach(() => {
|
|
29
|
-
// nodeRunner?.terminate();
|
|
30
|
-
// browserRunner?.terminate();
|
|
31
|
-
// });
|
|
32
|
-
// const testCases = [
|
|
33
|
-
// {
|
|
34
|
-
// name: "Simple payload generation",
|
|
35
|
-
// functionCode: `
|
|
36
|
-
// async function generate(defaultPayload, sessionData) {
|
|
37
|
-
// defaultPayload.message = {
|
|
38
|
-
// test: 'cross-environment',
|
|
39
|
-
// timestamp: new Date().toISOString()
|
|
40
|
-
// };
|
|
41
|
-
// return defaultPayload;
|
|
42
|
-
// }
|
|
43
|
-
// `,
|
|
44
|
-
// functionType: "generate" as const,
|
|
45
|
-
// args: [{ context: {} }, {}],
|
|
46
|
-
// validate: (result: any) => {
|
|
47
|
-
// expect(result.message.test).toBe("cross-environment");
|
|
48
|
-
// expect(result.message.timestamp).toBeDefined();
|
|
49
|
-
// },
|
|
50
|
-
// },
|
|
51
|
-
// {
|
|
52
|
-
// name: "Validation with complex logic",
|
|
53
|
-
// functionCode: `
|
|
54
|
-
// function validate(targetPayload, sessionData) {
|
|
55
|
-
// const hasMessage = targetPayload && targetPayload.message;
|
|
56
|
-
// const hasRequiredField = hasMessage && targetPayload.message.required;
|
|
57
|
-
// if (!hasRequiredField) {
|
|
58
|
-
// return {
|
|
59
|
-
// valid: false,
|
|
60
|
-
// code: 400,
|
|
61
|
-
// description: 'Missing required field'
|
|
62
|
-
// };
|
|
63
|
-
// }
|
|
64
|
-
// return {
|
|
65
|
-
// valid: true,
|
|
66
|
-
// code: 200,
|
|
67
|
-
// description: 'Validation passed'
|
|
68
|
-
// };
|
|
69
|
-
// }
|
|
70
|
-
// `,
|
|
71
|
-
// functionType: "validate" as const,
|
|
72
|
-
// args: [{ message: { required: true } }, {}],
|
|
73
|
-
// validate: (result: any) => {
|
|
74
|
-
// expect(result.valid).toBe(true);
|
|
75
|
-
// expect(result.code).toBe(200);
|
|
76
|
-
// },
|
|
77
|
-
// },
|
|
78
|
-
// {
|
|
79
|
-
// name: "Requirements check with session data",
|
|
80
|
-
// functionCode: `
|
|
81
|
-
// function meetsRequirements(sessionData) {
|
|
82
|
-
// const hasUserData = sessionData && sessionData.user_inputs;
|
|
83
|
-
// const hasRequiredAuth = hasUserData && sessionData.user_inputs.authenticated;
|
|
84
|
-
// if (!hasRequiredAuth) {
|
|
85
|
-
// return {
|
|
86
|
-
// valid: false,
|
|
87
|
-
// code: 401,
|
|
88
|
-
// description: 'Authentication required'
|
|
89
|
-
// };
|
|
90
|
-
// }
|
|
91
|
-
// return {
|
|
92
|
-
// valid: true,
|
|
93
|
-
// code: 200,
|
|
94
|
-
// description: 'Requirements met'
|
|
95
|
-
// };
|
|
96
|
-
// }
|
|
97
|
-
// `,
|
|
98
|
-
// functionType: "meetsRequirements" as const,
|
|
99
|
-
// args: [{ user_inputs: { authenticated: true } }],
|
|
100
|
-
// validate: (result: any) => {
|
|
101
|
-
// expect(result.valid).toBe(true);
|
|
102
|
-
// expect(result.code).toBe(200);
|
|
103
|
-
// },
|
|
104
|
-
// },
|
|
105
|
-
// ];
|
|
106
|
-
// describe.each(["node", "browser"])("%s Runner Consistency", (runnerType) => {
|
|
107
|
-
// let runner: BaseCodeRunner;
|
|
108
|
-
// beforeEach(() => {
|
|
109
|
-
// runner = runnerType === "node" ? nodeRunner : browserRunner;
|
|
110
|
-
// });
|
|
111
|
-
// testCases.forEach((testCase) => {
|
|
112
|
-
// it(`should handle ${testCase.name}`, async () => {
|
|
113
|
-
// const schema = getFunctionSchema(testCase.functionType);
|
|
114
|
-
// const result = await runner.execute(
|
|
115
|
-
// testCase.functionCode,
|
|
116
|
-
// schema,
|
|
117
|
-
// testCase.args,
|
|
118
|
-
// );
|
|
119
|
-
// expect(result.success).toBe(true);
|
|
120
|
-
// expect(result.result).toBeDefined();
|
|
121
|
-
// expect(result.timestamp).toBeDefined();
|
|
122
|
-
// expect(typeof result.executionTime).toBe("number");
|
|
123
|
-
// testCase.validate(result.result);
|
|
124
|
-
// });
|
|
125
|
-
// });
|
|
126
|
-
// });
|
|
127
|
-
// describe("Cross-Environment Consistency", () => {
|
|
128
|
-
// testCases.forEach((testCase) => {
|
|
129
|
-
// it(`should produce consistent results for ${testCase.name}`, async () => {
|
|
130
|
-
// const schema = getFunctionSchema(testCase.functionType);
|
|
131
|
-
// // Execute in both environments
|
|
132
|
-
// const [nodeResult, browserResult] = await Promise.all([
|
|
133
|
-
// nodeRunner.execute(testCase.functionCode, schema, testCase.args),
|
|
134
|
-
// browserRunner.execute(testCase.functionCode, schema, testCase.args),
|
|
135
|
-
// ]);
|
|
136
|
-
// // Both should succeed
|
|
137
|
-
// expect(nodeResult.success).toBe(true);
|
|
138
|
-
// expect(browserResult.success).toBe(true);
|
|
139
|
-
// // Results should be functionally equivalent
|
|
140
|
-
// // (timestamps might differ slightly, so we test structure)
|
|
141
|
-
// expect(typeof nodeResult.result).toBe(typeof browserResult.result);
|
|
142
|
-
// if (
|
|
143
|
-
// typeof nodeResult.result === "object" &&
|
|
144
|
-
// nodeResult.result !== null
|
|
145
|
-
// ) {
|
|
146
|
-
// // Compare object structure (excluding timestamp fields)
|
|
147
|
-
// const nodeKeys = Object.keys(nodeResult.result);
|
|
148
|
-
// const browserKeys = Object.keys(browserResult.result);
|
|
149
|
-
// expect(nodeKeys.sort()).toEqual(browserKeys.sort());
|
|
150
|
-
// }
|
|
151
|
-
// });
|
|
152
|
-
// });
|
|
153
|
-
// });
|
|
154
|
-
// describe("Error Handling Consistency", () => {
|
|
155
|
-
// const errorCases = [
|
|
156
|
-
// {
|
|
157
|
-
// name: "Syntax error",
|
|
158
|
-
// code: `
|
|
159
|
-
// function generate(defaultPayload, sessionData) {
|
|
160
|
-
// // Missing closing brace
|
|
161
|
-
// return defaultPayload
|
|
162
|
-
// `,
|
|
163
|
-
// functionType: "generate" as const,
|
|
164
|
-
// args: [{}, {}],
|
|
165
|
-
// },
|
|
166
|
-
// {
|
|
167
|
-
// name: "Runtime error",
|
|
168
|
-
// code: `
|
|
169
|
-
// function validate(targetPayload, sessionData) {
|
|
170
|
-
// throw new Error('Test error');
|
|
171
|
-
// }
|
|
172
|
-
// `,
|
|
173
|
-
// functionType: "validate" as const,
|
|
174
|
-
// args: [{}, {}],
|
|
175
|
-
// },
|
|
176
|
-
// ];
|
|
177
|
-
// errorCases.forEach((errorCase) => {
|
|
178
|
-
// it(`should handle ${errorCase.name} consistently`, async () => {
|
|
179
|
-
// const schema = getFunctionSchema(errorCase.functionType);
|
|
180
|
-
// const [nodeResult, browserResult] = await Promise.all([
|
|
181
|
-
// nodeRunner.execute(errorCase.code, schema, errorCase.args),
|
|
182
|
-
// browserRunner.execute(errorCase.code, schema, errorCase.args),
|
|
183
|
-
// ]);
|
|
184
|
-
// // Both should fail
|
|
185
|
-
// expect(nodeResult.success).toBe(false);
|
|
186
|
-
// expect(browserResult.success).toBe(false);
|
|
187
|
-
// // Both should have error information
|
|
188
|
-
// expect(nodeResult.error).toBeDefined();
|
|
189
|
-
// expect(browserResult.error).toBeDefined();
|
|
190
|
-
// });
|
|
191
|
-
// });
|
|
192
|
-
// });
|
|
193
|
-
// });
|