Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the fields that triggered update notifications #1364

Merged
merged 13 commits into from Aug 7, 2019
1 change: 1 addition & 0 deletions features/kuzzle.feature
Expand Up @@ -326,6 +326,7 @@ Feature: Kuzzle functional tests
When I write the document "documentAda"
Then I update the document with value "Hopper" in field "lastName"
Then I should receive a document notification with field action equal to "update"
And The notification should have "_updatedFields" array with 1 element
And The notification should have a "_source" member
And The notification should have volatile

Expand Down
11 changes: 11 additions & 0 deletions features/step_definitions/notifications.js
Expand Up @@ -37,6 +37,17 @@ Then(/^I should receive a ?(.*?) notification with field ?(.*?) equal to "([^"]*
});
});


Then(/^The notification should have "([^"]*)" array with ([\d]*) element/, function (member, n_elements, callback) {
if (this.api.responses.result[member].length === parseInt(n_elements)) {
callback();
} else {
console.log('Wrong notification received: ');
console.dir(this.api.responses, { colors: true, depth: null });
callback('The document was supposed to contain the member "' + member + '" with ' + n_elements + ' elements : Has '+ this.api.responses.result[member].length +'.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpicking) use string litterals

}
});

Then(/^The notification should ?(not)* have a "([^"]*)" member/, function (not, member, callback) {
if ((this.api.responses.result[member] || not) && !(this.api.responses.result[member] && not)) {
callback();
Expand Down
7 changes: 6 additions & 1 deletion lib/api/core/notifier.js
Expand Up @@ -340,11 +340,16 @@ class NotifierController {
result._source,
result._id);


const updatedFields = Object.keys(request.input.body)
.filter(_updatedFields => _updatedFields !== '_kuzzle_info');

return this.notifyDocument(
matchedRooms, request, 'in', 'done', 'update', {
_meta: updatedDocument._meta || {},
_id: updatedDocument._id,
_source: updatedDocument._source
_source: updatedDocument._source,
_updatedFields: updatedFields
});
})
.then(() => this.cache.get(cachePrefix + updatedDocument._id))
Expand Down
3 changes: 2 additions & 1 deletion test/api/core/notifier/notifyDocumentUpdate.test.js
Expand Up @@ -65,7 +65,8 @@ describe('Test: notifier.notifyDocumentUpdate', () => {
{
_id,
_meta: {canIhas: 'cheezburgers?'},
_source: {foo: 'bar'}
_source: {foo: 'bar'},
_updatedFields: ['foo']
});

should(notifier.notifyDocument.getCall(1)).calledWith(
Expand Down