Skip to content

fix: subscription to a LiveQuery containing ParseQuery.select overrides properties #1488

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

Merged
merged 5 commits into from
Jul 2, 2022
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