Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@microsoft/omnichannel-chat-sdk

Package Overview
Dependencies
Maintainers
5
Versions
336
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/omnichannel-chat-sdk - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1-main.30dc1d1

__tests__/OmnichannelChatSDK.node.spec.ts

599

__tests__/OmnichannelChatSDK.spec.ts
const OmnichannelChatSDK = require('../src/OmnichannelChatSDK').default;
import IFileInfo from "@microsoft/omnichannel-ic3core/lib/interfaces/IFileInfo";
import FileSharingProtocolType from "@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType";
import IFileMetadata from "@microsoft/omnichannel-ic3core/lib/model/IFileMetadata";
import IMessage from "@microsoft/omnichannel-ic3core/lib/model/IMessage";
import PersonType from "@microsoft/omnichannel-ic3core/lib/model/PersonType";

@@ -25,3 +30,3 @@ describe('Omnichannel Chat SDK', () => {

});
})
});

@@ -120,3 +125,3 @@ describe('Functionalities', () => {

it('ChatSDK.startchat() with existing liveChatContext should not call OCClient.getChatToken', async() => {
it('ChatSDK.startChat() should fail if OCClient.sessiontInit() fails', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);

@@ -126,2 +131,3 @@ chatSDK.getChatConfig = jest.fn();

await chatSDK.initialize();
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({

@@ -133,4 +139,90 @@ ChatId: '',

jest.spyOn(chatSDK.OCClient, 'sessionInit').mockRejectedValue(Promise.reject());
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve());
jest.spyOn(console, 'error');
try {
await chatSDK.startChat();
} catch (error) {
expect(console.error).toHaveBeenCalled();
}
expect(chatSDK.OCClient.sessionInit).toHaveBeenCalledTimes(1);
expect(chatSDK.IC3Client.initialize).toHaveBeenCalledTimes(0);
expect(chatSDK.IC3Client.joinConversation).toHaveBeenCalledTimes(0);
});
it('ChatSDK.startChat() should fail if IC3Client.initialize() fails', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
await chatSDK.initialize();
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({
ChatId: '',
Token: '',
RegionGtms: '{}'
}));
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'initialize').mockRejectedValue(Promise.reject());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve());
jest.spyOn(console, 'error');
try {
await chatSDK.startChat();
} catch (error) {
expect(console.error).toHaveBeenCalled();
}
expect(chatSDK.OCClient.sessionInit).toHaveBeenCalledTimes(1);
expect(chatSDK.IC3Client.initialize).toHaveBeenCalledTimes(1);
expect(chatSDK.IC3Client.joinConversation).toHaveBeenCalledTimes(0);
});
it('ChatSDK.startChat() should fail if IC3Client.joinConversation() fails', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
await chatSDK.initialize();
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({
ChatId: '',
Token: '',
RegionGtms: '{}'
}));
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockRejectedValue(Promise.reject());
jest.spyOn(console, 'error');
try {
await chatSDK.startChat();
} catch (error) {
expect(console.error).toHaveBeenCalled();
}
expect(chatSDK.OCClient.sessionInit).toHaveBeenCalledTimes(1);
expect(chatSDK.IC3Client.initialize).toHaveBeenCalledTimes(1);
expect(chatSDK.IC3Client.joinConversation).toHaveBeenCalledTimes(1);
});
it('ChatSDK.startchat() with existing liveChatContext should not call OCClient.getChatToken()', async() => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
await chatSDK.initialize();
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({
ChatId: '',
Token: '',
RegionGtms: '{}'
}));
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve());

@@ -159,2 +251,16 @@

