Skip to content

Commit 5b17a33

Browse files
committed
fix: LiveQuery can return incorrectly formatted Dates
1 parent 656bca6 commit 5b17a33

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

spec/ParseLiveQueryServer.spec.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,58 @@ describe('ParseLiveQueryServer', function () {
754754
parseLiveQueryServer._onAfterSave(message);
755755
});
756756

757+
fit('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._matchesSubscription = function (parseObject, subscription) {
780+
if (!parseObject) {
781+
return false;
782+
}
783+
subscription.query.date = { $exists: true };
784+
const matchesQuery = require('../lib/LiveQuery/QueryTools').matchesQuery;
785+
matchesQuery(parseObject, subscription.query);
786+
return true;
787+
};
788+
parseLiveQueryServer._matchesACL = function () {
789+
return Promise.resolve(true);
790+
};
791+
792+
parseLiveQueryServer._inflateParseObject(message);
793+
parseLiveQueryServer._onAfterSave(message);
794+
795+
// Make sure we send leave and enter command to client
796+
await timeout();
797+
798+
expect(client.pushCreate).toHaveBeenCalledWith(
799+
requestId2,
800+
{
801+
className: 'TestObject',
802+
key: 'value',
803+
date: { __type: 'Date', iso: date.toISOString() },
804+
},
805+
null
806+
);
807+
});
808+
757809
it('can handle object save command which does not match any subscription', async done => {
758810
const parseLiveQueryServer = new ParseLiveQueryServer({});
759811
// Make mock request message
@@ -1138,8 +1190,7 @@ describe('ParseLiveQueryServer', function () {
11381190
expect(toSend.original).toBeUndefined();
11391191
expect(spy).toHaveBeenCalledWith({
11401192
usage: 'Subscribing using fields parameter',
1141-
solution:
1142-
`Subscribe using "keys" instead.`,
1193+
solution: `Subscribe using "keys" instead.`,
11431194
});
11441195
});
11451196

@@ -1945,6 +1996,7 @@ describe('ParseLiveQueryServer', function () {
19451996
} else {
19461997
subscription.clientRequestIds = new Map([[clientId, [requestId]]]);
19471998
}
1999+
subscription.query = query.where;
19482000
return subscription;
19492001
}
19502002

0 commit comments

Comments
 (0)