fix: LiveQuery can return incorrectly formatted date (#8456)
This commit is contained in:
@@ -754,6 +754,49 @@ describe('ParseLiveQueryServer', function () {
|
|||||||
parseLiveQueryServer._onAfterSave(message);
|
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 => {
|
it('can handle object save command which does not match any subscription', async done => {
|
||||||
const parseLiveQueryServer = new ParseLiveQueryServer({});
|
const parseLiveQueryServer = new ParseLiveQueryServer({});
|
||||||
// Make mock request message
|
// Make mock request message
|
||||||
@@ -1138,8 +1181,7 @@ describe('ParseLiveQueryServer', function () {
|
|||||||
expect(toSend.original).toBeUndefined();
|
expect(toSend.original).toBeUndefined();
|
||||||
expect(spy).toHaveBeenCalledWith({
|
expect(spy).toHaveBeenCalledWith({
|
||||||
usage: 'Subscribing using fields parameter',
|
usage: 'Subscribing using fields parameter',
|
||||||
solution:
|
solution: `Subscribe using "keys" instead.`,
|
||||||
`Subscribe using "keys" instead.`,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1945,6 +1987,7 @@ describe('ParseLiveQueryServer', function () {
|
|||||||
} else {
|
} else {
|
||||||
subscription.clientRequestIds = new Map([[clientId, [requestId]]]);
|
subscription.clientRequestIds = new Map([[clientId, [requestId]]]);
|
||||||
}
|
}
|
||||||
|
subscription.query = query.where;
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import UserRouter from '../Routers/UsersRouter';
|
|||||||
import DatabaseController from '../Controllers/DatabaseController';
|
import DatabaseController from '../Controllers/DatabaseController';
|
||||||
import { isDeepStrictEqual } from 'util';
|
import { isDeepStrictEqual } from 'util';
|
||||||
import Deprecator from '../Deprecator/Deprecator';
|
import Deprecator from '../Deprecator/Deprecator';
|
||||||
|
import deepcopy from 'deepcopy';
|
||||||
|
|
||||||
class ParseLiveQueryServer {
|
class ParseLiveQueryServer {
|
||||||
clients: Map;
|
clients: Map;
|
||||||
@@ -496,7 +497,7 @@ class ParseLiveQueryServer {
|
|||||||
if (!parseObject) {
|
if (!parseObject) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return matchesQuery(parseObject, subscription.query);
|
return matchesQuery(deepcopy(parseObject), subscription.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _clearCachedRoles(userId: string) {
|
async _clearCachedRoles(userId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user