Skip to content

Commit 0a1998f

Browse files
Merge pull request #39 from MyPureCloud/gh-7
Fixes #7; adds some test coverage.
2 parents 8dbb9aa + c4f3b48 commit 0a1998f

4 files changed

Lines changed: 39 additions & 21 deletions

File tree

src/client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,15 @@ export default class PureCloudWebrtcSdk extends WildEmitter {
180180
/**
181181
* Accept a pending session based on the passed in ID.
182182
* @param id string ID of the pending session
183+
* @param opts object with mediaStream and/or audioElement to attach to session
183184
*/
184-
public acceptPendingSession (id: string): void {
185+
public acceptPendingSession (id: string, opts?: { mediaStream ?: MediaStream, audioElement?: HTMLAudioElement}): void {
186+
if (opts && opts.mediaStream) {
187+
this.pendingStream = opts.mediaStream;
188+
}
189+
if (opts && opts.audioElement) {
190+
this._pendingAudioElement = opts.audioElement;
191+
}
185192
this._streamingConnection.webrtcSessions.acceptRtcSession(id);
186193
}
187194

@@ -214,7 +221,7 @@ export default class PureCloudWebrtcSdk extends WildEmitter {
214221
const { body } = await requestApi.call(this, `/conversations/calls/${session.conversationId}`);
215222
const participant = body.participants
216223
.find((p: { user?: { id?: string } }) => p.user && p.user.id === this._personDetails.id);
217-
return requestApi.call(this, `/conversations/calls/${session.conversationId}/participants/${participant.id}`, {
224+
await requestApi.call(this, `/conversations/calls/${session.conversationId}/participants/${participant.id}`, {
218225
method: 'patch',
219226
data: JSON.stringify({ state: 'disconnected' })
220227
});

src/logging.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let APP_VERSION = '[AIV]{version}[/AIV]'; // injected by webpack auto-inject-ver
1111

1212
// check if it was replaced.
1313
// if it wasn't we're being imported or required from source, so get it from package.json
14+
/* istanbul ignore next */
1415
if (APP_VERSION.indexOf('AIV') > -1 &&
1516
APP_VERSION.indexOf('{version}') > -1 &&
1617
APP_VERSION.indexOf('/AIV') > -1) {

test/test-utils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ interface MockApiOptions {
4444
failSecurityCode?: boolean;
4545
failOrg?: boolean;
4646
failUser?: boolean;
47+
failConversationPatch?: boolean;
4748
failStreaming?: boolean;
4849
failLogs?: boolean;
4950
failLogsPayload?: boolean;
@@ -123,6 +124,7 @@ function mockApis (options: MockApiOptions = {}): MockApiReturns {
123124
failSecurityCode,
124125
failOrg,
125126
failUser,
127+
failConversationPatch,
126128
failStreaming,
127129
failLogs,
128130
failLogsPayload,
@@ -177,9 +179,15 @@ function mockApis (options: MockApiOptions = {}): MockApiReturns {
177179

178180
let patchConversation: nock.Scope;
179181
if (conversationId && participantId) {
180-
patchConversation = conversationsApi
181-
.patch(`/api/v2/conversations/calls/${conversationId}/participants/${participantId}`)
182-
.reply(202, {});
182+
if (failConversationPatch) {
183+
patchConversation = conversationsApi
184+
.patch(`/api/v2/conversations/calls/${conversationId}/participants/${participantId}`)
185+
.reply(401);
186+
} else {
187+
patchConversation = conversationsApi
188+
.patch(`/api/v2/conversations/calls/${conversationId}/participants/${participantId}`)
189+
.reply(202, {});
190+
}
183191
}
184192

185193
Object.defineProperty(global, 'window', { value: global.window || {}, writable: true });

test/unit/client.test.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,24 @@ describe('Client', () => {
284284
expect(mockSession.end).not.toHaveBeenCalled();
285285
});
286286

287-
// test.serial('requests the conversation then patches the participant to disconnected', async t => {
288-
// const sessionId = random();
289-
// const conversationId = random();
290-
// const participantId = PARTICIPANT_ID;
291-
// const { sdk, getConversation, patchConversation } = mockApis({ conversationId, participantId });
292-
// await sdk.initialize();
293-
294-
// const mockSession = { id: sessionId, conversationId, end: sinon.stub() };
295-
// sdk._sessionManager.sessions = {};
296-
// sdk._sessionManager.sessions[sessionId] = mockSession;
297-
298-
// await sdk.endSession({ conversationId });
299-
// getConversation.done();
300-
// patchConversation.done();
301-
// sinon.assert.notCalled(mockSession.end);
302-
// });
287+
test('ends the session directly if patching the conversation fails', async () => {
288+
const sessionId = random();
289+
const conversationId = random();
290+
const participantId = PARTICIPANT_ID;
291+
const { sdk, getConversation, patchConversation } = mockApis({ conversationId, participantId, failConversationPatch: true });
292+
await sdk.initialize();
293+
294+
const mockSession = { id: sessionId, conversationId, end: jest.fn() };
295+
sdk._sessionManager.sessions = {};
296+
sdk._sessionManager.sessions[sessionId] = mockSession;
297+
298+
await sdk.endSession({ id: sessionId })
299+
.catch(() => {
300+
getConversation.done();
301+
patchConversation.done();
302+
expect(mockSession.end).toHaveBeenCalled();
303+
});
304+
});
303305

304306
test('rejects if not provided either an id or a conversationId', async done => {
305307
const { sdk } = mockApis();

0 commit comments

Comments
 (0)