@ondc/automation-mock-runner 1.3.22 → 1.3.23

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.
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.validateConfigWithErrors = validateConfigWithErrors;
4
7
  exports.validateGoodConfig = validateGoodConfig;
5
8
  const mock_config_1 = require("../types/mock-config");
6
9
  const errors_1 = require("./errors");
10
+ const ajv_1 = __importDefault(require("ajv"));
7
11
  function validateConfigWithErrors(config) {
8
12
  const result = mock_config_1.MockPlaygroundConfigSchema.safeParse(config);
9
13
  if (result.success) {
@@ -25,8 +29,15 @@ function validateGoodConfig(config) {
25
29
  }
26
30
  const errors = [];
27
31
  // 2. If inputs.id is present, both sampleData and jsonSchema must also be present
32
+ // Also validate sampleData against jsonSchema when both are present
33
+ const ajv = new ajv_1.default();
28
34
  config.steps.forEach((step, index) => {
29
35
  const { id, sampleData, jsonSchema } = step.mock.inputs;
36
+ if (step.mock.inputs !== undefined) {
37
+ if (id === undefined || id === null) {
38
+ errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.id is required when inputs is defined`);
39
+ }
40
+ }
30
41
  if (id !== undefined) {
31
42
  if (sampleData === undefined || sampleData === null) {
32
43
  errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData is required when inputs.id is set`);
@@ -35,6 +46,18 @@ function validateGoodConfig(config) {
35
46
  errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.jsonSchema is required when inputs.id is set`);
36
47
  }
37
48
  }
49
+ if (sampleData !== undefined &&
50
+ sampleData !== null &&
51
+ jsonSchema !== undefined &&
52
+ jsonSchema !== null) {
53
+ const validate = ajv.compile(jsonSchema);
54
+ const valid = validate(sampleData);
55
+ if (!valid && validate.errors) {
56
+ validate.errors.forEach((e) => {
57
+ errors.push(`steps[${index}] (action_id: "${step.action_id}"): inputs.sampleData${e.dataPath} ${e.message}`);
58
+ });
59
+ }
60
+ }
38
61
  });
39
62
  // 3. Length of steps must equal length of transaction_history
40
63
  // if (config.steps.length !== config.transaction_history.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondc/automation-mock-runner",
3
- "version": "1.3.22",
3
+ "version": "1.3.23",
4
4
  "description": "A TypeScript library for ONDC automation mock runner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",