wa-chat-server
Version:
Watson Assistant powered chat server
125 lines (124 loc) • 6.42 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 });
exports.ConversationServicesTest = void 0;
const ConversationServices_1 = require("../../class/ConversationServices");
const ConversationServiceMock_1 = require("../mock/ConversationServiceMock");
const ConversationServiceMock2_1 = require("../mock/ConversationServiceMock2");
const WAChatServerConfigMock_1 = require("../mock/WAChatServerConfigMock");
const FSMock_1 = require("../mock/FSMock");
const Logger_1 = require("../../class/Logger/Logger");
class ConversationServicesTest {
constructor() {
this.schemaDir = '';
this.config = new WAChatServerConfigMock_1.WAChatServerConfigMock();
this.logger = new Logger_1.Logger(this.config);
}
obligatorySchemasListTest() {
return __awaiter(this, void 0, void 0, function* () {
it('obligatory-schemas-list', () => __awaiter(this, void 0, void 0, function* () {
expect.assertions(1);
const services = new ConversationServices_1.ConversationServices([
new ConversationServiceMock_1.ConversationServiceMock({
logger: this.logger,
requestValidation: true,
responseValidation: false,
}),
new ConversationServiceMock2_1.ConversationServiceMock2({
logger: this.logger,
requestValidation: true,
responseValidation: true,
}),
], null, this.config);
const expectedObligatorySchemas = new Set();
[
`${this.schemaDir}/request/Mock.json`,
`${this.schemaDir}/request/Mock2.json`,
`${this.schemaDir}/response/Mock2.json`,
].forEach((schema) => {
expectedObligatorySchemas.add(schema);
});
return expect(services.getObligatorySchemas()).toStrictEqual(expectedObligatorySchemas);
}));
});
}
optionalSchemasListTest() {
return __awaiter(this, void 0, void 0, function* () {
it('optional-schemas-list', () => __awaiter(this, void 0, void 0, function* () {
expect.assertions(1);
const services = new ConversationServices_1.ConversationServices([
new ConversationServiceMock_1.ConversationServiceMock({
logger: this.logger,
requestValidation: false,
responseValidation: true,
}),
new ConversationServiceMock2_1.ConversationServiceMock2({
logger: this.logger,
requestValidation: false,
responseValidation: false,
}),
], null, this.config);
const expectedOptionalSchemas = new Set();
[
`${this.schemaDir}/request/Mock.json`,
`${this.schemaDir}/request/Mock2.json`,
`${this.schemaDir}/response/Mock2.json`,
].forEach((schema) => {
expectedOptionalSchemas.add(schema);
});
return expect(services.getOptionalSchemas()).toStrictEqual(expectedOptionalSchemas);
}));
});
}
getSchemasOnFSTest() {
return __awaiter(this, void 0, void 0, function* () {
it('get-schemas-on-fs', () => __awaiter(this, void 0, void 0, function* () {
const fsMock = new FSMock_1.FSMock();
expect.assertions(1);
fsMock.addReadDirResult(['f.json', 'f.ignored']);
fsMock.addReadDirResult(['g.json', 'g.ignored']);
const services = new ConversationServices_1.ConversationServices([], fsMock, this.config);
const expectedValue = new Set();
expectedValue.add(`${this.schemaDir}/request/f.json`);
expectedValue.add(`${this.schemaDir}/response/g.json`);
const testedValue = yield services.getSchemasOnFS();
yield expect(testedValue).toStrictEqual(expectedValue);
}));
});
}
isSchemaOnFSTest() {
return __awaiter(this, void 0, void 0, function* () {
it('is-schema-on-fs', () => __awaiter(this, void 0, void 0, function* () {
const fsMock = new FSMock_1.FSMock();
expect.assertions(4);
fsMock.addReadDirResult(['f.json', 'f.ignored']);
fsMock.addReadDirResult(['g.json', 'g.ignored']);
const services = new ConversationServices_1.ConversationServices([], fsMock, this.config);
const reqDir = `${this.schemaDir}/request`;
const resDir = `${this.schemaDir}/response`;
expect(yield services.isSchemaOnFS(`${reqDir}/f.json`)).toStrictEqual(true);
expect(yield services.isSchemaOnFS(`${reqDir}/f.ignored`)).toStrictEqual(false);
expect(yield services.isSchemaOnFS(`${resDir}/g.json`)).toStrictEqual(true);
expect(yield services.isSchemaOnFS(`${resDir}/g.ignored`)).toStrictEqual(false);
}));
});
}
test() {
return __awaiter(this, void 0, void 0, function* () {
this.obligatorySchemasListTest();
this.optionalSchemasListTest();
this.getSchemasOnFSTest();
this.isSchemaOnFSTest();
});
}
}
exports.ConversationServicesTest = ConversationServicesTest;
new ConversationServicesTest().test();