Add original object to LiveQuery Events (#5265)
* Add original object to LiveQuery Events * change response original
This commit is contained in:
committed by
Florent Vilmart
parent
de92ce5c49
commit
ce7ff2ca44
@@ -899,6 +899,56 @@ describe('ParseLiveQueryServer', function() {
|
|||||||
}, jasmine.ASYNC_TEST_WAIT_TIME);
|
}, jasmine.ASYNC_TEST_WAIT_TIME);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can handle update command with original object', function(done) {
|
||||||
|
jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client');
|
||||||
|
const Client = require('../lib/LiveQuery/Client').Client;
|
||||||
|
const parseLiveQueryServer = new ParseLiveQueryServer({});
|
||||||
|
// Make mock request message
|
||||||
|
const message = generateMockMessage(true);
|
||||||
|
|
||||||
|
const clientId = 1;
|
||||||
|
const parseWebSocket = {
|
||||||
|
clientId,
|
||||||
|
send: jasmine.createSpy('send'),
|
||||||
|
};
|
||||||
|
const client = new Client(clientId, parseWebSocket);
|
||||||
|
spyOn(client, 'pushUpdate').and.callThrough();
|
||||||
|
parseLiveQueryServer.clients.set(clientId, client);
|
||||||
|
|
||||||
|
// Add mock subscription
|
||||||
|
const requestId = 2;
|
||||||
|
|
||||||
|
addMockSubscription(
|
||||||
|
parseLiveQueryServer,
|
||||||
|
clientId,
|
||||||
|
requestId,
|
||||||
|
parseWebSocket
|
||||||
|
);
|
||||||
|
// Mock _matchesSubscription to return matching
|
||||||
|
parseLiveQueryServer._matchesSubscription = function(parseObject) {
|
||||||
|
if (!parseObject) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
parseLiveQueryServer._matchesACL = function() {
|
||||||
|
return Promise.resolve(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
parseLiveQueryServer._onAfterSave(message);
|
||||||
|
|
||||||
|
// Make sure we send update command to client
|
||||||
|
setTimeout(function() {
|
||||||
|
expect(client.pushUpdate).toHaveBeenCalled();
|
||||||
|
const args = parseWebSocket.send.calls.mostRecent().args;
|
||||||
|
const toSend = JSON.parse(args[0]);
|
||||||
|
|
||||||
|
expect(toSend.object).toBeDefined();
|
||||||
|
expect(toSend.original).toBeDefined();
|
||||||
|
done();
|
||||||
|
}, jasmine.ASYNC_TEST_WAIT_TIME);
|
||||||
|
});
|
||||||
|
|
||||||
it('can handle object create command which matches some subscriptions', function(done) {
|
it('can handle object create command which matches some subscriptions', function(done) {
|
||||||
const parseLiveQueryServer = new ParseLiveQueryServer({});
|
const parseLiveQueryServer = new ParseLiveQueryServer({});
|
||||||
// Make mock request message
|
// Make mock request message
|
||||||
|
|||||||
@@ -78,7 +78,11 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_pushEvent(type: string): Function {
|
_pushEvent(type: string): Function {
|
||||||
return function(subscriptionId: number, parseObjectJSON: any): void {
|
return function(
|
||||||
|
subscriptionId: number,
|
||||||
|
parseObjectJSON: any,
|
||||||
|
parseOriginalObjectJSON: any
|
||||||
|
): void {
|
||||||
const response: Message = {
|
const response: Message = {
|
||||||
op: type,
|
op: type,
|
||||||
clientId: this.id,
|
clientId: this.id,
|
||||||
@@ -92,6 +96,12 @@ class Client {
|
|||||||
fields = this.subscriptionInfos.get(subscriptionId).fields;
|
fields = this.subscriptionInfos.get(subscriptionId).fields;
|
||||||
}
|
}
|
||||||
response['object'] = this._toJSONWithFields(parseObjectJSON, fields);
|
response['object'] = this._toJSONWithFields(parseObjectJSON, fields);
|
||||||
|
if (typeof parseOriginalObjectJSON !== 'undefined') {
|
||||||
|
response['original'] = this._toJSONWithFields(
|
||||||
|
parseOriginalObjectJSON,
|
||||||
|
fields
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Client.pushResponse(this.parseWebSocket, JSON.stringify(response));
|
Client.pushResponse(this.parseWebSocket, JSON.stringify(response));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -292,7 +292,11 @@ class ParseLiveQueryServer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const functionName = 'push' + type;
|
const functionName = 'push' + type;
|
||||||
client[functionName](requestId, currentParseObject);
|
client[functionName](
|
||||||
|
requestId,
|
||||||
|
currentParseObject,
|
||||||
|
originalParseObject
|
||||||
|
);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
logger.error('Matching ACL error : ', error);
|
logger.error('Matching ACL error : ', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user