scv-connector-base
Version:
Salesforce Service Cloud Connector Base
1,103 lines (1,012 loc) • 84.3 kB
JavaScript
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {
ActiveCallsResult,
AgentConfigResult,
SharedCapabilitiesResult,
VoiceCapabilitiesResult,
RecordingToggleResult,
ParticipantResult,
LogoutResult,
ContactsResult,
PhoneContactsResult,
CallResult,
HoldToggleResult,
InitResult,
GenericResult,
MuteToggleResult,
SignedRecordingUrlResult,
Contact,
PhoneCall,
PhoneCallAttributes,
CallInfo,
VendorConnector,
TelephonyConnector,
Phone,
AgentStatusInfo,
HangupResult,
AgentConfig,
StatsInfo,
AudioStats,
AudioStatsElement,
Constants,
SupervisorHangupResult,
SupervisedCallInfo,
AgentVendorStatusInfo,
StateChangeResult,
CustomError,
AgentWork,
ShowStorageAccessResult,
ContactsFilter,
AudioDevicesResult,
ACWInfo,
SetAgentConfigResult,
SetAgentStateResult,
HidDevice
} from '../main/index';
import { downloadLogs } from '../main/logger';
jest.mock('../main/logger');
describe('Types validation tests', () => {
const invalid_argument = /^Invalid argument/;
const dummyPhoneCall = new PhoneCall({ callId: 'callId', callType: Constants.CALL_TYPE.INBOUND, callSubtype: Constants.CALL_SUBTYPE.PSTN, state: 'state', callAttributes: {}, phoneNumber: '100'});
const dummyCallInfo = new CallInfo({ isOnHold: false, showMuteButton: true, showAddBlindTransferButton: true, showRecordButton: true, showAddCallerButton: true, showMergeButton: true, showSwapButton: true, additionalFields: "\"SourceType\": \"Service\"" });
describe('CustomError tests', () => {
const dummyLabelName = 'dummyLabelName';
const dummyNamespace = 'dummyNamespace';
const dummyMessage = 'dummyMessage';
it('Should create CustomError object - default', () => {
let customError;
expect(() => {
customError = new CustomError({ labelName: dummyLabelName, namespace: dummyNamespace });
}).not.toThrowError();
expect(customError.labelName).toEqual(dummyLabelName);
expect(customError.namespace).toEqual(dummyNamespace);
});
it('Should create CustomError object with message', () => {
let customError;
expect(() => {
customError = new CustomError({ labelName: dummyLabelName, namespace: dummyNamespace, message: dummyMessage });
}).not.toThrowError();
expect(customError.labelName).toEqual(dummyLabelName);
expect(customError.namespace).toEqual(dummyNamespace);
expect(customError.message).toEqual(dummyMessage);
});
});
describe('ActiveCallsResult tests', () => {
it('Should create ActiveCallsResult object - default', () => {
let activeCallsResult;
expect(() => {
activeCallsResult = new ActiveCallsResult({});
}).not.toThrowError();
expect(activeCallsResult.activeCalls).toEqual([]);
});
it('Should create ActiveCallsResult object', () => {
const activeCalls = [ dummyPhoneCall ];
let activeCallsResult;
expect(() => {
activeCallsResult = new ActiveCallsResult({ activeCalls });
}).not.toThrowError();
expect(activeCallsResult.activeCalls).toEqual(activeCalls);
});
});
describe('AudioDevicesResult tests', () => {
it('Should create AudioDevicesResult object - default', () => {
let audioDevicesResult;
expect(() => {
audioDevicesResult = new AudioDevicesResult({});
}).not.toThrowError();
expect(audioDevicesResult.audioDevices).toBeInstanceOf(Array);
});
it('Should create AudioDevicesResult object', () => {
const audioDevices = [{
"deviceId": "default",
"kind": "audioinput",
"label": "Default - MyHeadphones (Bluetooth)",
"groupId": "080523bb442ecd8c19e9e70dc0fc0f9c9d808f4cb071c65cf81e8e790117aa28"
}, {
"deviceId": "437c20a0dg2d20b44c2af5e619d8f0eb85e0fa1a877e0e45665bca3da42a9673",
"kind": "audioinput",
"label": "MacBook Pro Microphone (Built-in)",
"groupId": "16131a5ab07c4234be110a0b7dede980a1ef7239255785bbb91f99acdb82ee80"
}];
let audioDevicesResult;
expect(() => {
audioDevicesResult = new AudioDevicesResult({ audioDevices });
}).not.toThrowError();
expect(audioDevicesResult.audioDevices).toEqual(audioDevices);
});
});
describe('AgentConfigResult tests', () => {
it('Should create AgentConfigResult object - default', () => {
let agentConfigResult;
expect(() => {
agentConfigResult = new AgentConfigResult({});
}).not.toThrowError();
expect(agentConfigResult.phones).toEqual([Constants.PHONE_TYPE.SOFT_PHONE]);
expect(agentConfigResult.selectedPhone).toEqual(new Phone({type: Constants.PHONE_TYPE.SOFT_PHONE}));
expect(agentConfigResult.speakerDeviceId).toEqual('');
expect(agentConfigResult.microphoneDeviceId).toEqual('');
});
it('Should create AgentConfigResult object', () => {
let agentConfigResult;
const phones = ["DESK_PHONE", "SOFT_PHONE"];
const selectedPhone = new Phone({type: "SOFT_PHONE"});
const speakerDeviceId = 'testSpeakerDeviceId';
const microphoneDeviceId = 'testMicrophoneDeviceId';
expect(() => {
agentConfigResult = new AgentConfigResult({
phones,
selectedPhone,
speakerDeviceId,
microphoneDeviceId
});
}).not.toThrowError();
expect(agentConfigResult.phones).toEqual(phones);
expect(agentConfigResult.selectedPhone).toEqual(selectedPhone);
expect(agentConfigResult.speakerDeviceId).toEqual(speakerDeviceId);
expect(agentConfigResult.microphoneDeviceId).toEqual(microphoneDeviceId);
});
});
describe('AgentConfig tests', () => {
it('Should create AgentConfig object - default', () => {
let agentConfig;
const selectedPhone = new Phone({ type: Constants.PHONE_TYPE.SOFT_PHONE });
expect(() => {
agentConfig = new AgentConfig({ selectedPhone: selectedPhone });
}).not.toThrowError();
expect(agentConfig.selectedPhone).toEqual(selectedPhone);
expect(agentConfig.hidDeviceInfo).toEqual(undefined);
});
it('Should create AgentConfig object', () => {
let agentConfig;
const selectedPhone = new Phone({ type: Constants.PHONE_TYPE.SOFT_PHONE });
const hidDeviceInfo = new HidDevice({productId: 1234, vendorId: 567});
expect(() => {
agentConfig = new AgentConfig({ selectedPhone: selectedPhone, hidDeviceInfo: hidDeviceInfo });
}).not.toThrowError();
expect(agentConfig.selectedPhone).toEqual(selectedPhone);
expect(agentConfig.hidDeviceInfo).toEqual(hidDeviceInfo);
});
});
describe('SetAgentConfigResult tests', () => {
it('Should create SetAgentConfigResult object', () => {
const success = false;
let setAgentConfigResult;
expect(() => {
setAgentConfigResult = new SetAgentConfigResult({ success });
}).not.toThrowError();
expect(setAgentConfigResult.success).toEqual(success);
expect(setAgentConfigResult.isSystemEvent).toEqual(false);
});
it('Should create SetAgentConfigResult object with isSystemEvent true', () => {
const success = true;
const isSystemEvent = true;
let setAgentConfigResult;
expect(() => {
setAgentConfigResult = new SetAgentConfigResult({ success, isSystemEvent });
}).not.toThrowError();
expect(setAgentConfigResult.success).toEqual(success);
expect(setAgentConfigResult.isSystemEvent).toEqual(isSystemEvent);
});
});
describe('SetAgentStateResult tests', () => {
it('Should create SetAgentStateResult object', () => {
const success = false;
let setAgentStateResult;
expect(() => {
setAgentStateResult = new SetAgentStateResult({ success });
}).not.toThrowError();
expect(setAgentStateResult.success).toEqual(success);
expect(setAgentStateResult.isStatusSyncNeeded).toEqual(true);
});
it('Should create SetAgentStateResult object with isStatusSyncNeeded false', () => {
const success = true;
const isStatusSyncNeeded = false;
let setAgentStateResult;
expect(() => {
setAgentStateResult = new SetAgentStateResult({ success, isStatusSyncNeeded });
}).not.toThrowError();
expect(setAgentStateResult.success).toEqual(success);
expect(setAgentStateResult.isStatusSyncNeeded).toEqual(isStatusSyncNeeded);
});
});
describe('CapabilitiesResult tests', () => {
it('Should create SharedCapabilitiesResult object - default', () => {
let capabilitiesResult;
expect(() => {
capabilitiesResult = new SharedCapabilitiesResult({});
}).not.toThrowError();
expect(capabilitiesResult.debugEnabled).toEqual(true);
expect(capabilitiesResult.hasContactSearch).toEqual(false);
expect(capabilitiesResult.hasAgentAvailability).toEqual(false);
expect(capabilitiesResult.hasQueueWaitTime).toEqual(false);
expect(capabilitiesResult.hasTransferToOmniFlow).toEqual(false);
expect(capabilitiesResult.hasPendingStatusChange).toEqual(false);
expect(capabilitiesResult.hasSFDCPendingState).toEqual(false);
expect(capabilitiesResult.hasAutoAcceptEnabled).toEqual(false);
});
it('Should create VoiceCapabilitiesResult object - default', () => {
let capabilitiesResult;
expect(() => {
capabilitiesResult = new VoiceCapabilitiesResult({});
}).not.toThrowError();
expect(capabilitiesResult.hasMute).toEqual(true);
expect(capabilitiesResult.hasRecord).toEqual(true);
expect(capabilitiesResult.hasMerge).toEqual(true);
expect(capabilitiesResult.hasSwap).toEqual(true);
expect(capabilitiesResult.hasBlindTransfer).toEqual(false);
expect(capabilitiesResult.hasSignedRecordingUrl).toEqual(false);
expect(capabilitiesResult.supportsMos).toEqual(false);
expect(capabilitiesResult.hasSupervisorListenIn).toEqual(false);
expect(capabilitiesResult.hasSupervisorBargeIn).toEqual(false);
expect(capabilitiesResult.hasPhoneBook).toEqual(false);
expect(capabilitiesResult.hasGetExternalSpeakerDeviceSetting).toEqual(false);
expect(capabilitiesResult.hasSetExternalSpeakerDeviceSetting).toEqual(false);
expect(capabilitiesResult.hasGetExternalMicrophoneDeviceSetting).toEqual(false);
expect(capabilitiesResult.hasSetExternalMicrophoneDeviceSetting).toEqual(false);
expect(capabilitiesResult.canConsult).toEqual(false);
expect(capabilitiesResult.isDialPadDisabled).toEqual(false);
expect(capabilitiesResult.isHidSupported).toEqual(false);
});
it('Should create SharedCapabilitiesResult object', () => {
let capabilitiesResult;
const debugEnabled = false;
const hasContactSearch = true;
const hasAgentAvailability = false;
const hasQueueWaitTime = false;
const hasTransferToOmniFlow = true;
const hasPendingStatusChange = true;
const hasSFDCPendingState = true;
const hasAutoAcceptEnabled = true;
expect(() => {
capabilitiesResult = new SharedCapabilitiesResult({
debugEnabled,
hasContactSearch,
hasAgentAvailability,
hasQueueWaitTime,
hasTransferToOmniFlow,
hasPendingStatusChange,
hasSFDCPendingState,
hasAutoAcceptEnabled
});
}).not.toThrowError();
expect(capabilitiesResult.debugEnabled).toEqual(debugEnabled);
expect(capabilitiesResult.hasContactSearch).toEqual(hasContactSearch);
expect(capabilitiesResult.hasAgentAvailability).toEqual(hasAgentAvailability);
expect(capabilitiesResult.hasQueueWaitTime).toEqual(hasQueueWaitTime);
expect(capabilitiesResult.hasTransferToOmniFlow).toEqual(hasTransferToOmniFlow);
expect(capabilitiesResult.hasPendingStatusChange).toEqual(hasPendingStatusChange);
expect(capabilitiesResult.hasSFDCPendingState).toEqual(hasSFDCPendingState);
expect(capabilitiesResult.hasAutoAcceptEnabled).toEqual(hasAutoAcceptEnabled);
});
it('Should create VoiceCapabilitiesResult object', () => {
let capabilitiesResult;
const hasMute = false;
const hasRecord = false;
const hasMerge = false;
const hasSwap = false;
const hasBlindTransfer = true;
const hasSignedRecordingUrl = true;
const supportsMos = true;
const hasSupervisorListenIn = true;
const hasSupervisorBargeIn = true;
const hasPhoneBook = true;
const hasGetExternalSpeakerDeviceSetting = true;
const hasSetExternalSpeakerDeviceSetting = true;
const hasGetExternalMicrophoneDeviceSetting = true;
const hasSetExternalMicrophoneDeviceSetting = true;
const canConsult = true;
const isDialPadDisabled = true;
const isHidSupported = true;
expect(() => {
capabilitiesResult = new VoiceCapabilitiesResult({
hasMute,
hasRecord,
hasMerge,
hasSwap,
hasBlindTransfer,
hasSignedRecordingUrl,
supportsMos,
hasSupervisorListenIn,
hasSupervisorBargeIn,
hasPhoneBook,
hasGetExternalSpeakerDeviceSetting,
hasSetExternalSpeakerDeviceSetting,
hasGetExternalMicrophoneDeviceSetting,
hasSetExternalMicrophoneDeviceSetting,
canConsult,
isDialPadDisabled,
isHidSupported
});
}).not.toThrowError();
expect(capabilitiesResult.hasMute).toEqual(hasMute);
expect(capabilitiesResult.hasRecord).toEqual(hasRecord);
expect(capabilitiesResult.hasMerge).toEqual(hasMerge);
expect(capabilitiesResult.hasSwap).toEqual(hasSwap);
expect(capabilitiesResult.hasBlindTransfer).toEqual(hasBlindTransfer);
expect(capabilitiesResult.hasSignedRecordingUrl).toEqual(hasSignedRecordingUrl);
expect(capabilitiesResult.supportsMos).toEqual(supportsMos);
expect(capabilitiesResult.hasSupervisorListenIn).toEqual(hasSupervisorListenIn);
expect(capabilitiesResult.hasSupervisorBargeIn).toEqual(hasSupervisorBargeIn);
expect(capabilitiesResult.hasPhoneBook).toEqual(hasPhoneBook);
expect(capabilitiesResult.hasGetExternalSpeakerDeviceSetting).toEqual(hasGetExternalSpeakerDeviceSetting);
expect(capabilitiesResult.hasSetExternalSpeakerDeviceSetting).toEqual(hasSetExternalSpeakerDeviceSetting);
expect(capabilitiesResult.hasGetExternalMicrophoneDeviceSetting).toEqual(hasGetExternalMicrophoneDeviceSetting);
expect(capabilitiesResult.hasSetExternalMicrophoneDeviceSetting).toEqual(hasSetExternalMicrophoneDeviceSetting);
expect(capabilitiesResult.canConsult).toEqual(canConsult);
expect(capabilitiesResult.isDialPadDisabled).toEqual(isDialPadDisabled);
expect(capabilitiesResult.isHidSupported).toEqual(isHidSupported);
});
});
describe('RecordingToggleResult tests', () => {
it('Should create RecordingToggleResult object - default', () => {
const isRecordingPaused = true;
let recordingToggleResult;
expect(() => {
recordingToggleResult = new RecordingToggleResult({ isRecordingPaused });
}).not.toThrowError();
expect(recordingToggleResult.isRecordingPaused).toEqual(isRecordingPaused);
expect(recordingToggleResult.contactId).toEqual(null);
expect(recordingToggleResult.initialContactId).toEqual(null);
expect(recordingToggleResult.instanceId).toEqual(null);
expect(recordingToggleResult.region).toEqual(null);
});
it('Should create RecordingToggleResult object', () => {
const isRecordingPaused = true;
const contactId = 'contactId';
const initialContactId = 'initialContactId';
const instanceId = 'instanceId';
const region = 'region';
let recordingToggleResult;
expect(() => {
recordingToggleResult = new RecordingToggleResult({ isRecordingPaused,
contactId,
initialContactId,
instanceId,
region
});
}).not.toThrowError();
expect(recordingToggleResult.isRecordingPaused).toEqual(isRecordingPaused);
expect(recordingToggleResult.contactId).toEqual(contactId);
expect(recordingToggleResult.initialContactId).toEqual(initialContactId);
expect(recordingToggleResult.instanceId).toEqual(instanceId);
expect(recordingToggleResult.region).toEqual(region);
});
});
describe('SignedRecordingUrlResult', () => {
it('Should create SignedRecordingUrlResult object - default', () => {
const success = false;
let signedRecordingUrlResult;
expect(() => {
signedRecordingUrlResult = new SignedRecordingUrlResult({ success });
}).not.toThrowError();
expect(signedRecordingUrlResult.success).toEqual(success);
expect(signedRecordingUrlResult.url).toBeUndefined();
expect(signedRecordingUrlResult.duration).toBeUndefined();
expect(signedRecordingUrlResult.callId).toBeUndefined();
expect(signedRecordingUrlResult.connectionId).toBeUndefined();
});
it('Should create SignedRecordingUrlResult object', () => {
const success = true;
const url = 'url';
const duration = 10;
const callId = 'callId';
let signedRecordingUrlResult;
expect(() => {
signedRecordingUrlResult = new SignedRecordingUrlResult({ success, url, duration, callId });
}).not.toThrowError();
expect(signedRecordingUrlResult.success).toEqual(success);
expect(signedRecordingUrlResult.url).toEqual(url);
expect(signedRecordingUrlResult.callId).toEqual(callId);
expect(signedRecordingUrlResult.duration).toEqual(duration);
});
it('Should create SignedRecordingUrlResult object without duration', () => {
const success = true;
const url = 'url';
const callId = 'callId';
let signedRecordingUrlResult;
expect(() => {
signedRecordingUrlResult = new SignedRecordingUrlResult({ success, url, callId });
}).not.toThrowError();
expect(signedRecordingUrlResult.success).toEqual(success);
expect(signedRecordingUrlResult.url).toEqual(url);
expect(signedRecordingUrlResult.callId).toEqual(callId);
expect(signedRecordingUrlResult.duration).toEqual(undefined);
});
it('Should create NOT SignedRecordingUrlResult object for non string url', () => {
const success = true;
const url = 100;
const callId = 'callId';
const duration = 10;
expect(() => {
new SignedRecordingUrlResult({ success, url, duration, callId });
}).toThrowError();
});
it('Should create NOT SignedRecordingUrlResult object for non string callId', () => {
const success = true;
const url = 'url';
const duration = 10;
const callId = {};
expect(() => {
new SignedRecordingUrlResult({ success, url, duration, callId });
}).toThrowError();
});
it('Should create NOT SignedRecordingUrlResult object for non number duration', () => {
const success = true;
const url = 'url';
const callId = 'callId';
const duration = 'duration';
expect(() => {
new SignedRecordingUrlResult({ success, url, duration, callId });
}).toThrowError();
});
});
describe('ParticipantResult tests', () => {
it('Should create ParticipantResult object', () => {
const dummyPhoneNumber = 'phoneNumber';
const callId = 'callid';
const callAttributes = { isConsultCall: false };
let participantResult;
expect(() => {
participantResult = new ParticipantResult({ initialCallHasEnded: true,
callAttributes,
callInfo: dummyCallInfo,
phoneNumber: dummyPhoneNumber,
callId });
}).not.toThrowError();
expect(participantResult.initialCallHasEnded).toEqual(true);
expect(participantResult.callInfo).toEqual(dummyCallInfo);
expect(participantResult.callAttributes).toEqual(callAttributes);
expect(participantResult.phoneNumber).toEqual(dummyPhoneNumber);
expect(participantResult.callId).toEqual(callId);
expect(participantResult.connectionId).toEqual(callId);
});
it('Should create ParticipantResult object with connectionId', () => {
const dummyPhoneNumber = 'phoneNumber';
const callId = 'callid';
const connectionId = 'connectionId';
const callAttributes = { isConsultCall: false };
let participantResult;
expect(() => {
participantResult = new ParticipantResult({
initialCallHasEnded: true,
callAttributes,
callInfo: dummyCallInfo,
phoneNumber: dummyPhoneNumber,
callId,
connectionId
});
}).not.toThrowError();
expect(participantResult.initialCallHasEnded).toEqual(true);
expect(participantResult.callInfo).toEqual(dummyCallInfo);
expect(participantResult.callAttributes).toEqual(callAttributes);
expect(participantResult.phoneNumber).toEqual(dummyPhoneNumber);
expect(participantResult.callId).toEqual(callId);
expect(participantResult.connectionId).toEqual(connectionId);
});
});
describe('PhoneContactsResult tests', () => {
it('Should create PhoneContactsResult object - default', () => {
let phoneContactsResult;
expect(() => {
phoneContactsResult = new PhoneContactsResult({ });
}).not.toThrowError();
expect(phoneContactsResult.contacts).toEqual([]);
expect(phoneContactsResult.contactTypes).toEqual([]);
});
it('Should create PhoneContactsResult object', () => {
const contacts = [
new Contact({})
];
const contactTypes = [];
let phoneContactsResult;
expect(() => {
phoneContactsResult = new PhoneContactsResult({ contacts, contactTypes });
}).not.toThrowError();
expect(phoneContactsResult.contacts).toEqual(contacts);
expect(phoneContactsResult.contactTypes).toEqual(contactTypes);
});
});
describe('ContactsResult tests', () => {
it('Should create ContactsResult object - default', () => {
let contactsResult;
expect(() => {
contactsResult = new ContactsResult({ });
}).not.toThrowError();
expect(contactsResult.contacts).toEqual([]);
expect(contactsResult.contactTypes).toEqual([]);
});
it('Should create ContactsResult object', () => {
const contacts = [
new Contact({})
];
const contactTypes = [];
let contactsResult;
expect(() => {
contactsResult = new ContactsResult({ contacts, contactTypes });
}).not.toThrowError();
expect(contactsResult.contacts).toEqual(contacts);
expect(contactsResult.contactTypes).toEqual(contactTypes);
});
});
describe('CallResult tests', () => {
it('Should create CallResult object', () => {
const call = dummyPhoneCall;
let callResult;
expect(() => {
callResult = new CallResult({ call });
}).not.toThrowError();
expect(callResult.call).toEqual(call);
});
it('Should create CallResult object from empty call', () => {
let callResult;
expect(() => {
callResult = new CallResult({});
}).not.toThrowError();
expect(callResult.call).toEqual(undefined);
});
it('Should create CallResult object with hangup values', () => {
const reason = 'reason';
const closeCallOnError = true;
const callType = Constants.CALL_TYPE.OUTBOUND;
const callSubtype = Constants.CALL_SUBTYPE.PSTN;
const callId = 'callid';
const agentStatus = 'agentStatus';
const agentARN = 'agentARN';
let callHangupResult;
expect(() => {
callHangupResult = new CallResult({ call: new PhoneCall({ reason, closeCallOnError, callType, callSubtype, callId, agentStatus, agentARN })});
}).not.toThrowError();
expect(callHangupResult.call.reason).toEqual(reason);
expect(callHangupResult.call.closeCallOnError).toEqual(closeCallOnError);
expect(callHangupResult.call.callType).toEqual(callType);
expect(callHangupResult.call.callSubtype).toEqual(callSubtype);
expect(callHangupResult.call.callId).toEqual(callId);
expect(callHangupResult.call.agentStatus).toEqual(agentStatus);
expect(callHangupResult.call.agentARN).toEqual(agentARN);
});
});
describe('HangupResults tests', () => {
it('Should create HangupResult object', () => {
const call = dummyPhoneCall;
let hangupResult;
expect(() => {
hangupResult = new HangupResult({ calls: [call] });
}).not.toThrowError();
expect(hangupResult.calls).toEqual([call]);
});
it('Should create HangupResult for multiple calls', () => {
const call = dummyPhoneCall;
const call2 = dummyPhoneCall;
let hangupResult;
expect(() => {
hangupResult = new HangupResult({ calls: [call, call2] });
}).not.toThrowError();
expect(hangupResult.calls).toEqual([call, call2]);
});
it('Should create HangupResult object from call', () => {
const call = dummyPhoneCall;
let hangupResult;
expect(() => {
hangupResult = new HangupResult({ calls: call });
}).not.toThrowError();
expect(hangupResult.calls).toEqual([call]);
});
it('Should create HangupResult object with hangup values', () => {
const reason = 'reason';
const closeCallOnError = true;
const callType = Constants.CALL_TYPE.OUTBOUND;
const callSubtype = Constants.CALL_SUBTYPE.PSTN;
const callId = 'callid';
const agentStatus = 'agentStatus';
const agentARN = 'agentARN';
let callHangupResult;
expect(() => {
callHangupResult = new HangupResult({ calls: [new PhoneCall({ reason, closeCallOnError, callType, callSubtype, callId, agentStatus, agentARN })]});
}).not.toThrowError();
const hangupResultCall = callHangupResult.calls.pop()
expect(hangupResultCall.reason).toEqual(reason);
expect(hangupResultCall.closeCallOnError).toEqual(closeCallOnError);
expect(hangupResultCall.callType).toEqual(callType);
expect(hangupResultCall.callSubtype).toEqual(callSubtype);
expect(hangupResultCall.callId).toEqual(callId);
expect(hangupResultCall.agentStatus).toEqual(agentStatus);
expect(hangupResultCall.agentARN).toEqual(agentARN);
});
});
describe('HoldToggleResult tests', () => {
it('Should create HoldToggleResult object', () => {
const calls = { callId: dummyPhoneCall };
const isThirdPartyOnHold = false;
const isCustomerOnHold = true;
let holdToggleResult;
expect(() => {
holdToggleResult = new HoldToggleResult({ isThirdPartyOnHold, isCustomerOnHold, calls });
}).not.toThrowError();
expect(holdToggleResult.isThirdPartyOnHold).toEqual(isThirdPartyOnHold);
expect(holdToggleResult.isCustomerOnHold).toEqual(isCustomerOnHold);
expect(holdToggleResult.calls).toEqual(calls);
});
it('Should create HoldToggleResult object without calls', () => {
const isThirdPartyOnHold = false;
const isCustomerOnHold = true;
let holdToggleResult;
expect(() => {
holdToggleResult = new HoldToggleResult({ isThirdPartyOnHold, isCustomerOnHold });
}).not.toThrowError();
expect(holdToggleResult.isThirdPartyOnHold).toEqual(isThirdPartyOnHold);
expect(holdToggleResult.isCustomerOnHold).toEqual(isCustomerOnHold);
expect(holdToggleResult.calls).toEqual(undefined);
});
});
describe('MuteToggleResult tests', () => {
it('Should create MuteToggleResult object', () => {
let muteToggleResult;
const isMuted = false;
expect(() => {
muteToggleResult = new MuteToggleResult({ isMuted });
}).not.toThrowError();
expect(muteToggleResult.isMuted).toEqual(isMuted);
});
});
describe('InitResult tests', () => {
it('Should create InitResult object - default', () => {
let initResult;
expect(() => {
initResult = new InitResult({});
}).not.toThrowError();
expect(initResult.showLogin).toEqual(false);
expect(initResult.loginFrameHeight).toEqual(350);
});
it('Should create InitResult object - isSilentLogin true ', () => {
const showLogin = false;
const loginFrameHeight = 450;
const isSilentLogin = true;
let initResult;
expect(() => {
initResult = new InitResult({ showLogin, loginFrameHeight, isSilentLogin });
}).not.toThrowError();
expect(initResult.showLogin).toEqual(showLogin);
expect(initResult.loginFrameHeight).toEqual(loginFrameHeight);
expect(initResult.isSilentLogin).toEqual(true);
});
it('Should create InitResult object - showLogin true & isSilentLogin false ', () => {
const showLogin = true;
const loginFrameHeight = 450;
const isSilentLogin = true;
let initResult;
expect(() => {
initResult = new InitResult({ showLogin, loginFrameHeight, isSilentLogin });
}).not.toThrowError();
expect(initResult.showLogin).toEqual(showLogin);
expect(initResult.loginFrameHeight).toEqual(loginFrameHeight);
expect(initResult.isSilentLogin).toEqual(false);
});
it('Should create InitResult object - showStorageAccess true ', () => {
const showLogin = false;
const loginFrameHeight = 450;
const isSilentLogin = false;
const showStorageAccess = true;
let initResult;
expect(() => {
initResult = new InitResult({ showLogin, loginFrameHeight, isSilentLogin, showStorageAccess });
}).not.toThrowError();
expect(initResult.showLogin).toEqual(showLogin);
expect(initResult.loginFrameHeight).toEqual(loginFrameHeight);
expect(initResult.isSilentLogin).toEqual(false);
expect(initResult.showStorageAccess).toEqual(true);
});
});
describe('LogoutResult tests', () => {
it('Should create LogoutResult object - default', () => {
let logoutResult;
expect(() => {
logoutResult = new LogoutResult({ success: true });
}).not.toThrowError();
expect(logoutResult.success).toEqual(true);
expect(logoutResult.loginFrameHeight).toEqual(350);
});
it('Should create LogoutResult object', () => {
const success = false;
const loginFrameHeight = 450;
let logoutResult;
expect(() => {
logoutResult = new LogoutResult({ success, loginFrameHeight });
}).not.toThrowError();
expect(logoutResult.success).toEqual(success);
expect(logoutResult.loginFrameHeight).toEqual(loginFrameHeight);
});
});
describe('GenericResult tests', () => {
it('Should create GenericResult object', () => {
const success = false;
let genericResult;
expect(() => {
genericResult = new GenericResult({ success });
}).not.toThrowError();
expect(genericResult.success).toEqual(success);
});
});
describe('AgentWork tests', () => {
const workItemId = 'dummyWorkItemId';
const workId = 'dummyWorkId';
it('Should create AgentWork object with valid work lifecycle event', () => {
let agentWork;
expect(() => {
agentWork = new AgentWork({ workItemId, workId, workEvent: Constants.WORK_EVENT.ACCEPTED})
}).not.toThrowError();
expect(agentWork).not.toBeNull();
});
});
describe('CallInfo tests', () => {
it('Should create CallInfo object - default', () => {
const isOnHold = false;
const initialCallId = 'initialCallId';
const isExternalTransfer = false;
const showMuteButton = true;
const showAddCallerButton = true;
const showRecordButton = true;
const showAddBlindTransferButton = true;
const showMergeButton = true;
const showSwapButton = true;
const isMultiParty = true;
const isHIDCall = true;
const endCallDisabled = false;
const renderContactId = 'renderContactId';
let callInfo;
expect(() => {
callInfo = new CallInfo({ isOnHold, initialCallId, isExternalTransfer, showMuteButton, showAddCallerButton, showRecordButton, showAddBlindTransferButton, showMergeButton, showSwapButton, isMultiParty, isHIDCall, endCallDisabled, renderContactId });
}).not.toThrowError();
expect(callInfo.callStateTimestamp).toBeNull();
expect(callInfo.isOnHold).toEqual(isOnHold);
expect(callInfo.initialCallId).toEqual(initialCallId);
expect(callInfo.isMuted).toEqual(false);
expect(callInfo.isExternalTransfer).toEqual(isExternalTransfer);
expect(callInfo.isRecordingPaused).toEqual(false);
expect(callInfo.showAddBlindTransferButton).toEqual(true);
expect(callInfo.showMuteButton).toEqual(true);
expect(callInfo.showRecordButton).toEqual(true);
expect(callInfo.showAddCallerButton).toEqual(true);
expect(callInfo.showMergeButton).toEqual(true);
expect(callInfo.queueName).toEqual(null);
expect(callInfo.queueId).toEqual(null);
expect(callInfo.queueTimestamp).toEqual(null);
expect(callInfo.isMultiParty).toEqual(true);
expect(callInfo.isHIDCall).toEqual(true);
expect(callInfo.endCallDisabled).toEqual(false);
expect(callInfo.renderContactId).toEqual(renderContactId);
});
it('Should create CallInfo object', () => {
const callStateTimestamp = new Date();
const queueName = "queueName";
const queueId = "queueId";
const queueTimestamp = new Date();
const isOnHold = false;
let callInfo;
expect(() => {
callInfo = new CallInfo({ callStateTimestamp, isOnHold, queueName, queueId, queueTimestamp });
}).not.toThrowError();
expect(callInfo.callStateTimestamp).toEqual(callStateTimestamp);
expect(callInfo.isOnHold).toEqual(isOnHold);
expect(callInfo.queueName).toEqual(queueName);
expect(callInfo.queueId).toEqual(queueId);
expect(callInfo.queueTimestamp).toEqual(queueTimestamp);
});
it('Should throw on invalid callStateTimestamp', () => {
const callStateTimestamp = 'Invalid date';
const isOnHold = false;
expect(() => {
new CallInfo({ callStateTimestamp, isOnHold });
}).toThrowError();
});
});
describe('Contact tests', () => {
const phoneNumber = '1231231234';
const type = Constants.CONTACT_TYPE.AGENT;
const id = 'id';
const name = 'name';
const listType = Constants.CONTACT_LIST_TYPE.ALL;
const prefix = '+1';
const extension = '123';
const endpointARN = 'endpointARN';
const queue = 'queue';
const availability = "BUSY";
const queueWaitTime = "15";
const recordId = "00DXXX";
const description = "description";
describe('Contact success tests', () => {
it('Should create a Contact object without error', () => {
let contact;
expect(() => {
contact = new Contact({phoneNumber, id, type, name, listType, prefix, extension, endpointARN, queue, availability, queueWaitTime, recordId, description});
}).not.toThrowError();
expect(contact.phoneNumber).toEqual(phoneNumber);
expect(contact.type).toEqual(type);
expect(contact.id).toEqual(id);
expect(contact.name).toEqual(name);
expect(contact.listType).toEqual(listType);
expect(contact.prefix).toEqual(prefix);
expect(contact.extension).toEqual(extension);
expect(contact.endpointARN).toEqual(endpointARN);
expect(contact.queue).toEqual(queue);
expect(contact.availability).toEqual(availability);
expect(contact.queueWaitTime).toEqual(queueWaitTime);
expect(contact.recordId).toEqual(recordId);
expect(contact.description).toEqual(description);
});
it('Should create a Contact object without phoneNumber', () => {
let contact;
expect(() => {
contact = new Contact({id, type, name, prefix, extension});
}).not.toThrowError();
expect(contact.phoneNumber).toBeUndefined();
expect(contact.type).toEqual(type);
expect(contact.id).toEqual(id);
expect(contact.name).toEqual(name);
expect(contact.prefix).toEqual(prefix);
expect(contact.extension).toEqual(extension);
});
it('Should create a Contact object without type', () => {
let contact;
expect(() => {
contact = new Contact({phoneNumber, id, name, prefix, extension});
}).not.toThrowError();
expect(contact.phoneNumber).toEqual(phoneNumber);
expect(contact.type).toBeUndefined();
expect(contact.id).toEqual(id);
expect(contact.name).toEqual(name);
expect(contact.prefix).toEqual(prefix);
expect(contact.extension).toEqual(extension);
});
it('Should create a Contact object without id', () => {
let contact;
expect(() => {
contact = new Contact({phoneNumber, type, name, prefix, extension});
}).not.toThrowError();
expect(contact.phoneNumber).toEqual(phoneNumber);
expect(contact.type).toEqual(type);
expect(contact.id).toBeUndefined();
expect(contact.name).toEqual(name);
expect(contact.prefix).toEqual(prefix);
expect(contact.extension).toEqual(extension);
});
it('Should create a Contact object without label', () => {
let contact;
expect(() => {
contact = new Contact({phoneNumber, id, type, prefix, extension});
}).not.toThrowError();
expect(contact.phoneNumber).toEqual(phoneNumber);
expect(contact.type).toEqual(type);
expect(contact.id).toEqual(id);
expect(contact.label).toBeUndefined();
expect(contact.prefix).toEqual(prefix);
expect(contact.extension).toEqual(extension);
});
it('Should create a Contact object without prefix', () => {
let contact;
expect(() => {
contact = new Contact({phoneNumber, id, type, name, extension});
}).not.toThrowError();
expect(contact.phoneNumber).toEqual(phoneNumber);
expect(contact.type).toEqual(type);
expect(contact.id).toEqual(id);
expect(contact.name).toEqual(name);
expect(contact.prefix).toBeUndefined();
expect(contact.extension).toEqual(extension);
});
it('Should create a Contact object without extension', () => {
let contact;
expect(() => {
contact = new Contact({phoneNumber, id, type, name, prefix});
}).not.toThrowError();
expect(contact.phoneNumber).toEqual(phoneNumber);
expect(contact.type).toEqual(type);
expect(contact.id).toEqual(id);
expect(contact.name).toEqual(name);
expect(contact.prefix).toEqual(prefix);
expect(contact.extension).toBeUndefined();
});
});
describe('Contact failure tests', () => {
it('Should not create a Contact object for invalid phone number', () => {
const invalidPhoneNumber = 5555555555;
expect(() => new Contact({phoneNumber: invalidPhoneNumber, id, type, name, prefix, extension}))
.toThrowError(invalid_argument);
});
it('Should not create a Contact object for invalid type', () => {
const invalidType = 'INVALID_TYPE';
expect(() => new Contact({phoneNumber, id, type: invalidType, name, prefix, extension}))
.toThrowError(invalid_argument);
});
it('Should not create a Contact object for invalid id number', () => {
const invalidId = 123;
expect(() => new Contact({phoneNumber, id: invalidId, type, name, prefix, extension}))
.toThrowError(invalid_argument);
});
it('Should not create a Contact object for invalid name', () => {
const invalidName = [];
expect(() => new Contact({phoneNumber, id, type, name: invalidName, prefix, extension}))
.toThrowError(invalid_argument);
});
it('Should not create a Contact object for invalid prefix', () => {
const invalidPrefix = [];
expect(() => new Contact({phoneNumber, id, type, name, prefix: invalidPrefix, extension}))
.toThrowError(invalid_argument);
});
it('Should not create a Contact object for invalid extension', () => {
const invalidExtension = 123;
expect(() => new Contact({phoneNumber, id, type, name, prefix, extension: invalidExtension}))
.toThrowError(invalid_argument);
});
});
});
describe('PhoneCall tests', () => {
const callId = 'callId';
const callType = Constants.CALL_TYPE.INBOUND;
const callSubtype = Constants.CALL_SUBTYPE.WEB_RTC;
const contact = new Contact({});
const fromContact = new Contact({});
const toContact = new Contact({});
const state = 'state';
const callAttributes = {};
const phoneNumber = '5555555555';
const callInfo = new CallInfo({ isOnHold: false });
const connectionId = 'connectionId';
describe('PhoneCall success tests', () => {
it('Should create a PhoneCall object without error', () => {
let phoneCall;
expect(() => {
phoneCall = new PhoneCall({callId, callType, callSubtype, callInfo, contact, state, callAttributes, phoneNumber, fromContact, toContact, connectionId });
}).not.toThrowError();
expect(phoneCall.callId).toEqual(callId);
expect(phoneCall.callType).toEqual(callType);
expect(phoneCall.callSubtype).toEqual(callSubtype);
expect(phoneCall.callInfo).toEqual(callInfo);
expect(phoneCall.contact).toEqual(contact);
expect(phoneCall.state).toEqual(state);
expect(phoneCall.callAttributes).toEqual(callAttributes);
expect(phoneCall.phoneNumber).toEqual(phoneNumber);
expect(phoneCall.fromContact).toEqual(fromContact);
expect(phoneCall.toContact).toEqual(toContact);
expect(phoneCall.connectionId).toEqual(connectionId);
});
it('Should create a PhoneCall object without phone number', () => {
let phoneCall;
expect(() => {
phoneCall = new PhoneCall({callId, callType, callSubtype, contact, state, callAttributes });
}).not.toThrowError();
expect(phoneCall.callId).toEqual(callId);
expect(phoneCall.callType).toEqual(callType);
expect(phoneCall.callSubtype).toEqual(callSubtype);
expect(phoneCall.contact).toEqual(contact);
expect(phoneCall.state).toEqual(state);
expect(phoneCall.callAttributes).toEqual(callAttributes);
expect(phoneCall.connectionId).toEqual(callId);
});
it('Should create a PhoneCall object without callId & callType & callSubtype', () => {
let phoneCall;
expect(() => {
phoneCall = new PhoneCall({ contact, state, callAttributes });
}).not.toThrowError();
expect(phoneCall.contact).toEqual(contact);
expect(phoneCall.state).toEqual(state);
expect(phoneCall.callAttributes).toEqual(callAttributes);
});
it('Should create a PhoneCall object with toContact without using contact object', () => {
let phoneCall;
expect(() => {
phoneCall = new PhoneCall({ contact, state, callAttributes });
}).not.toThrowError();
expect(phoneCall.contact).toEqual(contact);
expect(phoneCall.toContact).toEqual(contact);
expect(phoneCall.state).toEqual(state);
expect(phoneCall.callAttributes).toEqual(callAttributes);
});
});
describe('PhoneCall failure tests', () => {
it('Should not create a PhoneCall object for invalid call id', () => {
const