wa-chat-server
Version:
Watson Assistant powered chat server
70 lines (69 loc) • 3.96 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.AuthenticationPreProcessingServiceTest = void 0;
const MessageRequestMock_1 = require("../mock/MessageRequestMock");
const UserMock_1 = require("../mock/UserMock");
const AuthenticationPreProcessingService_1 = require("../../class/PreProcessingService/AuthenticationPreProcessingService");
const Logger_1 = require("../../class/Logger/Logger");
const LoggerDriverMock_1 = require("../mock/LoggerDriverMock");
const WAChatServerConfigMock_1 = require("../mock/WAChatServerConfigMock");
const SessionMock_1 = require("../mock/SessionMock");
class AuthenticationPreProcessingServiceTest {
constructor() {
this.user = new UserMock_1.UserMock();
this.config = new WAChatServerConfigMock_1.WAChatServerConfigMock();
this.authService = new AuthenticationPreProcessingService_1.AuthenticationPreProcessingService(this.getLogger(), this.config);
}
getLogger(check = false, silence = true) {
return new Logger_1.Logger(this.config, new LoggerDriverMock_1.LoggerDriverMock(check, silence));
}
givenUserAuthenticatedWhenConversationCalledThenAuthenticationContextSet() {
return __awaiter(this, void 0, void 0, function* () {
it('givenUserAuthenticatedWhenConversationCalledThenAuthenticationContextSet', () => __awaiter(this, void 0, void 0, function* () {
expect.assertions(1);
const request = new MessageRequestMock_1.MessageRequestMock();
const session = new SessionMock_1.SessionMock();
session.data = {
general: {
azure: {
user: {},
},
},
};
yield this.authService.processRequest(request, session);
const result = 'true';
return expect(request.context.internal.authentication.isAuthenticated).toStrictEqual(result);
}));
});
}
givenUserNotAuthenticationWhenConversationCalledThenAuthenticationContextNotSet() {
return __awaiter(this, void 0, void 0, function* () {
it('givenUserNotAuthenticationWhenConversationCalledThenAuthenticationContextNotSet', () => __awaiter(this, void 0, void 0, function* () {
expect.assertions(1);
const request = new MessageRequestMock_1.MessageRequestMock();
const session = new SessionMock_1.SessionMock();
yield this.authService.processRequest(request, session);
return expect(request.context.internal &&
request.context.internal.authentication &&
request.context.internal.authentication.isAuthenticated).toBeUndefined();
}));
});
}
test() {
return __awaiter(this, void 0, void 0, function* () {
this.givenUserAuthenticatedWhenConversationCalledThenAuthenticationContextSet();
this.givenUserNotAuthenticationWhenConversationCalledThenAuthenticationContextNotSet();
});
}
}
exports.AuthenticationPreProcessingServiceTest = AuthenticationPreProcessingServiceTest;
new AuthenticationPreProcessingServiceTest().test();