UNPKG

ivr-tester-cli

Version:

CLI for automated testing of IVR call flows

68 lines (67 loc) 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scenarioConverter = exports.convertStep = exports.convertWhen = void 0; const validateJsonScenario_1 = require("./validateJsonScenario"); const isAnything_1 = require("./whenPrompt/isAnything"); const contains_1 = require("./whenPrompt/contains"); 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"); function convertWhen(jsonWhen) { switch (jsonWhen.type) { case isAnything_1.jsonWhenPromptIsAnything.typeValue: return isAnything_1.jsonWhenPromptIsAnything.converter(jsonWhen); case contains_1.jsonWhenPromptContains.typeValue: return contains_1.jsonWhenPromptContains.converter(jsonWhen); case containsSimilarTo_1.jsonWhenPromptContainsSimilarTo.typeValue: return containsSimilarTo_1.jsonWhenPromptContainsSimilarTo.converter(jsonWhen); case similarTo_1.jsonWhenPromptSimilarTo.typeValue: return similarTo_1.jsonWhenPromptSimilarTo.converter(jsonWhen); case or_1.jsonWhenPromptOr.typeValue: return or_1.jsonWhenPromptOr.converter(convertWhen)(jsonWhen); case and_1.jsonWhenPromptAnd.typeValue: return and_1.jsonWhenPromptAnd.converter(convertWhen)(jsonWhen); default: throw new Error(`Factory for whenPrompt '${JSON.stringify(jsonWhen)}' does not exist`); } } exports.convertWhen = convertWhen; function convertThen(jsonThen) { switch (jsonThen.type) { case doNothing_1.jsonThenDoNothing.typeValue: return doNothing_1.jsonThenDoNothing.converter(jsonThen); case press_1.jsonThenPress.typeValue: return press_1.jsonThenPress.converter(jsonThen); case hangUp_1.jsonThenHangUp.typeValue: return hangUp_1.jsonThenHangUp.converter(jsonThen); default: throw new Error(`Factory for then '${JSON.stringify(jsonThen)}' does not exist`); } } function convertStep(jsonStep) { return { whenPrompt: convertWhen(jsonStep.whenPrompt), then: convertThen(jsonStep.then), silenceAfterPrompt: jsonStep.silenceAfterPrompt, timeout: jsonStep.timeout, }; } exports.convertStep = convertStep; function convert(jsonScenario) { return { name: jsonScenario.name, steps: jsonScenario.steps.map(convertStep), }; } function scenarioConverter(scenario) { const validationResult = validateJsonScenario_1.validateScenario(scenario); if (validationResult.error) { throw new Error(validationResult.error.message); } return convert(validationResult.scenario); } exports.scenarioConverter = scenarioConverter;