UNPKG

ivr-tester-cli

Version:

CLI for automated testing of IVR call flows

42 lines (41 loc) 1.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateScenario = void 0; const joi_1 = __importDefault(require("joi")); const contains_1 = require("./whenPrompt/contains"); const isAnything_1 = require("./whenPrompt/isAnything"); const doNothing_1 = require("./then/doNothing"); const press_1 = require("./then/press"); const hangUp_1 = require("./then/hangUp"); const containsSimilarTo_1 = require("./whenPrompt/containsSimilarTo"); const similarTo_1 = require("./whenPrompt/similarTo"); const or_1 = require("./whenPrompt/or"); const and_1 = require("./whenPrompt/and"); const jsonScenarioSchema = joi_1.default.object({ name: joi_1.default.string().required(), steps: joi_1.default.array().items(joi_1.default.object({ whenPrompt: joi_1.default.alternatives() .try(isAnything_1.jsonWhenPromptIsAnything.schema, contains_1.jsonWhenPromptContains.schema, containsSimilarTo_1.jsonWhenPromptContainsSimilarTo.schema, similarTo_1.jsonWhenPromptSimilarTo.schema, or_1.jsonWhenPromptOr.schema, and_1.jsonWhenPromptAnd.schema) .required(), then: joi_1.default.alternatives() .try(doNothing_1.jsonThenDoNothing.schema, press_1.jsonThenPress.schema, hangUp_1.jsonThenHangUp.schema) .required(), silenceAfterPrompt: joi_1.default.number().required(), timeout: joi_1.default.number().required(), })), }).required(); const validateScenario = (scenario) => { const { error, value } = jsonScenarioSchema.validate(scenario, { presence: "required", }); if (error) { return { error }; } else { return { scenario: value }; } }; exports.validateScenario = validateScenario;