@ondc/automation-mock-runner 1.3.20 → 1.3.21

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.
@@ -290,10 +290,7 @@ class MockRunner {
290
290
  }
291
291
  }
292
292
  getDefaultStep(api, actionId, formType) {
293
- if (formType === "html_form") {
294
- throw new Error("HTML form generation is not implemented yet");
295
- }
296
- if (formType === "dynamic_form") {
293
+ if (formType === "dynamic_form" || formType === "html_form") {
297
294
  return {
298
295
  api: api,
299
296
  action_id: actionId,
@@ -197,7 +197,6 @@ async function getMinifiedCode(base64Code) {
197
197
  */
198
198
  async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
199
199
  flowConfig = JSON.parse(JSON.stringify(flowConfig));
200
- flowConfig.sequence = flowConfig.sequence.filter((step) => step.type !== "HTML_FORM" && step.type !== "DYNAMIC_FORM");
201
200
  payloads = payloads.sort((a, b) => new Date(a.context.timestamp).getTime() -
202
201
  new Date(b.context.timestamp).getTime());
203
202
  const domain = payloads[0].context.domain;
@@ -206,33 +205,37 @@ async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
206
205
  const mockRunner = new MockRunner_1.MockRunner(config);
207
206
  let index = 0;
208
207
  for (const step of flowConfig.sequence) {
209
- if (step.type === "HTML_FORM" ||
208
+ const isFormStep = step.type === "HTML_FORM" ||
210
209
  step.type === "DYNAMIC_FORM" ||
211
- step.type === "FORM") {
212
- continue;
210
+ step.type === "FORM";
211
+ let stepConfig;
212
+ if (isFormStep) {
213
+ // HTML_FORM is not yet fully implemented — fall back to dynamic_form default
214
+ stepConfig = mockRunner.getDefaultStep(step.type, step.key, "dynamic_form");
213
215
  }
214
- let stepPayload = payloads.findIndex((p) => p.context.action === step.type);
215
- const payload = stepPayload === -1 ? {} : payloads[stepPayload];
216
- if (stepPayload !== -1) {
217
- payloads.splice(stepPayload, 1); // remove used payload
218
- }
219
- const stepConfig = mockRunner.getDefaultStep(step.type, step.key);
220
- if (index === 0) {
221
- stepConfig.mock.generate = MockRunner_1.MockRunner.encodeBase64(`async function generate(defaultPayload, sessionData) {
216
+ else {
217
+ stepConfig = mockRunner.getDefaultStep(step.type, step.key);
218
+ if (index === 0) {
219
+ stepConfig.mock.generate = MockRunner_1.MockRunner.encodeBase64(`async function generate(defaultPayload, sessionData) {
222
220
  setCityFromInputs(defaultPayload, sessionData.user_inputs);
223
221
  return defaultPayload;
224
222
  }`);
225
- stepConfig.mock.inputs = cityInputs;
223
+ stepConfig.mock.inputs = cityInputs;
224
+ }
225
+ else {
226
+ stepConfig.mock.inputs = {};
227
+ }
228
+ const stepPayloadIndex = payloads.findIndex((p) => p.context.action === step.type);
229
+ if (stepPayloadIndex !== -1) {
230
+ stepConfig.mock.defaultPayload = payloads[stepPayloadIndex];
231
+ payloads.splice(stepPayloadIndex, 1); // remove used payload
232
+ }
233
+ index++;
226
234
  }
227
- else {
228
- stepConfig.mock.inputs = {};
229
- }
230
- stepConfig.mock.defaultPayload = payload;
231
235
  const findResponseFor = flowConfig.sequence.find((s) => s.pair === step.key);
232
236
  stepConfig.responseFor = findResponseFor ? findResponseFor.key : null;
233
237
  stepConfig.unsolicited = step.unsolicited;
234
238
  config.steps.push(stepConfig);
235
- index++;
236
239
  }
237
240
  return config;
238
241
  }
@@ -686,71 +686,6 @@ describe("configHelper", () => {
686
686
  expect(onSearchStepConfig.unsolicited).toBe(false);
687
687
  expect(onSearchStepConfig.mock.defaultPayload).toBe(onSearchPayload);
688
688
  });
689
- it("should ignore HTML_FORM and DYNAMIC_FORM steps and preserve unsolicited flag", async () => {
690
- const payloads = [
691
- {
692
- context: {
693
- action: "search",
694
- timestamp: "2025-01-01T09:00:00.000Z",
695
- domain: "ONDC:RET10",
696
- version: "2.0.0",
697
- },
698
- },
699
- {
700
- context: {
701
- action: "on_status",
702
- timestamp: "2025-01-01T10:00:00.000Z",
703
- domain: "ONDC:RET10",
704
- version: "2.0.0",
705
- },
706
- },
707
- ];
708
- const flowConfig = {
709
- id: "flow_with_forms",
710
- sequence: [
711
- {
712
- key: "search_step",
713
- type: "search",
714
- unsolicited: false,
715
- description: "Search step",
716
- pair: null,
717
- owner: "BAP",
718
- },
719
- {
720
- key: "html_form_step",
721
- type: "HTML_FORM",
722
- unsolicited: false,
723
- description: "HTML form step",
724
- pair: null,
725
- owner: "BAP",
726
- },
727
- {
728
- key: "dynamic_form_step",
729
- type: "DYNAMIC_FORM",
730
- unsolicited: false,
731
- description: "Dynamic form step",
732
- pair: null,
733
- owner: "BAP",
734
- },
735
- {
736
- key: "on_status_step",
737
- type: "on_status",
738
- unsolicited: true,
739
- description: "Unsolicited status",
740
- pair: null,
741
- owner: "BPP",
742
- },
743
- ],
744
- };
745
- const config = await (0, configHelper_1.generatePlaygroundConfigFromFlowConfig)(payloads, flowConfig);
746
- // Only non-form steps should be present
747
- expect(config.steps.map((s) => s.action_id)).toEqual([
748
- "search_step",
749
- "on_status_step",
750
- ]);
751
- const onStatusStep = config.steps.find((s) => s.action_id === "on_status_step");
752
- expect(onStatusStep?.unsolicited).toBe(true);
753
- });
754
689
  it("should derive version from core_version when version is missing", async () => {
755
690
  const payloads = [
756
691
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondc/automation-mock-runner",
3
- "version": "1.3.20",
3
+ "version": "1.3.21",
4
4
  "description": "A TypeScript library for ONDC automation mock runner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",