Skip to content

Commit

Permalink
Fixing stop broadcast (#333)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
marinaserranomontes and jeffswartz authored Jun 11, 2024
1 parent d743baa commit 1bdd7b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});
};

Expand Down
13 changes: 11 additions & 2 deletions test/opentok-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1895,15 +1895,15 @@ 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({
message: 'error message'
});
}
else {
body = JSON.stringify(mockBroadcastObject);
body = jsonResponse ? JSON.stringify(mockBroadcastObject) : mockBroadcastObject;
}
nock('https://api.opentok.com')
.post('/v2/project/APIKEY/broadcast/' + broadcastId + '/stop')
Expand All @@ -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;
Expand Down

0 comments on commit 1bdd7b2

Please sign in to comment.