Skip to content

Commit

Permalink
fix: map error when items is not defined for list streams
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck committed Feb 29, 2024
1 parent ee9eb27 commit 1fc3c2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Client.prototype.listStreams = function listStreams(sessionId, cb) {
method: 'GET',
headers: this.generateHeaders(),
callback: (err, body) => {
cb(err, body?.items.map((stream) => new Stream(JSON.stringify(stream))))
cb(err, body?.items?.map((stream) => new Stream(JSON.stringify(stream))) || [])
},
});
};
Expand Down
12 changes: 12 additions & 0 deletions test/opentok-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,18 @@ describe('listStreams', function () {
});
});

it('should not error when items is missing in response', function (done) {
nock('https://api.opentok.com')
.get('/v2/project/123456/session/' + SESSIONID + '/stream')
.reply(200, { count: 0 }, { 'Content-Type': 'application/json' });

opentok.listStreams(SESSIONID, function (err, streams) {
expect(err).to.be.null;
expect(streams).to.empty;
done();
});
});

it('should return an error if sessionId is null', function (done) {
opentok.listStreams(null, function (err, streams) {
expect(err).to.not.be.null;
Expand Down

0 comments on commit 1fc3c2f

Please sign in to comment.