Skip to content

Commit

Permalink
fix: subscription to a LiveQuery containing ParseQuery.select overr…
Browse files Browse the repository at this point in the history
…ides properties (#1488)
  • Loading branch information
dblythy authored Jul 2, 2022
1 parent e5420ff commit b80eee4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
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

0 comments on commit b80eee4

Please sign in to comment.