it('ChatSDK.getLiveChatConfig() should return the cached value by default', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.liveChatConfig = {
id: 0
}
const liveChatConfig = await chatSDK.getLiveChatConfig();
expect(liveChatConfig.id).toBe(chatSDK.liveChatConfig.id);
expect(chatSDK.getChatConfig).toHaveBeenCalledTimes(0);
});
it('ChatSDK.startChat() with preChatResponse should pass it to OCClient.sessionInit() call\'s optional parameters', async() => {

@@ -221,3 +327,2 @@ const chatSDK = new OmnichannelChatSDK(omnichannelConfig);

jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({

@@ -246,2 +351,79 @@ ChatId: '',

it('ChatSDK.getCurrentLiveChatContext() should return chat session data', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
await chatSDK.initialize();
chatSDK.IC3Client = {
initialize: jest.fn(),
joinConversation: jest.fn()
}
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({
ChatId: '',
Token: '',
RegionGtms: '{}'
}));
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
await chatSDK.startChat();
const chatContext = await chatSDK.getCurrentLiveChatContext();
expect(Object.keys(chatContext).includes('chatToken')).toBe(true);
expect(Object.keys(chatContext).includes('requestId')).toBe(true);
});
it('ChatSDK.getCurrentLiveChatContext() with empty chatToken should return an empty chat session data', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
await chatSDK.initialize();
chatSDK.IC3Client = {
initialize: jest.fn(),
joinConversation: jest.fn()
}
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({
ChatId: '',
Token: '',
RegionGtms: '{}'
}));
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
const chatContext = await chatSDK.getCurrentLiveChatContext();
expect(Object.keys(chatContext).length).toBe(0);
expect(Object.keys(chatContext).includes('chatToken')).toBe(false);
expect(Object.keys(chatContext).includes('requestId')).toBe(false);
});
it('ChatSDK.getMessages should call conversation.getMessages()', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
chatSDK.OCClient = {
sessionInit: jest.fn()
}
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
getMessages: () => {}
}));
await chatSDK.startChat();
jest.spyOn(chatSDK.conversation, 'getMessages').mockResolvedValue(Promise.resolve());
await chatSDK.getMessages();
expect(chatSDK.conversation.getMessages).toHaveBeenCalledTimes(1);
});
it('ChatSDK.sendMessage() should mask characters if enabled', async () => {

@@ -337,2 +519,338 @@ const chatSDK = new OmnichannelChatSDK(omnichannelConfig);

it('ChatSDK.sendMessage() should send message with custom tags if set', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
chatSDK.OCClient = {
sessionInit: jest.fn()
}
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
sendMessage: (message: any) => {}
}));
await chatSDK.startChat();
jest.spyOn(chatSDK.conversation, 'sendMessage').mockResolvedValue(Promise.resolve());
const messageToSend = {
content: 'sample',
tags: ['system']
}
await chatSDK.sendMessage(messageToSend);
expect(chatSDK.conversation.sendMessage).toHaveBeenCalledTimes(1);
expect((chatSDK.conversation.sendMessage.mock.calls[0][0] as any).tags.length).not.toBe(0);
});
it('ChatSDK.sendMessage() should send message with custom timestamp if set', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
chatSDK.OCClient = {
sessionInit: jest.fn()
}
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
sendMessage: (message: any) => {}
}));
await chatSDK.startChat();
jest.spyOn(chatSDK.conversation, 'sendMessage').mockResolvedValue(Promise.resolve());
const messageToSend = {
content: 'sample',
timestamp: 'timestamp'
}
await chatSDK.sendMessage(messageToSend);
expect(chatSDK.conversation.sendMessage).toHaveBeenCalledTimes(1);
expect((chatSDK.conversation.sendMessage.mock.calls[0][0] as any).timestamp).toEqual(messageToSend.timestamp);
});
it('ChatSDK.sendTypingEvent() should call conversation.sendMessageToBot()', async() => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
chatSDK.OCClient = {
sessionInit: jest.fn()
}
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
indicateTypingStatus: (value: number) => {},
getMembers: () => {},
sendMessageToBot: (botId: string, message: any) => {}
}));
await chatSDK.startChat();
const members = [
{id: 'id', type: PersonType.Bot}
];
jest.spyOn(chatSDK.conversation, 'indicateTypingStatus').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.conversation, 'getMembers').mockResolvedValue(Promise.resolve(members));
jest.spyOn(chatSDK.conversation, 'sendMessageToBot').mockResolvedValue(Promise.resolve());
await chatSDK.sendTypingEvent();
expect(chatSDK.conversation.indicateTypingStatus).toHaveBeenCalledTimes(1);
expect(chatSDK.conversation.getMembers).toHaveBeenCalledTimes(1);
expect(chatSDK.conversation.sendMessageToBot).toHaveBeenCalledTimes(1);
});
it('ChatSDK.sendTypingEvent() should fail if conversation.sendMessageToBot() fails', async() => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
chatSDK.OCClient = {
sessionInit: jest.fn()
}
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
indicateTypingStatus: (value: number) => {},
getMembers: () => {},
sendMessageToBot: (botId: string, message: any) => {}
}));
await chatSDK.startChat();
const members = [
{id: 'id', type: PersonType.Bot}
];
jest.spyOn(chatSDK.conversation, 'indicateTypingStatus').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.conversation, 'getMembers').mockResolvedValue(Promise.resolve(members));
jest.spyOn(chatSDK.conversation, 'sendMessageToBot').mockRejectedValue(Promise.reject());
jest.spyOn(console, 'error');
try {
await chatSDK.sendTypingEvent();
} catch (error) {
expect(console.error).toHaveBeenCalled();
}
expect(chatSDK.conversation.indicateTypingStatus).toHaveBeenCalledTimes(1);
expect(chatSDK.conversation.getMembers).toHaveBeenCalledTimes(1);
expect(chatSDK.conversation.sendMessageToBot).toHaveBeenCalledTimes(1);
});
it('ChatSDK.uploadFileAttachment() should call conversation.sendFileData() & conversation.sendFileMessage()', async() => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
chatSDK.OCClient = {
sessionInit: jest.fn()
}
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
sendFileData: (fileInfo: IFileInfo, fileSharingProtocolType: FileSharingProtocolType) => {},
sendFileMessage: (fileMetaData: IFileMetadata, message: IMessage) => {}
}));
await chatSDK.startChat();
jest.spyOn(chatSDK.conversation, 'sendFileData').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.conversation, 'sendFileMessage').mockResolvedValue(Promise.resolve());
const fileInfo = {};
await chatSDK.uploadFileAttachment(fileInfo);
expect(chatSDK.conversation.sendFileData).toHaveBeenCalledTimes(1);
expect(chatSDK.conversation.sendFileMessage).toHaveBeenCalledTimes(1);
});
it('ChatSDK.downloadFileAttachment() should call conversation.downloadFile()', async() => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
chatSDK.OCClient = {
sessionInit: jest.fn()
}
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
downloadFile: () => {}
}));
await chatSDK.startChat();
jest.spyOn(chatSDK.conversation, 'downloadFile').mockResolvedValue(Promise.resolve());
const fileMetaData = {};
await chatSDK.downloadFileAttachment(fileMetaData);
expect(chatSDK.conversation.downloadFile).toHaveBeenCalledTimes(1);
});
it('ChatSDK.emailLiveChatTranscript() should call OCClient.emailTranscript()', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.OCClient, 'emailTranscript').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
sendMessage: (message: any) => {}
}));
await chatSDK.startChat();
const emailBody = {
emailAddress: 'sample@microsoft.com',
attachmentMessage: 'sample',
CustomerLocale: 'sample'
};
await chatSDK.emailLiveChatTranscript(emailBody);
expect(chatSDK.OCClient.emailTranscript).toHaveBeenCalledTimes(1);
});
it('ChatSDK.emailLiveChatTranscript() with authenticatedUserToken should pass it to OCClient.emailTranscript()', async () => {
const chatSDKConfig = {
getAuthToken: async () => {
return 'authenticatedUserToken'
}
};
const chatSDK = new OmnichannelChatSDK(omnichannelConfig, chatSDKConfig);
chatSDK.getChatConfig = jest.fn();
await chatSDK.initialize();
chatSDK.IC3Client.initialize = jest.fn();
chatSDK.IC3Client.joinConversation = jest.fn();
const optionaParams = {
authenticatedUserToken: 'authenticatedUserToken'
}
jest.spyOn(chatSDK.OCClient, 'getChatConfig').mockResolvedValue(Promise.resolve({
DataMaskingInfo: { setting: { msdyn_maskforcustomer: false } },
LiveWSAndLiveChatEngJoin: { PreChatSurvey: { msdyn_prechatenabled: false } },
LiveChatConfigAuthSettings: {}
}));
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({
ChatId: '',
Token: '',
RegionGtms: '{}'
}));
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.OCClient, 'emailTranscript').mockResolvedValue(Promise.resolve());
await chatSDK.startChat();
chatSDK.authenticatedUserToken = optionaParams.authenticatedUserToken;
const emailBody = {
emailAddress: 'sample@microsoft.com',
attachmentMessage: 'sample',
CustomerLocale: 'sample'
};
const emailTranscriptOptionalParams = {
authenticatedUserToken: optionaParams.authenticatedUserToken
}
await chatSDK.emailLiveChatTranscript(emailBody);
expect(chatSDK.OCClient.emailTranscript).toHaveBeenCalledTimes(1);
expect(chatSDK.OCClient.emailTranscript.mock.calls[0][3]).toMatchObject(emailTranscriptOptionalParams);
});
it('ChatSDK.getLiveChatTranscript() should call OCClient.getChatTranscripts()', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.OCClient, 'getChatTranscripts').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
sendMessage: (message: any) => {}
}));
await chatSDK.startChat();
await chatSDK.getLiveChatTranscript();
expect(chatSDK.OCClient.getChatTranscripts).toHaveBeenCalledTimes(1);
});
it('ChatSDK.getLiveChatTranscript() with authenticatedUserToken should pass it to OCClient.getChatTranscripts()', async () => {
const chatSDKConfig = {
getAuthToken: async () => {
return 'authenticatedUserToken'
}
};
const chatSDK = new OmnichannelChatSDK(omnichannelConfig, chatSDKConfig);
chatSDK.getChatConfig = jest.fn();
await chatSDK.initialize();
chatSDK.IC3Client.initialize = jest.fn();
chatSDK.IC3Client.joinConversation = jest.fn();
const optionaParams = {
authenticatedUserToken: 'authenticatedUserToken'
}
jest.spyOn(chatSDK.OCClient, 'getChatConfig').mockResolvedValue(Promise.resolve({
DataMaskingInfo: { setting: { msdyn_maskforcustomer: false } },
LiveWSAndLiveChatEngJoin: { PreChatSurvey: { msdyn_prechatenabled: false } },
LiveChatConfigAuthSettings: {}
}));
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({
ChatId: '',
Token: '',
RegionGtms: '{}'
}));
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.OCClient, 'getChatTranscripts').mockResolvedValue(Promise.resolve());
await chatSDK.startChat();
chatSDK.authenticatedUserToken = optionaParams.authenticatedUserToken;
await chatSDK.startChat();
const getChatTranscriptOptionalParams = {
authenticatedUserToken: optionaParams.authenticatedUserToken
}
await chatSDK.getLiveChatTranscript();
expect(chatSDK.OCClient.getChatTranscripts).toHaveBeenCalledTimes(1);
expect(chatSDK.OCClient.getChatTranscripts.mock.calls[0][3]).toMatchObject(getChatTranscriptOptionalParams);
});
it('ChatSDK.getIC3Client() should return IC3Core if platform is Node', async () => {

@@ -487,3 +1005,78 @@ const IC3SDKProvider = require('@microsoft/omnichannel-ic3core').SDKProvider;

});
it('ChatSDK.endChat() should fail if OCClient.sessionClose() fails', async () => {
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
chatSDK.getChatConfig = jest.fn();
chatSDK.getChatToken = jest.fn();
await chatSDK.initialize();
await chatSDK.startChat();
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'initialize').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.IC3Client, 'joinConversation').mockResolvedValue(Promise.resolve({
disconnect: () => {}
}));
jest.spyOn(chatSDK.OCClient, 'sessionClose').mockRejectedValue(Promise.reject());
try {
await chatSDK.endChat();
} catch (error) {
expect(console.error).toHaveBeenCalled();
}
expect(chatSDK.OCClient.sessionClose).toHaveBeenCalledTimes(1);
});
it('ChatSDK.endChat() with authenticatedUserToken should pass it to OCClient.sessionClose() call\'s optional parameters', async () => {
const chatSDKConfig = {
getAuthToken: async () => {
return 'authenticatedUserToken'
}
};
const chatSDK = new OmnichannelChatSDK(omnichannelConfig, chatSDKConfig);
chatSDK.getChatConfig = jest.fn();
await chatSDK.initialize();
chatSDK.IC3Client.initialize = jest.fn();
chatSDK.IC3Client.joinConversation = jest.fn();
const optionaParams = {
authenticatedUserToken: 'authenticatedUserToken'
}
jest.spyOn(chatSDK.OCClient, 'getChatConfig').mockResolvedValue(Promise.resolve({
DataMaskingInfo: { setting: { msdyn_maskforcustomer: false } },
LiveWSAndLiveChatEngJoin: { PreChatSurvey: { msdyn_prechatenabled: false } },
LiveChatConfigAuthSettings: {}
}));
jest.spyOn(chatSDK.OCClient, 'getChatToken').mockResolvedValue(Promise.resolve({
ChatId: '',
Token: '',
RegionGtms: '{}'
}));
jest.spyOn(chatSDK.OCClient, 'sessionInit').mockResolvedValue(Promise.resolve());
jest.spyOn(chatSDK.OCClient, 'sessionClose').mockResolvedValue(Promise.resolve());
await chatSDK.startChat();
chatSDK.authenticatedUserToken = optionaParams.authenticatedUserToken;
chatSDK.conversation = {
disconnect: jest.fn()
};
const sessionCloseOptionalParams = {
authenticatedUserToken: optionaParams.authenticatedUserToken
}
await chatSDK.endChat();
expect(chatSDK.OCClient.sessionClose).toHaveBeenCalledTimes(1);
expect(chatSDK.OCClient.sessionClose.mock.calls[0][1]).toMatchObject(sessionCloseOptionalParams);
});
});
})

