wa-chat-server-mluvii
Version:
Mluvii adapter for the modules wa-chat-server
119 lines (118 loc) • 4.63 kB
JavaScript
;
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 MluviiToWatsonConverter_1 = require("../../class/MluviiToWatsonConverter");
class MluviiToWatsonConverterTest {
getSession() {
return new SessionMock_1.SessionMock();
}
getConverter(mluviiRequest) {
const log = new LoggerMock_1.LoggerMock();
const dependencies = {
log,
axios: null,
watsonToMluviiConverterClass: null,
};
return new MluviiToWatsonConverter_1.MluviiToWatsonConverter(mluviiRequest, dependencies, this.getSession());
}
textTest() {
return __awaiter(this, void 0, void 0, function* () {
it('text', () => {
expect.assertions(1);
const mluviiRequest = {
activity: 'Text',
text: 'T',
};
const watsonRequest = {
input: {
text: 'T',
},
};
const converter = this.getConverter(mluviiRequest);
expect(converter.convert()).toEqual(watsonRequest);
});
});
}
suggestionsMatchedTest() {
return __awaiter(this, void 0, void 0, function* () {
it('suggestions-matched', () => {
expect.assertions(2);
const mluviiRequest = {
activity: 'Text',
text: 'L2',
};
const converter = this.getConverter(mluviiRequest);
converter.session.data = {
mluvii: {
suggestions: [
{
label: 'L1',
input: { suggestion_id: 'S1' },
},
{
label: 'L2',
input: { suggestion_id: 'S2' },
},
],
},
};
const watsonRequest = {
input: {
suggestion_id: 'S2',
},
};
expect(converter.convert()).toEqual(watsonRequest);
expect(converter.session.data.mluvii.suggestions).toBeUndefined();
});
});
}
suggestionsNotMatchedTest() {
return __awaiter(this, void 0, void 0, function* () {
it('suggestions-not-matched', () => {
expect.assertions(2);
const mluviiRequest = {
activity: 'Text',
text: 'T',
};
const converter = this.getConverter(mluviiRequest);
converter.session.data = {
mluvii: {
suggestions: [
{
label: 'L1',
input: { suggestion_id: 'S1' },
},
{
label: 'L2',
input: { suggestion_id: 'S2' },
},
],
},
};
const watsonRequest = {
input: {
text: 'T',
},
};
expect(converter.convert()).toEqual(watsonRequest);
expect(converter.session.data.mluvii.suggestions).toBeUndefined();
});
});
}
test() {
this.textTest();
this.suggestionsMatchedTest();
this.suggestionsNotMatchedTest();
}
}
new MluviiToWatsonConverterTest().test();