@ondc/automation-mock-runner 1.3.12 → 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.d.ts
CHANGED
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",
|
|
@@ -421,6 +424,18 @@ class MockRunner {
|
|
|
421
424
|
// Priority 4: Generate new UUID as last resort
|
|
422
425
|
return (0, uuid_1.v4)();
|
|
423
426
|
})();
|
|
427
|
+
const bapId = MockRunner.getIdFromSession(sessionData, "bapId") ||
|
|
428
|
+
this.config.transaction_data?.bap_id ||
|
|
429
|
+
"";
|
|
430
|
+
const bppId = MockRunner.getIdFromSession(sessionData, "bppId") ||
|
|
431
|
+
this.config.transaction_data?.bpp_id ||
|
|
432
|
+
"";
|
|
433
|
+
const bapUri = MockRunner.getIdFromSession(sessionData, "bapUri") ||
|
|
434
|
+
this.config.transaction_data?.bap_uri ||
|
|
435
|
+
"";
|
|
436
|
+
const bppUri = MockRunner.getIdFromSession(sessionData, "bppUri") ||
|
|
437
|
+
this.config.transaction_data?.bpp_uri ||
|
|
438
|
+
"";
|
|
424
439
|
// Build base context
|
|
425
440
|
const baseContext = {
|
|
426
441
|
domain: this.config.meta?.domain || "",
|
|
@@ -428,23 +443,25 @@ class MockRunner {
|
|
|
428
443
|
timestamp: new Date().toISOString(),
|
|
429
444
|
transaction_id: transactionId,
|
|
430
445
|
message_id: messageId,
|
|
431
|
-
bap_id:
|
|
432
|
-
bap_uri:
|
|
446
|
+
bap_id: bapId,
|
|
447
|
+
bap_uri: bapUri,
|
|
433
448
|
ttl: "PT30S",
|
|
434
449
|
};
|
|
435
450
|
// Add BPP details for non-search actions
|
|
436
451
|
if (action !== "search") {
|
|
437
|
-
baseContext.bpp_id =
|
|
438
|
-
baseContext.bpp_uri =
|
|
452
|
+
baseContext.bpp_id = bppId;
|
|
453
|
+
baseContext.bpp_uri = bppUri;
|
|
439
454
|
}
|
|
440
455
|
// Version-specific context structure
|
|
441
456
|
const version = this.config.meta?.version || "2.0.0";
|
|
442
457
|
const majorVersion = parseInt(version.split(".")[0], 10);
|
|
458
|
+
// set city code
|
|
459
|
+
const cityCode = MockRunner.getIdFromSession(sessionData, "city_code") || "*";
|
|
443
460
|
if (majorVersion === 1) {
|
|
444
461
|
return {
|
|
445
462
|
...baseContext,
|
|
446
463
|
country: "IND",
|
|
447
|
-
city:
|
|
464
|
+
city: cityCode,
|
|
448
465
|
core_version: version,
|
|
449
466
|
};
|
|
450
467
|
}
|
|
@@ -457,7 +474,7 @@ class MockRunner {
|
|
|
457
474
|
code: "IND",
|
|
458
475
|
},
|
|
459
476
|
city: {
|
|
460
|
-
code:
|
|
477
|
+
code: cityCode,
|
|
461
478
|
},
|
|
462
479
|
},
|
|
463
480
|
};
|
|
@@ -562,5 +579,18 @@ class MockRunner {
|
|
|
562
579
|
const bytes = new Uint8Array([...binaryString].map((char) => char.charCodeAt(0)));
|
|
563
580
|
return new TextDecoder().decode(bytes);
|
|
564
581
|
}
|
|
582
|
+
static getIdFromSession(sessionData, key) {
|
|
583
|
+
if (sessionData === undefined) {
|
|
584
|
+
return undefined;
|
|
585
|
+
}
|
|
586
|
+
const data = sessionData[key];
|
|
587
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
588
|
+
return data[0];
|
|
589
|
+
}
|
|
590
|
+
if (typeof data === "string") {
|
|
591
|
+
return data;
|
|
592
|
+
}
|
|
593
|
+
return undefined;
|
|
594
|
+
}
|
|
565
595
|
}
|
|
566
596
|
exports.MockRunner = MockRunner;
|
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 () => {
|