UNPKG

wa-chat-server-mluvii

Version:

Mluvii adapter for the modules wa-chat-server

226 lines (225 loc) 8.89 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const LoggerMock_1 = require("../mock/LoggerMock"); const SessionMock_1 = require("../mock/SessionMock"); const WatsonToMluviiConverter_1 = require("../../class/WatsonToMluviiConverter"); class WatsonToMluviiConverterTest { getSession() { return new SessionMock_1.SessionMock(); } getConverter(watsonResponse) { const log = new LoggerMock_1.LoggerMock(); const dependencies = { log, axios: null, watsonToMluviiConverterClass: null, }; return new WatsonToMluviiConverter_1.WatsonToMluviiConverter(watsonResponse, dependencies, this.getSession()); } textTest() { return __awaiter(this, void 0, void 0, function* () { it('text', () => { const watsonResponse = { result: { output: { generic: [ { response_type: 'text', text: 'T', }, ], }, }, }; const mluviiActivities = [ { type: 'message', text: 'T', }, ]; const converter = this.getConverter(watsonResponse); expect(converter.convert()).toEqual(mluviiActivities); }); }); } markupTest() { return __awaiter(this, void 0, void 0, function* () { it('markup', () => { const watsonResponse = { result: { output: { generic: [ { response_type: 'text', text: '<strong>S</strong><a href="http://i.cz">L</a>', }, ], }, }, }; const mluviiActivities = [ { type: 'message', text: '**S**[L](http://i.cz)', }, ]; const converter = this.getConverter(watsonResponse); expect(converter.convert()).toEqual(mluviiActivities); }); }); } textAndButtonsTest() { return __awaiter(this, void 0, void 0, function* () { it('text-and-buttons', () => { const watsonResponse = { result: { output: { generic: [ { response_type: 'text', text: 'T', }, { response_type: 'option', options: [ { label: 'L1', value: { input: { text: 'T1' } }, }, { label: 'L2', value: { input: { text: 'T2' } }, }, ], }, ], }, }, }; const mluviiActivities = [ { type: 'message', text: 'T', attachments: [ { contentType: 'application/vnd.microsoft.card.hero', content: { buttons: [ { type: 'imBack', title: 'L1', value: 'T1', }, { type: 'imBack', title: 'L2', value: 'T2', }, ], }, }, ], }, ]; const converter = this.getConverter(watsonResponse); expect(converter.convert()).toEqual(mluviiActivities); }); }); } suggestionsTest() { return __awaiter(this, void 0, void 0, function* () { it('suggetions', () => { expect.assertions(2); const suggestions = [ { label: 'L1', value: { input: { suggestion_id: 'S1', }, }, }, { label: 'L2', value: { input: { suggestion_id: 'S2', }, }, }, ]; const suggestionsInSession = [ { label: 'L1', input: { suggestion_id: 'S1', }, }, { label: 'L2', input: { suggestion_id: 'S2', }, }, ]; const watsonResponse = { result: { output: { generic: [ { response_type: 'suggestion', title: 'T', suggestions, }, ], }, }, }; const mluviiActivities = [ { type: 'message', text: 'T', attachments: [ { contentType: 'application/vnd.microsoft.card.hero', content: { buttons: [ { type: 'imBack', title: 'L1', value: 'L1', }, { type: 'imBack', title: 'L2', value: 'L2', }, ], }, }, ], }, ]; const converter = this.getConverter(watsonResponse); expect(converter.convert()).toEqual(mluviiActivities); expect(converter.session.data.mluvii.suggestions).toEqual(suggestionsInSession); }); }); } test() { this.textTest(); this.markupTest(); this.textAndButtonsTest(); this.suggestionsTest(); } } new WatsonToMluviiConverterTest().test();