From a9cc7bf3e7acebee333503f03a72db4e9999867e Mon Sep 17 00:00:00 2001 From: Michael Huynh Date: Thu, 15 Aug 2024 11:44:42 -0700 Subject: [PATCH 1/3] feat: call progress event e2e tests --- .../callMessage/callProgressEvent.ts | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 tests/integration/callMessage/callProgressEvent.ts diff --git a/tests/integration/callMessage/callProgressEvent.ts b/tests/integration/callMessage/callProgressEvent.ts new file mode 100644 index 00000000..d90b9485 --- /dev/null +++ b/tests/integration/callMessage/callProgressEvent.ts @@ -0,0 +1,141 @@ +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import Device from '../../../lib/twilio/device'; +import type Call from '../../../lib/twilio/call'; +import { generateAccessToken } from '../../lib/token'; +import { expectEvent } from '../../lib/util'; +const env = require('../../env'); + +function waitFor(n: number, reject?: boolean) { + return new Promise((res, rej) => setTimeout(reject ? rej : res, n)); +} + +describe('callProgressEvent', function() { + let teardown: () => void; + + this.timeout(1000 * 60 * 10); // 10 minute timeout for the whole suite + + const setup = async (aliceOptions: any, bobOptions: any, tokenTtl = 180) => { + const aliceId = `client-id-call-message-tests-alice-${Date.now()}`; + const aliceToken = generateAccessToken(aliceId, tokenTtl, env.appSid); + const aliceDevice = new Device(aliceToken, aliceOptions); + + const bobId = `client-id-call-message-tests-bob-${Date.now()}`; + const bobToken = generateAccessToken(bobId, tokenTtl, env.appSid); + const bobDevice = new Device(bobToken, bobOptions); + + teardown = () => { + aliceDevice.destroy(); + bobDevice.destroy(); + }; + + await bobDevice.register(); + + const bobCallPromise: Promise = expectEvent( + Device.EventName.Incoming, + bobDevice, + ); + + const aliceCall = await aliceDevice.connect({ params: { To: bobId } }); + const bobCall = await bobCallPromise; + + const aliceMessageReceivedSpy = sinon.spy(); + const bobMessageReceivedSpy = sinon.spy(); + + aliceCall.on('messageReceived', aliceMessageReceivedSpy); + bobCall.on('messageReceived', bobMessageReceivedSpy); + + const aliceCallAcceptPromise = expectEvent('accept', aliceCall); + const bobCallAcceptPromise = expectEvent('accept', bobCall); + + bobCall.accept(); + + await aliceCallAcceptPromise; + await bobCallAcceptPromise; + + await waitFor(5000); + + return { + aliceDevice, + bobDevice, + aliceCall, + bobCall, + aliceMessageReceivedSpy, + bobMessageReceivedSpy, + }; + }; + + beforeEach(() => { + teardown = () => {}; + }); + + afterEach(() => { + teardown?.(); + }); + + // NOTE(mhuynh): Once backend changes are done to facilitate call message + // event type filtering, we can re-enable this test. + // See VBLOCKS-3332 + it.skip( + 'does not receive call progress events', + async function() { + const callMessageEvents = []; + const deviceOptions = { callMessageEvents }; + + const { aliceMessageReceivedSpy, bobMessageReceivedSpy } = await setup( + deviceOptions, + deviceOptions, + ); + + sinon.assert.notCalled(aliceMessageReceivedSpy); + sinon.assert.notCalled(bobMessageReceivedSpy); + }, + ); + + it( + 'receives call progress events', + async function() { + const callMessageEvents = ['call-progress-event']; + const deviceOptions = { callMessageEvents }; + + const { aliceCall, aliceMessageReceivedSpy, bobMessageReceivedSpy } = + await setup(deviceOptions, deviceOptions); + + aliceCall.disconnect(); + + await waitFor(5000); + + const expectedCallProgressEvents = + ['ringing', 'initiated', 'in-progress']; + + const actualCallProgressEvents: any[] = []; + + for (const arg of aliceMessageReceivedSpy.args) { + assert.strictEqual(arg.length, 1); + + const { + content: { + ParentCallSid, + CallType, + CallStatus, + CallSid, + }, + contentType, + messageType, + voiceEventSid + } = arg[0]; + + assert.deepStrictEqual(CallType, 'CLIENT'); + assert.deepStrictEqual(contentType, 'application/json'); + assert.deepStrictEqual(messageType, 'call-progress-event'); + + actualCallProgressEvents.push(CallStatus); + } + + assert.deepStrictEqual( + actualCallProgressEvents, + expectedCallProgressEvents, + ); + }, + ); +}); From 6c126408db7253f7f7d4f0f0950747435783ff00 Mon Sep 17 00:00:00 2001 From: Michael Huynh Date: Thu, 15 Aug 2024 13:38:01 -0700 Subject: [PATCH 2/3] fix: remove unsupported nullish function invocation --- tests/integration/callMessage/callProgressEvent.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/callMessage/callProgressEvent.ts b/tests/integration/callMessage/callProgressEvent.ts index d90b9485..2b604697 100644 --- a/tests/integration/callMessage/callProgressEvent.ts +++ b/tests/integration/callMessage/callProgressEvent.ts @@ -70,7 +70,9 @@ describe('callProgressEvent', function() { }); afterEach(() => { - teardown?.(); + if (teardown) { + teardown(); + } }); // NOTE(mhuynh): Once backend changes are done to facilitate call message From 9b4a67a73e38864c787aae4083aab90bf61f00fe Mon Sep 17 00:00:00 2001 From: Michael Huynh Date: Thu, 15 Aug 2024 14:14:56 -0700 Subject: [PATCH 3/3] fix: comment out unused test --- .../callMessage/callProgressEvent.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/integration/callMessage/callProgressEvent.ts b/tests/integration/callMessage/callProgressEvent.ts index 2b604697..8e8fcebe 100644 --- a/tests/integration/callMessage/callProgressEvent.ts +++ b/tests/integration/callMessage/callProgressEvent.ts @@ -78,21 +78,21 @@ describe('callProgressEvent', function() { // NOTE(mhuynh): Once backend changes are done to facilitate call message // event type filtering, we can re-enable this test. // See VBLOCKS-3332 - it.skip( - 'does not receive call progress events', - async function() { - const callMessageEvents = []; - const deviceOptions = { callMessageEvents }; - - const { aliceMessageReceivedSpy, bobMessageReceivedSpy } = await setup( - deviceOptions, - deviceOptions, - ); - - sinon.assert.notCalled(aliceMessageReceivedSpy); - sinon.assert.notCalled(bobMessageReceivedSpy); - }, - ); + // it( + // 'does not receive call progress events', + // async function() { + // const callMessageEvents = []; + // const deviceOptions = { callMessageEvents }; + + // const { aliceMessageReceivedSpy, bobMessageReceivedSpy } = await setup( + // deviceOptions, + // deviceOptions, + // ); + + // sinon.assert.notCalled(aliceMessageReceivedSpy); + // sinon.assert.notCalled(bobMessageReceivedSpy); + // }, + // ); it( 'receives call progress events',