@ondc/automation-mock-runner 1.3.5 → 1.3.6
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/configHelper.js
CHANGED
|
@@ -155,10 +155,7 @@ async function getMinifiedCode(base64Code) {
|
|
|
155
155
|
*/
|
|
156
156
|
async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
|
|
157
157
|
flowConfig = JSON.parse(JSON.stringify(flowConfig));
|
|
158
|
-
flowConfig.sequence = flowConfig.sequence.filter((step) => step.type
|
|
159
|
-
if (payloads.length < flowConfig.sequence.length) {
|
|
160
|
-
throw new Error(`Insufficient payloads provided. Expected at least ${flowConfig.sequence.length}, but got ${payloads.length}`);
|
|
161
|
-
}
|
|
158
|
+
flowConfig.sequence = flowConfig.sequence.filter((step) => step.type !== "HTML_FORM" && step.type !== "DYNAMIC_FORM");
|
|
162
159
|
payloads = payloads.sort((a, b) => new Date(a.context.timestamp).getTime() -
|
|
163
160
|
new Date(b.context.timestamp).getTime());
|
|
164
161
|
const domain = payloads[0].context.domain;
|
|
@@ -171,12 +168,11 @@ async function generatePlaygroundConfigFromFlowConfig(payloads, flowConfig) {
|
|
|
171
168
|
step.type === "FORM") {
|
|
172
169
|
continue;
|
|
173
170
|
}
|
|
174
|
-
|
|
171
|
+
let stepPayload = payloads.findIndex((p) => p.context.action === step.type);
|
|
172
|
+
const payload = stepPayload === -1 ? {} : payloads[stepPayload];
|
|
175
173
|
if (stepPayload === -1) {
|
|
176
|
-
|
|
174
|
+
payloads.splice(stepPayload, 1); // remove used payload
|
|
177
175
|
}
|
|
178
|
-
const payload = payloads[stepPayload];
|
|
179
|
-
payloads.splice(stepPayload, 1); // remove used payload
|
|
180
176
|
const stepConfig = mockRunner.getDefaultStep(step.type, step.key);
|
|
181
177
|
stepConfig.mock.inputs = {};
|
|
182
178
|
stepConfig.mock.defaultPayload = payload;
|
|
@@ -626,6 +626,163 @@ describe("configHelper", () => {
|
|
|
626
626
|
});
|
|
627
627
|
});
|
|
628
628
|
});
|
|
629
|
+
describe("generatePlaygroundConfigFromFlowConfig", () => {
|
|
630
|
+
it("should generate config with meta derived from earliest payload and map steps", async () => {
|
|
631
|
+
const searchPayload = {
|
|
632
|
+
context: {
|
|
633
|
+
action: "search",
|
|
634
|
+
timestamp: "2025-01-01T09:00:00.000Z",
|
|
635
|
+
domain: "ONDC:TRV14",
|
|
636
|
+
version: "1.5.0",
|
|
637
|
+
},
|
|
638
|
+
};
|
|
639
|
+
const onSearchPayload = {
|
|
640
|
+
context: {
|
|
641
|
+
action: "on_search",
|
|
642
|
+
timestamp: "2025-01-02T10:00:00.000Z",
|
|
643
|
+
domain: "ONDC:TRV14",
|
|
644
|
+
version: "1.5.0",
|
|
645
|
+
},
|
|
646
|
+
};
|
|
647
|
+
// Intentionally unsorted by timestamp to verify internal sorting
|
|
648
|
+
const payloads = [onSearchPayload, searchPayload];
|
|
649
|
+
const flowConfig = {
|
|
650
|
+
id: "sample_flow",
|
|
651
|
+
title: "Sample Flow",
|
|
652
|
+
description: "Test flow for playground config generation",
|
|
653
|
+
sequence: [
|
|
654
|
+
{
|
|
655
|
+
key: "search_step",
|
|
656
|
+
type: "search",
|
|
657
|
+
unsolicited: false,
|
|
658
|
+
description: "Search step",
|
|
659
|
+
pair: null,
|
|
660
|
+
owner: "BAP",
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
key: "on_search_step",
|
|
664
|
+
type: "on_search",
|
|
665
|
+
unsolicited: false,
|
|
666
|
+
description: "On search step",
|
|
667
|
+
pair: "search_step",
|
|
668
|
+
owner: "BPP",
|
|
669
|
+
},
|
|
670
|
+
],
|
|
671
|
+
};
|
|
672
|
+
const config = await (0, configHelper_1.generatePlaygroundConfigFromFlowConfig)(payloads, flowConfig);
|
|
673
|
+
expect(config.meta.domain).toBe("ONDC:TRV14");
|
|
674
|
+
expect(config.meta.version).toBe("1.5.0");
|
|
675
|
+
expect(config.meta.flowId).toBe("sample_flow_logs_flow_ONDC:TRV14_v1.5.0");
|
|
676
|
+
expect(config.steps).toHaveLength(2);
|
|
677
|
+
const [searchStepConfig, onSearchStepConfig] = config.steps;
|
|
678
|
+
expect(searchStepConfig.api).toBe("search");
|
|
679
|
+
expect(searchStepConfig.action_id).toBe("search_step");
|
|
680
|
+
expect(searchStepConfig.responseFor).toBe("on_search_step");
|
|
681
|
+
expect(searchStepConfig.unsolicited).toBe(false);
|
|
682
|
+
expect(searchStepConfig.mock.inputs).toEqual({});
|
|
683
|
+
expect(searchStepConfig.mock.defaultPayload).toBe(searchPayload);
|
|
684
|
+
expect(onSearchStepConfig.api).toBe("on_search");
|
|
685
|
+
expect(onSearchStepConfig.action_id).toBe("on_search_step");
|
|
686
|
+
expect(onSearchStepConfig.responseFor).toBeNull();
|
|
687
|
+
expect(onSearchStepConfig.unsolicited).toBe(false);
|
|
688
|
+
expect(onSearchStepConfig.mock.inputs).toEqual({});
|
|
689
|
+
expect(onSearchStepConfig.mock.defaultPayload).toBe(onSearchPayload);
|
|
690
|
+
});
|
|
691
|
+
it("should ignore HTML_FORM and DYNAMIC_FORM steps and preserve unsolicited flag", async () => {
|
|
692
|
+
const payloads = [
|
|
693
|
+
{
|
|
694
|
+
context: {
|
|
695
|
+
action: "search",
|
|
696
|
+
timestamp: "2025-01-01T09:00:00.000Z",
|
|
697
|
+
domain: "ONDC:RET10",
|
|
698
|
+
version: "2.0.0",
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
context: {
|
|
703
|
+
action: "on_status",
|
|
704
|
+
timestamp: "2025-01-01T10:00:00.000Z",
|
|
705
|
+
domain: "ONDC:RET10",
|
|
706
|
+
version: "2.0.0",
|
|
707
|
+
},
|
|
708
|
+
},
|
|
709
|
+
];
|
|
710
|
+
const flowConfig = {
|
|
711
|
+
id: "flow_with_forms",
|
|
712
|
+
sequence: [
|
|
713
|
+
{
|
|
714
|
+
key: "search_step",
|
|
715
|
+
type: "search",
|
|
716
|
+
unsolicited: false,
|
|
717
|
+
description: "Search step",
|
|
718
|
+
pair: null,
|
|
719
|
+
owner: "BAP",
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
key: "html_form_step",
|
|
723
|
+
type: "HTML_FORM",
|
|
724
|
+
unsolicited: false,
|
|
725
|
+
description: "HTML form step",
|
|
726
|
+
pair: null,
|
|
727
|
+
owner: "BAP",
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
key: "dynamic_form_step",
|
|
731
|
+
type: "DYNAMIC_FORM",
|
|
732
|
+
unsolicited: false,
|
|
733
|
+
description: "Dynamic form step",
|
|
734
|
+
pair: null,
|
|
735
|
+
owner: "BAP",
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
key: "on_status_step",
|
|
739
|
+
type: "on_status",
|
|
740
|
+
unsolicited: true,
|
|
741
|
+
description: "Unsolicited status",
|
|
742
|
+
pair: null,
|
|
743
|
+
owner: "BPP",
|
|
744
|
+
},
|
|
745
|
+
],
|
|
746
|
+
};
|
|
747
|
+
const config = await (0, configHelper_1.generatePlaygroundConfigFromFlowConfig)(payloads, flowConfig);
|
|
748
|
+
// Only non-form steps should be present
|
|
749
|
+
expect(config.steps.map((s) => s.action_id)).toEqual([
|
|
750
|
+
"search_step",
|
|
751
|
+
"on_status_step",
|
|
752
|
+
]);
|
|
753
|
+
const onStatusStep = config.steps.find((s) => s.action_id === "on_status_step");
|
|
754
|
+
expect(onStatusStep?.unsolicited).toBe(true);
|
|
755
|
+
});
|
|
756
|
+
it("should derive version from core_version when version is missing", async () => {
|
|
757
|
+
const payloads = [
|
|
758
|
+
{
|
|
759
|
+
context: {
|
|
760
|
+
action: "search",
|
|
761
|
+
timestamp: "2025-01-01T09:00:00.000Z",
|
|
762
|
+
domain: "ONDC:FIS12",
|
|
763
|
+
core_version: "1.0.0",
|
|
764
|
+
},
|
|
765
|
+
},
|
|
766
|
+
];
|
|
767
|
+
const flowConfig = {
|
|
768
|
+
id: "core_version_flow",
|
|
769
|
+
sequence: [
|
|
770
|
+
{
|
|
771
|
+
key: "search_step",
|
|
772
|
+
type: "search",
|
|
773
|
+
unsolicited: false,
|
|
774
|
+
description: "Search step",
|
|
775
|
+
pair: null,
|
|
776
|
+
owner: "BAP",
|
|
777
|
+
},
|
|
778
|
+
],
|
|
779
|
+
};
|
|
780
|
+
const config = await (0, configHelper_1.generatePlaygroundConfigFromFlowConfig)(payloads, flowConfig);
|
|
781
|
+
expect(config.meta.domain).toBe("ONDC:FIS12");
|
|
782
|
+
expect(config.meta.version).toBe("1.0.0");
|
|
783
|
+
expect(config.meta.flowId).toBe("core_version_flow_logs_flow_ONDC:FIS12_v1.0.0");
|
|
784
|
+
});
|
|
785
|
+
});
|
|
629
786
|
describe("Edge Cases", () => {
|
|
630
787
|
it("should handle config with missing description", () => {
|
|
631
788
|
const configWithoutDesc = {
|