54

lib/OmnichannelChatSDK.js

@@ -336,18 +336,27 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var typingPayload;
var _this = this;
var typingPayload, members, botMembers, error_6;
return __generator(this, function (_a) {
typingPayload = "{isTyping: 0}";
try {
this.conversation.indicateTypingStatus(0);
this.conversation.getMembers().then(function (members) {
var botMembers = members.filter(function (member) { return member.type === PersonType_1.default.Bot; });
_this.conversation.sendMessageToBot(botMembers[0].id, { payload: typingPayload });
});
switch (_a.label) {
case 0:
typingPayload = "{isTyping: 0}";
_a.label = 1;
case 1:
_a.trys.push([1, 5, , 6]);
return [4 /*yield*/, this.conversation.indicateTypingStatus(0)];
case 2:
_a.sent();
return [4 /*yield*/, this.conversation.getMembers()];
case 3:
members = _a.sent();
botMembers = members.filter(function (member) { return member.type === PersonType_1.default.Bot; });
return [4 /*yield*/, this.conversation.sendMessageToBot(botMembers[0].id, { payload: typingPayload })];
case 4:
_a.sent();
return [3 /*break*/, 6];
case 5:
error_6 = _a.sent();
console.error("OmnichannelChatSDK/sendTypingEvent/error");
return [2 /*return*/, error_6];
case 6: return [2 /*return*/];
}
catch (error) {
console.error("OmnichannelChatSDK/sendTypingEvent/error");
return [2 /*return*/, error];
}
return [2 /*return*/];
});

@@ -385,3 +394,3 @@ });

