@ondc/automation-mock-runner 1.3.54 → 1.3.56
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
|
@@ -123,5 +123,7 @@ export declare class MockRunner {
|
|
|
123
123
|
static encodeBase64(input: string): string;
|
|
124
124
|
static decodeBase64(encoded: string): string;
|
|
125
125
|
private static resolveBaseActionId;
|
|
126
|
+
private resolveStep;
|
|
127
|
+
private allActionIds;
|
|
126
128
|
private static getIdFromSession;
|
|
127
129
|
}
|
package/dist/lib/MockRunner.js
CHANGED
|
@@ -162,12 +162,10 @@ class MockRunner {
|
|
|
162
162
|
actionId,
|
|
163
163
|
sessionKeys: Object.keys(sessionData),
|
|
164
164
|
});
|
|
165
|
-
const step = this.
|
|
165
|
+
const step = this.resolveStep(baseActionId);
|
|
166
166
|
if (!step) {
|
|
167
|
-
|
|
168
|
-
throw new errors_1.ActionNotFoundError(actionId, availableActions);
|
|
167
|
+
throw new errors_1.ActionNotFoundError(actionId, this.allActionIds());
|
|
169
168
|
}
|
|
170
|
-
const index = this.config.steps.findIndex((s) => s.action_id === baseActionId);
|
|
171
169
|
// Deep clone to avoid mutations
|
|
172
170
|
const defaultPayload = JSON.parse(JSON.stringify(step.mock.defaultPayload));
|
|
173
171
|
const context = this.generateContext(step.action_id, step.api, sessionData);
|
|
@@ -248,7 +246,7 @@ class MockRunner {
|
|
|
248
246
|
async runValidatePayloadWithSession(actionId, targetPayload, sessionData) {
|
|
249
247
|
try {
|
|
250
248
|
const baseActionId = MockRunner.resolveBaseActionId(actionId);
|
|
251
|
-
const step = this.
|
|
249
|
+
const step = this.resolveStep(baseActionId);
|
|
252
250
|
if (!step) {
|
|
253
251
|
throw new Error(`Action step with ID ${actionId} not found.`);
|
|
254
252
|
}
|
|
@@ -300,7 +298,7 @@ class MockRunner {
|
|
|
300
298
|
async runMeetRequirementsWithSession(actionId, sessionData) {
|
|
301
299
|
try {
|
|
302
300
|
const baseActionId = MockRunner.resolveBaseActionId(actionId);
|
|
303
|
-
const step = this.
|
|
301
|
+
const step = this.resolveStep(baseActionId);
|
|
304
302
|
if (!step) {
|
|
305
303
|
throw new Error(`Action step with ID ${actionId} not found.`);
|
|
306
304
|
}
|
|
@@ -423,7 +421,7 @@ class MockRunner {
|
|
|
423
421
|
// GENERATED#1#on_search_full_page_gcr
|
|
424
422
|
// get the last by splitting on # and taking the last part
|
|
425
423
|
const baseActionId = MockRunner.resolveBaseActionId(actionId);
|
|
426
|
-
const step = this.
|
|
424
|
+
const step = this.resolveStep(baseActionId);
|
|
427
425
|
// Determine the message_id based on responseFor logic
|
|
428
426
|
let messageId = (0, uuid_1.v4)();
|
|
429
427
|
if (step?.responseFor) {
|
|
@@ -635,6 +633,18 @@ class MockRunner {
|
|
|
635
633
|
static resolveBaseActionId(actionId) {
|
|
636
634
|
return actionId.split("#").slice(-1)[0];
|
|
637
635
|
}
|
|
636
|
+
// Resolve a step by base action id across main steps then extra steps.
|
|
637
|
+
resolveStep(baseActionId) {
|
|
638
|
+
return (this.config.steps.find((s) => s.action_id === baseActionId) ??
|
|
639
|
+
this.config.extra_steps?.steps.find((s) => s.action_id === baseActionId));
|
|
640
|
+
}
|
|
641
|
+
// All known action ids (main + extra), for error messages.
|
|
642
|
+
allActionIds() {
|
|
643
|
+
return [
|
|
644
|
+
...this.config.steps.map((s) => s.action_id),
|
|
645
|
+
...(this.config.extra_steps?.steps.map((s) => s.action_id) ?? []),
|
|
646
|
+
];
|
|
647
|
+
}
|
|
638
648
|
static getIdFromSession(sessionData, key) {
|
|
639
649
|
if (sessionData === undefined) {
|
|
640
650
|
return undefined;
|
package/dist/lib/configHelper.js
CHANGED
|
@@ -166,6 +166,17 @@ async function createOptimizedMockConfig(config) {
|
|
|
166
166
|
},
|
|
167
167
|
};
|
|
168
168
|
}));
|
|
169
|
+
const optimizedExtraSteps = config.extra_steps ? await Promise.all(config.extra_steps.steps.map(async (step) => {
|
|
170
|
+
return {
|
|
171
|
+
...step,
|
|
172
|
+
mock: {
|
|
173
|
+
...step.mock,
|
|
174
|
+
generate: await getMinifiedCode(step.mock.generate),
|
|
175
|
+
validate: await getMinifiedCode(step.mock.validate),
|
|
176
|
+
requirements: await getMinifiedCode(step.mock.requirements),
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
})) : [];
|
|
169
180
|
const optimizedConfig = {
|
|
170
181
|
meta: config.meta,
|
|
171
182
|
transaction_history: [],
|
|
@@ -173,6 +184,9 @@ async function createOptimizedMockConfig(config) {
|
|
|
173
184
|
validationLib: config.validationLib,
|
|
174
185
|
transaction_data: config.transaction_data,
|
|
175
186
|
steps: optimizedSteps,
|
|
187
|
+
extra_steps: {
|
|
188
|
+
steps: optimizedExtraSteps,
|
|
189
|
+
}
|
|
176
190
|
};
|
|
177
191
|
return optimizedConfig;
|
|
178
192
|
}
|
|
@@ -719,4 +719,58 @@ describe("MockRunner", () => {
|
|
|
719
719
|
expect(result.success).toBe(true);
|
|
720
720
|
});
|
|
721
721
|
});
|
|
722
|
+
describe("extra steps support in *WithSession methods", () => {
|
|
723
|
+
let runner;
|
|
724
|
+
beforeEach(async () => {
|
|
725
|
+
const baseConfig = {
|
|
726
|
+
meta: {
|
|
727
|
+
domain: "ONDC:TRV14",
|
|
728
|
+
version: "2.0.0",
|
|
729
|
+
flowId: "extra-steps-test",
|
|
730
|
+
},
|
|
731
|
+
transaction_data: {
|
|
732
|
+
transaction_id: "extra-steps-txn-id",
|
|
733
|
+
latest_timestamp: "1970-01-01T00:00:00.000Z",
|
|
734
|
+
},
|
|
735
|
+
steps: [],
|
|
736
|
+
transaction_history: [],
|
|
737
|
+
validationLib: "",
|
|
738
|
+
helperLib: "",
|
|
739
|
+
};
|
|
740
|
+
const base = new MockRunner_1.MockRunner(baseConfig, true);
|
|
741
|
+
base.getConfig().steps.push(base.getDefaultStep("search", "search_0"));
|
|
742
|
+
const optimized = await (0, configHelper_1.createOptimizedMockConfig)(base.getConfig());
|
|
743
|
+
// createOptimizedMockConfig drops extra_steps, so attach an extra step
|
|
744
|
+
// (absent from main steps) after optimizing the main steps.
|
|
745
|
+
optimized.extra_steps = {
|
|
746
|
+
steps: [base.getDefaultStep("on_status", "on_status_0")],
|
|
747
|
+
};
|
|
748
|
+
runner = new MockRunner_1.MockRunner(optimized, true);
|
|
749
|
+
});
|
|
750
|
+
it("runGeneratePayloadWithSession resolves a step from extra_steps", async () => {
|
|
751
|
+
const result = await runner.runGeneratePayloadWithSession("on_status_0", {
|
|
752
|
+
transaction_id: "some-txn",
|
|
753
|
+
});
|
|
754
|
+
expect(result.success).toBe(true);
|
|
755
|
+
});
|
|
756
|
+
it("runValidatePayloadWithSession resolves a step from extra_steps", async () => {
|
|
757
|
+
const result = await runner.runValidatePayloadWithSession("on_status_0", { context: {}, message: {} }, {});
|
|
758
|
+
expect(result.success).toBe(true);
|
|
759
|
+
});
|
|
760
|
+
it("runMeetRequirementsWithSession resolves a step from extra_steps", async () => {
|
|
761
|
+
const result = await runner.runMeetRequirementsWithSession("on_status_0", {});
|
|
762
|
+
expect(result.success).toBe(true);
|
|
763
|
+
});
|
|
764
|
+
it("main steps still resolve (main takes precedence over extras)", async () => {
|
|
765
|
+
const result = await runner.runGeneratePayloadWithSession("search_0", {
|
|
766
|
+
transaction_id: "some-txn",
|
|
767
|
+
});
|
|
768
|
+
expect(result.success).toBe(true);
|
|
769
|
+
});
|
|
770
|
+
it("an action id in neither main nor extra returns failure", async () => {
|
|
771
|
+
const result = await runner.runGeneratePayloadWithSession("not_a_real_action", {});
|
|
772
|
+
expect(result.success).toBe(false);
|
|
773
|
+
expect(result.error?.message).toContain("not_a_real_action");
|
|
774
|
+
});
|
|
775
|
+
});
|
|
722
776
|
});
|