forked from amazon-connect/amazon-connect-streams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ringtone.spec.js
188 lines (158 loc) · 8.4 KB
/
ringtone.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
require("../unit/test-setup.js");
describe('RingtoneEngine', function () {
var sandbox = sinon.createSandbox();
var bus,
contactId,
contact;
before(function () {
bus = new connect.EventBus();
global.ringtoneObj = {
ringtoneUrl: "ringtone.com"
}
contactId = "1234567890";
contact = new connect.Contact(contactId);
});
function contactStubHelper(contactStubMethodToOutput) {
sandbox.stub(contact, "getType").returns(contactStubMethodToOutput.contactType);
sandbox.stub(contact, "isSoftphoneCall").returns(contactStubMethodToOutput.isSoftphoneCall);
sandbox.stub(contact, "isInbound").returns(contactStubMethodToOutput.isInbound);
}
after(function () {
sandbox.restore();
});
describe('#connect.VoiceRingtoneEngine', function () {
before(function () {
connect.agent.initialized = true;
sandbox.stub(connect.core, "getEventBus").returns(bus);
sandbox.stub(connect.Agent.prototype, "getContacts").returns([]);
this.voiceRingtoneEngine = new connect.VoiceRingtoneEngine(ringtoneObj);
this.ringtoneSetup = sandbox.stub(this.voiceRingtoneEngine, "_ringtoneSetup");
assert.doesNotThrow(this.voiceRingtoneEngine._driveRingtone, Error, "Not implemented.");
sandbox.stub(contact, "getType").returns(lily.ContactType.VOICE);
sandbox.stub(contact, "isSoftphoneCall").returns(true);
sandbox.stub(contact, "isInbound").returns(true);
});
after(function () {
connect.agent.initialized = false;
sandbox.restore();
});
it('validate the VoiceRingtoneEngine implemements the _driveRingtone method and calls the _ringtoneSetup for VOICE calls', function () {
bus.trigger(connect.ContactEvents.INIT, contact);
bus.trigger(connect.core.getContactEventName(connect.ContactEvents.CONNECTING, contactId), contact);
assert.isTrue(this.ringtoneSetup.withArgs(contact).calledOnce);
});
it('validate the VoiceRingtoneEngine should not call _ringtoneSetup for non VOICE, non softphone calls', function () {
contact.getType.restore();
sandbox.stub(contact, "getType").returns(lily.ContactType.QUEUE_CALLBACK);
bus.trigger(connect.ContactEvents.INIT, contact);
bus.trigger(connect.core.getContactEventName(connect.ContactEvents.CONNECTING, contactId), contact);
this.ringtoneSetup.restore();
this.ringtoneSetup = sandbox.stub(this.voiceRingtoneEngine, "_ringtoneSetup");
assert.isTrue(this.ringtoneSetup.notCalled);
contact.getType.restore();
contact.isSoftphoneCall.restore();
sandbox.stub(contact, "isSoftphoneCall").returns(false);
sandbox.stub(contact, "getType").returns(lily.ContactType.VOICE);
assert.isTrue(this.ringtoneSetup.notCalled);
});
});
describe('#connect.QueueCallbackRingtoneEngine', function () {
before(function () {
sandbox.stub(connect.core, "getEventBus").returns(bus);
this.queueCallbackRingtoneEngine = new connect.QueueCallbackRingtoneEngine(ringtoneObj);
this.ringtoneSetup = sandbox.stub(this.queueCallbackRingtoneEngine, "_ringtoneSetup");
assert.doesNotThrow(this.queueCallbackRingtoneEngine._driveRingtone, Error, "Not implemented.");
sandbox.stub(contact, "getType").returns(lily.ContactType.QUEUE_CALLBACK);
});
after(function () {
sandbox.restore();
});
it('validate the QueueCallbackRingtoneEngine implemements _driveRingtone method and calls the _ringtoneSetup for QUEUE_CALLBACK calls ', function () {
bus.trigger(connect.ContactEvents.INIT, contact);
bus.trigger(connect.core.getContactEventName(connect.ContactEvents.INCOMING, contactId), contact);
assert.isTrue(this.ringtoneSetup.withArgs(contact).calledOnce);
});
it('validate the QueueCallbackRingtoneEngine should not call the _ringtoneSetup for Voice calls ', function () {
contact.getType.restore();
sandbox.stub(contact, "getType").returns(lily.ContactType.VOICE);
this.ringtoneSetup.restore();
this.ringtoneSetup = sandbox.stub(this.queueCallbackRingtoneEngine, "_ringtoneSetup");
bus.trigger(connect.ContactEvents.INIT, contact);
bus.trigger(connect.core.getContactEventName(connect.ContactEvents.INCOMING, contactId), contact);
assert.isTrue(this.ringtoneSetup.notCalled);
});
});
describe('#connect.ChatRingtoneEngine', function () {
before(function () {
sandbox.stub(connect.core, "getEventBus").returns(bus);
this.chatRingtoneEngine = new connect.ChatRingtoneEngine(ringtoneObj);
this.ringtoneSetup = sandbox.stub(this.chatRingtoneEngine, "_ringtoneSetup");
assert.doesNotThrow(this.chatRingtoneEngine._driveRingtone, Error, "Not implemented.");
sandbox.stub(contact, "getType").returns(lily.ContactType.CHAT);
sandbox.stub(contact, "isInbound").returns(true);
let connectionState;
sandbox.stub(connect.core, 'getAgentDataProvider').returns({
getContactData: () => ({ connections: [{ state: { type: "connecting" }}]}),
getConnectionData: () => ({
isSilentMonitor: false,
state: { type: connectionState },
getMediaController: () => {}
})
});
});
after(function () {
sandbox.restore();
});
it('validate the ChatRingtoneEngine implemements _driveRingtone method and calls the _ringtoneSetup for CHAT calls ', function () {
bus.trigger(connect.ContactEvents.INIT, contact);
bus.trigger(connect.core.getContactEventName(connect.ContactEvents.CONNECTING, contactId), contact);
assert.isTrue(this.ringtoneSetup.withArgs(contact).calledOnce);
});
it('validate the ChatRingtoneEngine should not call the _ringtoneSetup for Voice calls ', function () {
contact.getType.restore();
sandbox.stub(contact, "getType").returns(lily.ContactType.VOICE);
this.ringtoneSetup.restore();
this.ringtoneSetup = sandbox.stub(this.chatRingtoneEngine, "_ringtoneSetup");
bus.trigger(connect.ContactEvents.INIT, contact);
bus.trigger(connect.core.getContactEventName(connect.ContactEvents.CONNECTING, contactId), contact);
assert.isTrue(this.ringtoneSetup.notCalled);
});
});
describe('#connect.TaskRingtoneEngine', function () {
beforeEach(function () {
sandbox.stub(connect.core, "getEventBus").returns(bus);
this.ringtoneEngine = new connect.TaskRingtoneEngine(ringtoneObj);
this.ringtoneSetup = sandbox.stub(this.ringtoneEngine, "_ringtoneSetup");
assert.doesNotThrow(this.ringtoneEngine._driveRingtone, Error, "Not implemented.");
});
afterEach(function () {
sandbox.restore();
});
it('validate the TaskRingtoneEngine implemements the _driveRingtone method and calls the _ringtoneSetup for TASK contacts', function () {
// setup
contactStubHelper({
contactType: lily.ContactType.TASK,
isSoftphoneCall: false,
isInbound: true
});
// enact
bus.trigger(connect.ContactEvents.INIT, contact);
bus.trigger(connect.core.getContactEventName(connect.ContactEvents.CONNECTING, contactId), contact);
// verify
assert.isTrue(this.ringtoneSetup.withArgs(contact).calledOnce);
});
it('validate the TaskRingtoneEngine should not call _ringtoneSetup for non TASK', function () {
// setup
contactStubHelper({
contactType: lily.ContactType.QUEUE_CALLBACK,
isSoftphoneCall: false,
isInbound: true
});
// enact
bus.trigger(connect.ContactEvents.INIT, contact);
bus.trigger(connect.core.getContactEventName(connect.ContactEvents.CONNECTING, contactId), contact);
// verify
assert.isTrue(this.ringtoneSetup.notCalled);
});
});
});