return __awaiter(this, void 0, void 0, function () {
var fileMetadata, messageToSend, error_6;
var fileMetadata, messageToSend, error_7;
return __generator(this, function (_a) {

@@ -414,5 +423,5 @@ switch (_a.label) {

case 4:
error_6 = _a.sent();
console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_6);
return [2 /*return*/, error_6];
error_7 = _a.sent();
console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_7);
return [2 /*return*/, error_7];
case 5: return [2 /*return*/];

@@ -494,2 +503,3 @@ }

};
/* istanbul ignore next */
OmnichannelChatSDK.prototype.setDebug = function (flag) {

@@ -549,3 +559,3 @@ this.debug = flag;

return __awaiter(this, void 0, void 0, function () {
var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, isPreChatEnabled, token, error_7;
var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, isPreChatEnabled, token, error_8;
return __generator(this, function (_a) {

@@ -594,5 +604,5 @@ switch (_a.label) {

case 5:
error_7 = _a.sent();
console.error("OmnichannelChatSDK/getChatConfig/error " + error_7);
return [2 /*return*/, error_7];
error_8 = _a.sent();
console.error("OmnichannelChatSDK/getChatConfig/error " + error_8);
return [2 /*return*/, error_8];
case 6: return [2 /*return*/];

@@ -599,0 +609,0 @@ }

{
"name": "@microsoft/omnichannel-chat-sdk",
"version": "0.1.0",
"version": "0.1.1-main.30dc1d1",
"description": "Microsoft Omnichannel Chat SDK",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -266,7 +266,6 @@ import {SDKProvider as OCSDKProvider, uuidv4 } from "@microsoft/ocsdk";

try {
this.conversation!.indicateTypingStatus(0);
this.conversation!.getMembers().then((members: any) => {
const botMembers = members.filter((member: any) => member.type === PersonType.Bot);
this.conversation!.sendMessageToBot(botMembers[0].id, {payload: typingPayload});
});
await this.conversation!.indicateTypingStatus(0);
const members: any = await this.conversation!.getMembers();
const botMembers = members.filter((member: any) => member.type === PersonType.Bot);
await this.conversation!.sendMessageToBot(botMembers[0].id, {payload: typingPayload});
} catch (error) {

@@ -391,2 +390,3 @@ console.error("OmnichannelChatSDK/sendTypingEvent/error");

/* istanbul ignore next */
public setDebug(flag: boolean) {

@@ -393,0 +393,0 @@ this.debug = flag;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc