Skip to content

Commit

Permalink
fix: LiveQuery can return incorrectly formatted date (#8456)
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy authored Mar 6, 2023
1 parent 6613872 commit 4ce135a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
47 changes: 45 additions & 2 deletions spec/ParseLiveQueryServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,49 @@ describe('ParseLiveQueryServer', function () {
parseLiveQueryServer._onAfterSave(message);
});

it('sends correct object for dates', async () => {
jasmine.restoreLibrary('../lib/LiveQuery/QueryTools', 'matchesQuery');

const parseLiveQueryServer = new ParseLiveQueryServer({});

const date = new Date();
const message = {
currentParseObject: {
date: { __type: 'Date', iso: date.toISOString() },
__type: 'Object',
key: 'value',
className: testClassName,
},
};
// Add mock client
const clientId = 1;
const client = addMockClient(parseLiveQueryServer, clientId);

const requestId2 = 2;

await addMockSubscription(parseLiveQueryServer, clientId, requestId2);

parseLiveQueryServer._matchesACL = function () {
return Promise.resolve(true);
};

parseLiveQueryServer._inflateParseObject(message);
parseLiveQueryServer._onAfterSave(message);

// Make sure we send leave and enter command to client
await timeout();

expect(client.pushCreate).toHaveBeenCalledWith(
requestId2,
{
className: 'TestObject',
key: 'value',
date: { __type: 'Date', iso: date.toISOString() },
},
null
);
});

it('can handle object save command which does not match any subscription', async done => {
const parseLiveQueryServer = new ParseLiveQueryServer({});
// Make mock request message
Expand Down Expand Up @@ -1138,8 +1181,7 @@ describe('ParseLiveQueryServer', function () {
expect(toSend.original).toBeUndefined();
expect(spy).toHaveBeenCalledWith({
usage: 'Subscribing using fields parameter',
solution:
`Subscribe using "keys" instead.`,
solution: `Subscribe using "keys" instead.`,
});
});

Expand Down Expand Up @@ -1945,6 +1987,7 @@ describe('ParseLiveQueryServer', function () {
} else {
subscription.clientRequestIds = new Map([[clientId, [requestId]]]);
}
subscription.query = query.where;
return subscription;
}

Expand Down
3 changes: 2 additions & 1 deletion src/LiveQuery/ParseLiveQueryServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import UserRouter from '../Routers/UsersRouter';
import DatabaseController from '../Controllers/DatabaseController';
import { isDeepStrictEqual } from 'util';
import Deprecator from '../Deprecator/Deprecator';
import deepcopy from 'deepcopy';

class ParseLiveQueryServer {
clients: Map;
Expand Down Expand Up @@ -496,7 +497,7 @@ class ParseLiveQueryServer {
if (!parseObject) {
return false;
}
return matchesQuery(parseObject, subscription.query);
return matchesQuery(deepcopy(parseObject), subscription.query);
}

async _clearCachedRoles(userId: string) {
Expand Down

0 comments on commit 4ce135a

Please sign in to comment.