Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "3.1.1",
"version": "3.1.2",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <support@kuzzle.io>",
"repository": {
Expand Down
5 changes: 2 additions & 3 deletions src/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,12 @@ function notificationCallback (data) {
return this.kuzzle.emitEvent('jwtTokenExpired');
}

if (data.controller === 'document') {
if (data.controller === 'document' || (data.controller === 'realtime' && data.action === 'publish')) {
data.type = 'document';
data.document = new Document(this.collection, data.result._id, data.result._source);
delete data.result;
}

if (data.controller === 'realtime') {
else if (data.controller === 'realtime') {
data.type = 'user';
data.user = {count: data.result.count};
delete data.result;
Expand Down
28 changes: 28 additions & 0 deletions test/Room/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,34 @@ describe('Room methods', function () {
.be.an.instanceOf(Document);
});

it('should handle realtime publish notifications', () => {
notifCB.call(room, {
controller: 'realtime',
action: 'publish',
result: {
_source: {
foo: 'bar'
}
}
});

should(room.callback)
.be.calledOnce()
.be.calledWithMatch(null, {
controller: 'realtime',
action: 'publish',
type: 'document',
document: {
id: undefined,
content: {
foo: 'bar'
}
}
});
should(room.callback.firstCall.args[1].document)
.be.an.instanceOf(Document);
});

it('should handle user notifications', () => {
notifCB.call(room, {
controller: 'realtime',
Expand Down