@ondc/automation-mock-runner 1.3.10 → 1.3.12

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.
@@ -76,7 +76,9 @@ class MockRunner {
76
76
  inputSchema: step.mock.inputs.jsonSchema,
77
77
  });
78
78
  }
79
- sessionData.user_inputs = inputs;
79
+ if (Object.keys(inputs).length > 0) {
80
+ sessionData.user_inputs = inputs;
81
+ }
80
82
  const context = this.generateContext(step.action_id, step.api);
81
83
  defaultPayload.context = context;
82
84
  const schema = (0, function_registry_1.getFunctionSchema)("generate");
@@ -201,7 +201,7 @@ async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
201
201
  }
202
202
  let stepPayload = payloads.findIndex((p) => p.context.action === step.type);
203
203
  const payload = stepPayload === -1 ? {} : payloads[stepPayload];
204
- if (stepPayload === -1) {
204
+ if (stepPayload !== -1) {
205
205
  payloads.splice(stepPayload, 1); // remove used payload
206
206
  }
207
207
  const stepConfig = mockRunner.getDefaultStep(step.type, step.key);
@@ -782,6 +782,140 @@ describe("configHelper", () => {
782
782
  expect(config.meta.version).toBe("1.0.0");
783
783
  expect(config.meta.flowId).toBe("core_version_flow_logs_flow_ONDC:FIS12_v1.0.0");
784
784
  });
785
+ it("should handle multiple search requests with different timestamps interspersed with on_search responses", async () => {
786
+ const payloads = [
787
+ {
788
+ context: {
789
+ action: "search",
790
+ timestamp: "2025-01-01T09:00:00.000Z",
791
+ domain: "ONDC:RET10",
792
+ version: "1.0.0",
793
+ },
794
+ },
795
+ {
796
+ context: {
797
+ action: "on_search",
798
+ timestamp: "2025-01-01T09:01:00.000Z",
799
+ domain: "ONDC:RET10",
800
+ version: "1.0.0",
801
+ },
802
+ },
803
+ {
804
+ context: {
805
+ action: "search",
806
+ timestamp: "2025-01-01T09:02:00.000Z",
807
+ domain: "ONDC:RET10",
808
+ version: "1.0.0",
809
+ },
810
+ },
811
+ {
812
+ context: {
813
+ action: "on_search",
814
+ timestamp: "2025-01-01T09:03:00.000Z",
815
+ domain: "ONDC:RET10",
816
+ version: "1.0.0",
817
+ },
818
+ },
819
+ {
820
+ context: {
821
+ action: "search",
822
+ timestamp: "2025-01-01T09:04:00.000Z",
823
+ domain: "ONDC:RET10",
824
+ version: "1.0.0",
825
+ },
826
+ },
827
+ {
828
+ context: {
829
+ action: "on_search",
830
+ timestamp: "2025-01-01T09:05:00.000Z",
831
+ domain: "ONDC:RET10",
832
+ version: "1.0.0",
833
+ },
834
+ },
835
+ ];
836
+ const flowConfig = {
837
+ id: "multi_search_flow",
838
+ sequence: [
839
+ {
840
+ key: "search_1",
841
+ type: "search",
842
+ unsolicited: false,
843
+ description: "First search step",
844
+ pair: null,
845
+ owner: "BAP",
846
+ },
847
+ {
848
+ key: "on_search_1",
849
+ type: "on_search",
850
+ unsolicited: false,
851
+ description: "First on_search step",
852
+ pair: "search_1",
853
+ owner: "BPP",
854
+ },
855
+ {
856
+ key: "search_2",
857
+ type: "search",
858
+ unsolicited: false,
859
+ description: "Second search step",
860
+ pair: null,
861
+ owner: "BAP",
862
+ },
863
+ {
864
+ key: "on_search_2",
865
+ type: "on_search",
866
+ unsolicited: false,
867
+ description: "Second on_search step",
868
+ pair: "search_2",
869
+ owner: "BPP",
870
+ },
871
+ {
872
+ key: "search_3",
873
+ type: "search",
874
+ unsolicited: false,
875
+ description: "Third search step",
876
+ pair: null,
877
+ owner: "BAP",
878
+ },
879
+ {
880
+ key: "on_search_3",
881
+ type: "on_search",
882
+ unsolicited: false,
883
+ description: "Third on_search step",
884
+ pair: "search_3",
885
+ owner: "BPP",
886
+ },
887
+ ],
888
+ };
889
+ const config = await (0, configHelper_1.generatePlaygroundConfigFromFlowConfig)(payloads, flowConfig);
890
+ // Verify all 6 steps (3 search + 3 on_search) are present
891
+ expect(config.steps).toHaveLength(6);
892
+ // Verify the order and types of steps
893
+ expect(config.steps[0].api).toBe("search");
894
+ expect(config.steps[0].action_id).toBe("search_1");
895
+ expect(config.steps[0].mock.defaultPayload.context.timestamp).toBe("2025-01-01T09:00:00.000Z");
896
+ expect(config.steps[1].api).toBe("on_search");
897
+ expect(config.steps[1].action_id).toBe("on_search_1");
898
+ expect(config.steps[1].mock.defaultPayload.context.timestamp).toBe("2025-01-01T09:01:00.000Z");
899
+ expect(config.steps[2].api).toBe("search");
900
+ expect(config.steps[2].action_id).toBe("search_2");
901
+ expect(config.steps[2].mock.defaultPayload.context.timestamp).toBe("2025-01-01T09:02:00.000Z");
902
+ expect(config.steps[3].api).toBe("on_search");
903
+ expect(config.steps[3].action_id).toBe("on_search_2");
904
+ expect(config.steps[3].mock.defaultPayload.context.timestamp).toBe("2025-01-01T09:03:00.000Z");
905
+ expect(config.steps[4].api).toBe("search");
906
+ expect(config.steps[4].action_id).toBe("search_3");
907
+ expect(config.steps[4].mock.defaultPayload.context.timestamp).toBe("2025-01-01T09:04:00.000Z");
908
+ expect(config.steps[5].api).toBe("on_search");
909
+ expect(config.steps[5].action_id).toBe("on_search_3");
910
+ expect(config.steps[5].mock.defaultPayload.context.timestamp).toBe("2025-01-01T09:05:00.000Z");
911
+ // Verify responseFor relationships
912
+ expect(config.steps[0].responseFor).toBe("on_search_1");
913
+ expect(config.steps[1].responseFor).toBeNull();
914
+ expect(config.steps[2].responseFor).toBe("on_search_2");
915
+ expect(config.steps[3].responseFor).toBeNull();
916
+ expect(config.steps[4].responseFor).toBe("on_search_3");
917
+ expect(config.steps[5].responseFor).toBeNull();
918
+ });
785
919
  });
786
920
  describe("Edge Cases", () => {
787
921
  it("should handle config with missing description", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondc/automation-mock-runner",
3
- "version": "1.3.10",
3
+ "version": "1.3.12",
4
4
  "description": "A TypeScript library for ONDC automation mock runner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",