UNPKG

clwoz-models

Version:
79 lines 3.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var ObiUtils_1 = require("./ObiUtils"); var testDataToMap = function (data) { var output = []; for (var _i = 0, data_1 = data; _i < data_1.length; _i++) { var datum = data_1[_i]; var d = { lgName: datum.tag, text: datum.text, suggestions: datum.suggestions }; output.push(d); } return output; }; describe('OBIutils', function () { describe('ObiUtils', function () { test('Given a well-formed input, verifies the expected output', function () { var input = "\n # option0\n - ```\n Hi! I'm a virtual agent. I can help with account questions, orders, store information, and more.\n [Suggestions=]\n ```\n # option1\n - ```\n If you'd like to speak to a human agent, let me know at any time.\n [Suggestions=Talk to agent|Goodbye]\n ```\n "; var lgMap = []; ObiUtils_1.ObiUtils.addToLGMap(input, lgMap); var expected = testDataToMap([ { tag: 'option0', text: "Hi! I'm a virtual agent. I can help with account questions, orders, store information, and more.", suggestions: [] }, { tag: 'option1', text: "If you'd like to speak to a human agent, let me know at any time.", suggestions: ['Talk to agent', 'Goodbye'] } ]); expect(lgMap).toMatchObject(expected); }); test('Validate exception on missing expected tokens', function () { var inputs = [ { missing_str: '-', input: "\n # option0\n ```\n This config is missing a hyphen\n [Suggestions=]\n ```\n " }, { // Not '```' since the input contains it later. missing_str: '```', input: "\n # option0\n -\n This config is missing the leading 3 backticks\n [Suggestions=]\n ```\n " }, { missing_str: '[', input: "\n # option0\n - ```\n This config is missing an open bracket\n Suggestions=]\n ```\n " }, { missing_str: ']', input: "\n # option0\n - ```\n This config is missing a close bracket\n [Suggestions=\n ```\n " }, ]; for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) { var data = inputs_1[_i]; try { ObiUtils_1.ObiUtils.addToLGMap(data.input, []); fail('Did not get expected exception'); } catch (e) { if (e instanceof RangeError) { expect(e.message).toBe(data.missing_str + " not found"); } else { fail('Unexpected error'); } } } }); }); }); //# sourceMappingURL=ObiUtils.test.js.map