@ondc/automation-mock-runner 1.3.50 → 1.3.51
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.
|
@@ -342,7 +342,7 @@ class CodeValidator {
|
|
|
342
342
|
*/
|
|
343
343
|
static checkBestPractices(ast, schema) {
|
|
344
344
|
const warnings = [];
|
|
345
|
-
const hasReturn = this.collectTopLevelReturns(ast).length > 0;
|
|
345
|
+
const hasReturn = this.collectTopLevelReturns(ast, schema.name).length > 0;
|
|
346
346
|
if (!hasReturn) {
|
|
347
347
|
warnings.push(`Function should return a value (expected: ${schema.returnType.description})`);
|
|
348
348
|
}
|
|
@@ -4,6 +4,7 @@ const code_validator_1 = require("../lib/validators/code-validator");
|
|
|
4
4
|
const function_registry_1 = require("../lib/constants/function-registry");
|
|
5
5
|
const validateSchema = (0, function_registry_1.getFunctionSchema)("validate");
|
|
6
6
|
const meetsRequirementsSchema = (0, function_registry_1.getFunctionSchema)("meetsRequirements");
|
|
7
|
+
const generateSchema = (0, function_registry_1.getFunctionSchema)("generate");
|
|
7
8
|
describe("CodeValidator.validate — return structure", () => {
|
|
8
9
|
it("accepts an outer return with the full expected shape", () => {
|
|
9
10
|
const code = `
|
|
@@ -76,6 +77,26 @@ describe("CodeValidator.validate — return structure", () => {
|
|
|
76
77
|
`;
|
|
77
78
|
const result = code_validator_1.CodeValidator.validate(code, validateSchema);
|
|
78
79
|
expect(result.errors).toEqual([]);
|
|
80
|
+
expect(result.warnings).toEqual([]);
|
|
81
|
+
expect(result.isValid).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
it("does not warn 'should return a value' when target fn has a return (validate)", () => {
|
|
84
|
+
const code = `
|
|
85
|
+
function validate(targetPayload, sessionData) {
|
|
86
|
+
return { valid: true, code: 200, description: "Valid request" };
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
const result = code_validator_1.CodeValidator.validate(code, validateSchema);
|
|
90
|
+
expect(result.warnings.some((w) => w.includes("should return a value"))).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
it("does not warn 'should return a value' for generate with a return", () => {
|
|
93
|
+
const code = `
|
|
94
|
+
async function generate(defaultPayload, sessionData) {
|
|
95
|
+
return defaultPayload;
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
const result = code_validator_1.CodeValidator.validate(code, generateSchema);
|
|
99
|
+
expect(result.warnings.some((w) => w.includes("should return a value"))).toBe(false);
|
|
79
100
|
expect(result.isValid).toBe(true);
|
|
80
101
|
});
|
|
81
102
|
it("ignores sibling top-level helper function returns (meetsRequirements)", () => {
|