Skip to content

Commit 4ce135a

Browse files
authored
fix: LiveQuery can return incorrectly formatted date (#8456)
1 parent 6613872 commit 4ce135a

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

spec/ParseLiveQueryServer.spec.js

+45-2
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,49 @@ describe('ParseLiveQueryServer', function () {
754754
parseLiveQueryServer._onAfterSave(message);
755755
});
756756

757+
it('sends correct object for dates', async () => {
758+
jasmine.restoreLibrary('../lib/LiveQuery/QueryTools', 'matchesQuery');
759+
760+
const parseLiveQueryServer = new ParseLiveQueryServer({});
761+
762+
const date = new Date();
763+
const message = {
764+
currentParseObject: {
765+
date: { __type: 'Date', iso: date.toISOString() },
766+
__type: 'Object',
767+
key: 'value',
768+
className: testClassName,
769+
},
770+
};
771+
// Add mock client
772+
const clientId = 1;
773+
const client = addMockClient(parseLiveQueryServer, clientId);
774+
775+
const requestId2 = 2;
776+
777+
await addMockSubscription(parseLiveQueryServer, clientId, requestId2);
778+
779+
parseLiveQueryServer._matchesACL = function () {
780+
return Promise.resolve(true);
781+
};
782+
783+
parseLiveQueryServer._inflateParseObject(message);
784+
parseLiveQueryServer._onAfterSave(message);
785+
786+
// Make sure we send leave and enter command to client
787+
await timeout();
788+
789+
expect(client.pushCreate).toHaveBeenCalledWith(
790+
requestId2,
791+
{
792+
className: 'TestObject',
793+
key: 'value',
794+
date: { __type: 'Date', iso: date.toISOString() },
795+
},
796+
null
797+
);
798+
});
799+
757800
it('can handle object save command which does not match any subscription', async done => {
758801
const parseLiveQueryServer = new ParseLiveQueryServer({});
759802
// Make mock request message
@@ -1138,8 +1181,7 @@ describe('ParseLiveQueryServer', function () {
11381181
expect(toSend.original).toBeUndefined();
11391182
expect(spy).toHaveBeenCalledWith({
11401183
usage: 'Subscribing using fields parameter',
1141-
solution:
1142-
`Subscribe using "keys" instead.`,
1184+
solution: `Subscribe using "keys" instead.`,
11431185
});
11441186
});
11451187

@@ -1945,6 +1987,7 @@ describe('ParseLiveQueryServer', function () {
19451987
} else {
19461988
subscription.clientRequestIds = new Map([[clientId, [requestId]]]);
19471989
}
1990+
subscription.query = query.where;
19481991
return subscription;
19491992
}
19501993

src/LiveQuery/ParseLiveQueryServer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import UserRouter from '../Routers/UsersRouter';
2424
import DatabaseController from '../Controllers/DatabaseController';
2525
import { isDeepStrictEqual } from 'util';
2626
import Deprecator from '../Deprecator/Deprecator';
27+
import deepcopy from 'deepcopy';
2728

2829
class ParseLiveQueryServer {
2930
clients: Map;
@@ -496,7 +497,7 @@ class ParseLiveQueryServer {
496497
if (!parseObject) {
497498
return false;
498499
}
499-
return matchesQuery(parseObject, subscription.query);
500+
return matchesQuery(deepcopy(parseObject), subscription.query);
500501
}
501502

502503
async _clearCachedRoles(userId: string) {

0 commit comments

Comments
 (0)