ivr-tester-cli
Version:
CLI for automated testing of IVR call flows
48 lines (47 loc) • 2.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCli = void 0;
const commander_1 = require("commander");
const fs_1 = require("fs");
const ivr_tester_1 = require("ivr-tester");
const ngrok_1 = __importDefault(require("ngrok"));
const createProgram_1 = require("./createProgram");
const loadScenarioOption_1 = require("./options/scenario/loadScenarioOption");
const loadConfigOption_1 = require("./options/config/loadConfigOption");
const jsonFileReader_1 = require("./fileSystem/jsonFileReader");
const readableFileValidator_1 = require("./fileSystem/readableFileValidator");
function createCli({ ivrTesterFactory = (config) => new ivr_tester_1.IvrTester(config), ngrokServer = ngrok_1.default, outputConsole = console, program = createProgram_1.createProgram(new commander_1.Command(), false), fsReadFileSync = fs_1.readFileSync, fsAccessSync = fs_1.accessSync, requireModule = require, } = {}) {
program.command.requiredOption("-f, --from <phoneNumber>", "Phone number calling from e.g. +441234567890");
program.command.requiredOption("-t, --to <phoneNumber>", "Phone number to be called e.g. +441234567890");
program.command.requiredOption("-c, --config-path <filePath>", "path of the config file", readableFileValidator_1.readableFileValidator(fsAccessSync));
program.command.requiredOption("-s, --scenario-path <filePath>", "path of the scenario file", readableFileValidator_1.readableFileValidator(fsAccessSync));
const jsonFileReader = jsonFileReader_1.createJsonFileReader(fsReadFileSync);
return async function (args) {
program.command.parse(args);
const options = program.command.opts();
let scenario;
try {
scenario = loadScenarioOption_1.loadScenarioOption(options, jsonFileReader);
}
catch (error) {
program.exit(error.message);
}
let config;
try {
config = loadConfigOption_1.loadConfigOption(options, jsonFileReader, requireModule);
}
catch (error) {
program.exit(error.message);
}
const call = {
from: options.from,
to: options.to,
};
const url = await ngrokServer.connect(config.localServerPort);
await ivrTesterFactory({ ...config, publicServerUrl: url }).run(call, scenario);
};
}
exports.createCli = createCli;