feat: Deprecate LiveQuery fields option in favor of keys for semantic consistency (#8388)

This commit is contained in:
Daniel
2023-02-17 23:24:33 +11:00
committed by GitHub
parent 992b3c79f5
commit a49e323d5a
5 changed files with 110 additions and 14 deletions

View File

@@ -294,7 +294,7 @@ describe('ParseLiveQueryServer', function () {
where: {
key: 'value',
},
fields: ['test'],
keys: ['test'],
};
const requestId = 2;
const request = {
@@ -331,7 +331,7 @@ describe('ParseLiveQueryServer', function () {
where: {
key: 'value',
},
fields: ['test'],
keys: ['test'],
};
const requestId = 2;
const request = {
@@ -378,7 +378,7 @@ describe('ParseLiveQueryServer', function () {
where: {
key: 'value',
},
fields: ['test'],
keys: ['test'],
};
await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query);
// Add subscription for mock client 2
@@ -390,7 +390,7 @@ describe('ParseLiveQueryServer', function () {
where: {
key: 'value',
},
fields: ['testAgain'],
keys: ['testAgain'],
};
const requestIdAgain = 1;
await addMockSubscription(
@@ -1060,7 +1060,7 @@ describe('ParseLiveQueryServer', function () {
where: {
key: 'value',
},
fields: ['test'],
keys: ['test'],
};
await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query);
// Mock _matchesSubscription to return matching
@@ -1087,6 +1087,62 @@ describe('ParseLiveQueryServer', function () {
done();
});
it('can deprecate fields', async () => {
const Deprecator = require('../lib/Deprecator/Deprecator');
const spy = spyOn(Deprecator, 'logRuntimeDeprecation').and.callFake(() => {});
jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client');
const Client = require('../lib/LiveQuery/Client').Client;
const parseLiveQueryServer = new ParseLiveQueryServer({});
// Make mock request message
const message = generateMockMessage();
const clientId = 1;
const parseWebSocket = {
clientId,
send: jasmine.createSpy('send'),
};
const client = new Client(clientId, parseWebSocket);
spyOn(client, 'pushCreate').and.callThrough();
parseLiveQueryServer.clients.set(clientId, client);
// Add mock subscription
const requestId = 2;
const query = {
className: testClassName,
where: {
key: 'value',
},
fields: ['test'],
};
await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query);
// Mock _matchesSubscription to return matching
parseLiveQueryServer._matchesSubscription = function (parseObject) {
if (!parseObject) {
return false;
}
return true;
};
parseLiveQueryServer._matchesACL = function () {
return Promise.resolve(true);
};
parseLiveQueryServer._onAfterSave(message);
// Make sure we send create command to client
await timeout();
expect(client.pushCreate).toHaveBeenCalled();
const args = parseWebSocket.send.calls.mostRecent().args;
const toSend = JSON.parse(args[0]);
expect(toSend.object).toBeDefined();
expect(toSend.original).toBeUndefined();
expect(spy).toHaveBeenCalledWith({
usage: 'Subscribing using fields parameter',
solution:
`Subscribe using "keys" instead.`,
});
});
it('can handle create command with watch', async () => {
jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client');
const Client = require('../lib/LiveQuery/Client').Client;
@@ -1865,7 +1921,7 @@ describe('ParseLiveQueryServer', function () {
where: {
key: 'value',
},
fields: ['test'],
keys: ['test'],
};
}
const request = {