Skip to content

Commit 7441e86

Browse files
committed
KuzzleRoom.count now fail if there is no room ID
1 parent 8188bd5 commit 7441e86

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/kuzzleRoom.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,18 @@ KuzzleRoom.prototype.count = function (cb) {
126126
var data;
127127

128128
this.kuzzle.callbackRequired('KuzzleRoom.count', cb);
129+
129130
data = this.kuzzle.addHeaders({body: {roomId: this.roomId}}, this.headers);
130131

131132
if (this.subscribing) {
132133
this.queue.push({action: 'count', args: [cb]});
133134
return this;
134135
}
135136

137+
if (!this.roomId) {
138+
throw new Error('KuzzleRoom.count: cannot count subscriptions on an inactive room');
139+
}
140+
136141
this.kuzzle.query(this.collection.buildQueryArgs('subscribe', 'count'), data, function (err, res) {
137142
if (err) {
138143
return cb(err);
@@ -165,6 +170,8 @@ KuzzleRoom.prototype.renew = function (filters, cb) {
165170
filters = null;
166171
}
167172

173+
self.kuzzle.callbackRequired('KuzzleRoom.renew', cb);
174+
168175
/*
169176
Skip subscription renewal if another one was performed a moment before
170177
*/
@@ -191,8 +198,6 @@ KuzzleRoom.prototype.renew = function (filters, cb) {
191198
return self;
192199
}
193200

194-
self.kuzzle.callbackRequired('KuzzleRoom.renew', cb);
195-
196201
self.unsubscribe();
197202
self.roomId = null;
198203
self.subscribing = true;

test/kuzzleRoom/methods.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe('KuzzleRoom methods', function () {
7171
body: {}
7272
};
7373
room = new KuzzleRoom(dataCollection);
74+
room.roomId = 'foobar';
7475
});
7576

7677
it('should send the right query to Kuzzle', function () {
@@ -111,6 +112,11 @@ describe('KuzzleRoom methods', function () {
111112
done();
112113
});
113114
});
115+
116+
it('should fail if the room has no room ID', function () {
117+
room.roomId = undefined;
118+
should(function () {room.count(function () {})}).throw();
119+
});
114120
});
115121

116122
describe('#renew', function () {

0 commit comments

Comments
 (0)