Skip to content

Commit

Permalink
Updated getSubscriptions to return all subscriptions by topic
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-blasco committed Feb 23, 2021
1 parent fbf975d commit 969484b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,18 @@
* @function
* @public
* @alias getSubscriptions
* @return { Array }
*/
PubSub.getSubscriptions = function getSubscriptions(topic){
var m;
var token;
var list = [];
for (m in messages){
if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0){
list.push(m);
if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0) {
for (token in messages[m]) {
list.push(messages[m][token]);
}
break;
}
}
return list;
Expand Down
13 changes: 13 additions & 0 deletions test/test-getSubscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,17 @@ describe('getSubscriptions method', function () {
assert.equals(subscriptions,1);
});

it('should return all subscriptions', function() {
var topic = TestHelper.getUniqueString(),
spy1 = sinon.spy(),
spy2 = sinon.spy();

PubSub.subscribe(topic, spy1);
PubSub.subscribe(topic, spy2);

var subscriptions = PubSub.getSubscriptions(topic);
assert.equals(subscriptions[0], spy1);
assert.equals(subscriptions[1], spy2);
});

});

0 comments on commit 969484b

Please sign in to comment.