Skip to content

Commit 195890c

Browse files
author
timmydoza
authored
Merge pull request #71 from twilio-labs/use-default-twilio-client
Use default twilio client
2 parents f72c8a2 + b75ad75 commit 195890c

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.8.2
4+
5+
### Maintenence
6+
7+
- 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()`.
8+
39
## 0.8.1
410

511
### Enhancement

src/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ TWILIO_API_SECRET = the secret for the API Key`);
212212
},
213213
pkgJson: {
214214
dependencies: {
215-
twilio: '^3.54.2',
215+
twilio: '^3.60.0', // This determines the version of the Twilio client returned by context.getTwilioClient()
216216
},
217217
},
218218
functionsEnv: 'dev',

src/serverless/functions/recordingrules.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/* global Twilio Runtime */
22
'use strict';
33

4-
// We need to use a newer twilio client than the one provided by context.getTwilioClient(),
5-
// so we require it here. The version is specified in helpers.js in the 'deployOptions' object.
6-
// TODO: replace with context.getTwilioClient() when https://issues.corp.twilio.com/browse/RUN-3731 is complete
7-
const twilio = require('twilio');
8-
94
module.exports.handler = async (context, event, callback) => {
105
const authHandler = require(Runtime.getAssets()['/auth-handler.js'].path);
116
authHandler(context, event, callback);
@@ -37,7 +32,7 @@ module.exports.handler = async (context, event, callback) => {
3732
return callback(null, response);
3833
}
3934

40-
const client = twilio(context.ACCOUNT_SID, context.AUTH_TOKEN);
35+
const client = context.getTwilioClient();
4136

4237
try {
4338
const recordingRulesResponse = await client.video.rooms(room_sid).recordingRules.update({ rules });

test/serverless/functions/recordingrules.test.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ const mockClient = jest.fn(() => ({
1313
},
1414
}));
1515

16+
const mockContext = {
17+
ACCOUNT_SID: '1234',
18+
AUTH_TOKEN: '2345',
19+
getTwilioClient: () => mockClient(),
20+
};
21+
1622
jest.mock('twilio');
1723
twilio.mockImplementation(mockClient);
1824

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

23-
await handler(
24-
{ ACCOUNT_SID: '1234', AUTH_TOKEN: '2345' },
25-
{ room_sid: 'mockRoomSid', rules: 'mockRules' },
26-
mockCallback
27-
);
29+
await handler(mockContext, { room_sid: 'mockRoomSid', rules: 'mockRules' }, mockCallback);
2830

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

42-
await handler(
43-
{ ACCOUNT_SID: '1234', AUTH_TOKEN: '2345' },
44-
{ room_sid: 'mockRoomSid', rules: 'mockRules' },
45-
mockCallback
46-
);
43+
await handler(mockContext, { room_sid: 'mockRoomSid', rules: 'mockRules' }, mockCallback);
4744

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

58-
await handler({ ACCOUNT_SID: '1234', AUTH_TOKEN: '2345' }, { rules: 'mockRules' }, mockCallback);
55+
await handler(mockContext, { rules: 'mockRules' }, mockCallback);
5956

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

75-
await handler({ ACCOUNT_SID: '1234', AUTH_TOKEN: '2345' }, { room_sid: 'mockSid' }, mockCallback);
72+
await handler(mockContext, { room_sid: 'mockSid' }, mockCallback);
7673

7774
expect(mockCallback).toHaveBeenCalledWith(null, {
7875
body: {

0 commit comments

Comments
 (0)