From 1bdd7b26418cd117c841dd21b3202a0aeb01e99c Mon Sep 17 00:00:00 2001 From: marina serrano montes Date: Tue, 11 Jun 2024 21:54:33 +0200 Subject: [PATCH] Fixing stop broadcast (#333) * Fixing stop broadcast * Update package-lock.json * Rev version to 2.18.1 * revert version change * Add test for non-JSON stopBroadcast response * Fix test --------- Co-authored-by: Jeff Swartz --- lib/client.js | 5 ++++- test/opentok-test.js | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index 9983685c..fa4af290 100644 --- a/lib/client.js +++ b/lib/client.js @@ -288,7 +288,10 @@ Client.prototype.stopBroadcast = function (broadcastId, cb) { method: 'POST', body: { }, headers: this.generateHeaders(), - callback: cb, + callback: (err, json) => { + const responseText = typeof json === 'object' ? JSON.stringify(json) : json; + cb(err, responseText); + }, }); }; diff --git a/test/opentok-test.js b/test/opentok-test.js index ea2bf1cf..af1ae4ef 100644 --- a/test/opentok-test.js +++ b/test/opentok-test.js @@ -1895,7 +1895,7 @@ describe('#stopBroadcast', function () { var opentok = new OpenTok('APIKEY', 'APISECRET'); var BROADCAST_ID = 'BROADCAST_ID'; - function mockStopBroadcastRequest(broadcastId, status) { + function mockStopBroadcastRequest(broadcastId, status, jsonResponse) { var body; if (status) { body = JSON.stringify({ @@ -1903,7 +1903,7 @@ describe('#stopBroadcast', function () { }); } else { - body = JSON.stringify(mockBroadcastObject); + body = jsonResponse ? JSON.stringify(mockBroadcastObject) : mockBroadcastObject; } nock('https://api.opentok.com') .post('/v2/project/APIKEY/broadcast/' + broadcastId + '/stop') @@ -1915,6 +1915,15 @@ describe('#stopBroadcast', function () { }); it('succeeds given valid parameters', function (done) { + mockStopBroadcastRequest(BROADCAST_ID, null, true); + opentok.stopBroadcast(BROADCAST_ID, function (err, broadcast) { + expect(err).to.be.null; + validateBroadcastObject(broadcast); + done(); + }); + }); + + it('succeeds with non-json body response', function (done) { mockStopBroadcastRequest(BROADCAST_ID); opentok.stopBroadcast(BROADCAST_ID, function (err, broadcast) { expect(err).to.be.null;