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
5 changes: 4 additions & 1 deletion src/LiveQueryClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ class LiveQueryClient extends EventEmitter {
data.original = ParseObject.fromJSON(data.original, false);
}
delete data.object.__type;
const parseObject = ParseObject.fromJSON(data.object, override);
const parseObject = ParseObject.fromJSON(
data.object,
!(subscription.query && subscription.query._select) ? override : false
);

if (data.original) {
subscription.emit(data.op, parseObject, data.original, response);
Expand Down
37 changes: 37 additions & 0 deletions src/__tests__/LiveQueryClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,43 @@ describe('LiveQueryClient', () => {
spy.mockRestore();
});

it('can handle select in websocket payload', () => {
const liveQueryClient = new LiveQueryClient({
applicationId: 'applicationId',
serverURL: 'ws://test',
javascriptKey: 'javascriptKey',
masterKey: 'masterKey',
sessionToken: 'sessionToken',
});
// Add mock subscription
const subscription = new events.EventEmitter();
subscription.query = new ParseQuery('Test').select('foo');
liveQueryClient.subscriptions.set(1, subscription);
const object = new ParseObject('Test');
const original = new ParseObject('Test');
object.set('key', 'value');
original.set('key', 'old');
const data = {
op: 'update',
clientId: 1,
requestId: 1,
object: object._toFullJSON(),
original: original._toFullJSON(),
};
const event = {
data: JSON.stringify(data),
};

const spy = jest
.spyOn(ParseObject, 'fromJSON')
.mockImplementationOnce(() => original)
.mockImplementationOnce(() => object);

liveQueryClient._handleWebSocketMessage(event);
expect(ParseObject.fromJSON.mock.calls[1][1]).toEqual(false);
spy.mockRestore();
});

it('can handle WebSocket response unset field', async () => {
const liveQueryClient = new LiveQueryClient({
applicationId: 'applicationId',
Expand Down