@ondc/automation-mock-runner 1.3.13 → 1.3.14
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.js
CHANGED
|
@@ -331,6 +331,9 @@ class MockRunner {
|
|
|
331
331
|
bapUri: "$.context.bap_uri",
|
|
332
332
|
bppId: "$.context.bpp_id",
|
|
333
333
|
bppUri: "$.context.bpp_uri",
|
|
334
|
+
city_code: this.config.meta.version.startsWith("1")
|
|
335
|
+
? "$.context.city"
|
|
336
|
+
: "$.context.location.city.code",
|
|
334
337
|
},
|
|
335
338
|
inputs: {
|
|
336
339
|
id: "ExampleInputId",
|
|
@@ -452,11 +455,13 @@ class MockRunner {
|
|
|
452
455
|
// Version-specific context structure
|
|
453
456
|
const version = this.config.meta?.version || "2.0.0";
|
|
454
457
|
const majorVersion = parseInt(version.split(".")[0], 10);
|
|
458
|
+
// set city code
|
|
459
|
+
const cityCode = MockRunner.getIdFromSession(sessionData, "city_code") || "*";
|
|
455
460
|
if (majorVersion === 1) {
|
|
456
461
|
return {
|
|
457
462
|
...baseContext,
|
|
458
463
|
country: "IND",
|
|
459
|
-
city:
|
|
464
|
+
city: cityCode,
|
|
460
465
|
core_version: version,
|
|
461
466
|
};
|
|
462
467
|
}
|
|
@@ -469,7 +474,7 @@ class MockRunner {
|
|
|
469
474
|
code: "IND",
|
|
470
475
|
},
|
|
471
476
|
city: {
|
|
472
|
-
code:
|
|
477
|
+
code: cityCode,
|
|
473
478
|
},
|
|
474
479
|
},
|
|
475
480
|
};
|
package/dist/lib/configHelper.js
CHANGED
|
@@ -73,7 +73,18 @@ const isoDurToSec = (duration) => {
|
|
|
73
73
|
(Number(s?.[10]) || 0) * 3600 +
|
|
74
74
|
(Number(s?.[12]) || 0) * 60 +
|
|
75
75
|
(Number(s?.[14]) || 0);
|
|
76
|
-
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const setCityFromInputs = (payload, inputs) => {
|
|
79
|
+
if (!inputs) return "*";
|
|
80
|
+
if (payload.context.version.startsWith("1")) {
|
|
81
|
+
payload.context.city = inputs.city_code ?? "*";
|
|
82
|
+
} else {
|
|
83
|
+
payload.context.location.city.code = inputs.city_code ?? "*";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
`;
|
|
77
88
|
function convertToFlowConfig(config) {
|
|
78
89
|
const flowConfig = {};
|
|
79
90
|
flowConfig.id = config.meta.flowId;
|
|
@@ -193,6 +204,7 @@ async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
|
|
|
193
204
|
const version = payloads[0].context.version || payloads[0].context.core_version || "1.0.0";
|
|
194
205
|
const config = createInitialMockConfig(domain, version, `${flowConfig.id}_logs_flow_${domain}_v${version}`);
|
|
195
206
|
const mockRunner = new MockRunner_1.MockRunner(config);
|
|
207
|
+
let index = 0;
|
|
196
208
|
for (const step of flowConfig.sequence) {
|
|
197
209
|
if (step.type === "HTML_FORM" ||
|
|
198
210
|
step.type === "DYNAMIC_FORM" ||
|
|
@@ -205,7 +217,16 @@ async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
|
|
|
205
217
|
payloads.splice(stepPayload, 1); // remove used payload
|
|
206
218
|
}
|
|
207
219
|
const stepConfig = mockRunner.getDefaultStep(step.type, step.key);
|
|
208
|
-
|
|
220
|
+
if (index === 0) {
|
|
221
|
+
stepConfig.mock.defaultPayload = MockRunner_1.MockRunner.encodeBase64(`async function generate(defaultPayload, sessionData) {
|
|
222
|
+
setCityFromInputs(defaultPayload, sessionData.user_inputs);
|
|
223
|
+
return defaultPayload;
|
|
224
|
+
}`);
|
|
225
|
+
stepConfig.mock.inputs = cityInputs;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
stepConfig.mock.inputs = {};
|
|
229
|
+
}
|
|
209
230
|
stepConfig.mock.defaultPayload = payload;
|
|
210
231
|
const findResponseFor = flowConfig.sequence.find((s) => s.pair === step.key);
|
|
211
232
|
stepConfig.responseFor = findResponseFor ? findResponseFor.key : null;
|
|
@@ -214,3 +235,17 @@ async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
|
|
|
214
235
|
}
|
|
215
236
|
return config;
|
|
216
237
|
}
|
|
238
|
+
const cityInputs = {
|
|
239
|
+
id: "ExampleInputId",
|
|
240
|
+
jsonSchema: {
|
|
241
|
+
$schema: "https://json-schema.org/draft-07/schema",
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {
|
|
244
|
+
city_code: {
|
|
245
|
+
type: "string",
|
|
246
|
+
description: "",
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
required: ["city_code"],
|
|
250
|
+
},
|
|
251
|
+
};
|
|
@@ -679,13 +679,11 @@ describe("configHelper", () => {
|
|
|
679
679
|
expect(searchStepConfig.action_id).toBe("search_step");
|
|
680
680
|
expect(searchStepConfig.responseFor).toBe("on_search_step");
|
|
681
681
|
expect(searchStepConfig.unsolicited).toBe(false);
|
|
682
|
-
expect(searchStepConfig.mock.inputs).toEqual({});
|
|
683
682
|
expect(searchStepConfig.mock.defaultPayload).toBe(searchPayload);
|
|
684
683
|
expect(onSearchStepConfig.api).toBe("on_search");
|
|
685
684
|
expect(onSearchStepConfig.action_id).toBe("on_search_step");
|
|
686
685
|
expect(onSearchStepConfig.responseFor).toBeNull();
|
|
687
686
|
expect(onSearchStepConfig.unsolicited).toBe(false);
|
|
688
|
-
expect(onSearchStepConfig.mock.inputs).toEqual({});
|
|
689
687
|
expect(onSearchStepConfig.mock.defaultPayload).toBe(onSearchPayload);
|
|
690
688
|
});
|
|
691
689
|
it("should ignore HTML_FORM and DYNAMIC_FORM steps and preserve unsolicited flag", async () => {
|