Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.8.2

### Maintenence

- The [recording rules function](https://github.com/twilio-labs/plugin-rtc/blob/master/src/serverless/functions/recordingrules.js) now uses the Twilio client returned by `context.getTwilioClient()`.

## 0.8.1

### Enhancement
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ TWILIO_API_SECRET = the secret for the API Key`);
},
pkgJson: {
dependencies: {
twilio: '^3.54.2',
twilio: '^3.60.0', // This determines the version of the Twilio client returned by context.getTwilioClient()
},
},
functionsEnv: 'dev',
Expand Down
7 changes: 1 addition & 6 deletions src/serverless/functions/recordingrules.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/* global Twilio Runtime */
'use strict';

// We need to use a newer twilio client than the one provided by context.getTwilioClient(),
// so we require it here. The version is specified in helpers.js in the 'deployOptions' object.
// TODO: replace with context.getTwilioClient() when https://issues.corp.twilio.com/browse/RUN-3731 is complete
const twilio = require('twilio');

module.exports.handler = async (context, event, callback) => {
const authHandler = require(Runtime.getAssets()['/auth-handler.js'].path);
authHandler(context, event, callback);
Expand Down Expand Up @@ -37,7 +32,7 @@ module.exports.handler = async (context, event, callback) => {
return callback(null, response);
}

const client = twilio(context.ACCOUNT_SID, context.AUTH_TOKEN);
const client = context.getTwilioClient();

try {
const recordingRulesResponse = await client.video.rooms(room_sid).recordingRules.update({ rules });
Expand Down
23 changes: 10 additions & 13 deletions test/serverless/functions/recordingrules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ const mockClient = jest.fn(() => ({
},
}));

const mockContext = {
ACCOUNT_SID: '1234',
AUTH_TOKEN: '2345',
getTwilioClient: () => mockClient(),
};

jest.mock('twilio');
twilio.mockImplementation(mockClient);

describe('the recordingrules function', () => {
it('should correctly respond when a room update is successful', async () => {
const mockCallback = jest.fn();

await handler(
{ ACCOUNT_SID: '1234', AUTH_TOKEN: '2345' },
{ room_sid: 'mockRoomSid', rules: 'mockRules' },
mockCallback
);
await handler(mockContext, { room_sid: 'mockRoomSid', rules: 'mockRules' }, mockCallback);

expect(mockClient).toHaveBeenCalledWith('1234', '2345');
expect(mockCallback).toHaveBeenCalledWith(null, {
body: 'mockSuccessResponse',
headers: { 'Content-Type': 'application/json' },
Expand All @@ -39,11 +40,7 @@ describe('the recordingrules function', () => {
const mockError = { message: 'mockErrorMesage', code: 123 };
mockUpdateFn.mockImplementationOnce(() => Promise.reject(mockError));

await handler(
{ ACCOUNT_SID: '1234', AUTH_TOKEN: '2345' },
{ room_sid: 'mockRoomSid', rules: 'mockRules' },
mockCallback
);
await handler(mockContext, { room_sid: 'mockRoomSid', rules: 'mockRules' }, mockCallback);

expect(mockCallback).toHaveBeenCalledWith(null, {
body: { error: mockError },
Expand All @@ -55,7 +52,7 @@ describe('the recordingrules function', () => {
it('should return a "missing room_sid" error when the room_sid is absent', async () => {
const mockCallback = jest.fn();

await handler({ ACCOUNT_SID: '1234', AUTH_TOKEN: '2345' }, { rules: 'mockRules' }, mockCallback);
await handler(mockContext, { rules: 'mockRules' }, mockCallback);

expect(mockCallback).toHaveBeenCalledWith(null, {
body: {
Expand All @@ -72,7 +69,7 @@ describe('the recordingrules function', () => {
it('should return a "missing rules" error when the rules array is absent', async () => {
const mockCallback = jest.fn();

await handler({ ACCOUNT_SID: '1234', AUTH_TOKEN: '2345' }, { room_sid: 'mockSid' }, mockCallback);
await handler(mockContext, { room_sid: 'mockSid' }, mockCallback);

expect(mockCallback).toHaveBeenCalledWith(null, {
body: {
Expand Down