Skip to content

Commit 97c3f47

Browse files
authored
Merge branch 'alpha' into event-emitter
2 parents 7a8c275 + 94e7248 commit 97c3f47

File tree

7 files changed

+101
-23
lines changed

7 files changed

+101
-23
lines changed

src/ObjectStateMutations.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ export function estimateAttributes(
150150
function nestedSet(obj, key, value) {
151151
const path = key.split('.');
152152
for (let i = 0; i < path.length - 1; i++) {
153-
if (!(path[i] in obj)) obj[path[i]] = {};
153+
if (!(path[i] in obj)) {
154+
obj[path[i]] = {};
155+
}
154156
obj = obj[path[i]];
155157
}
156158
if (typeof value === 'undefined') {

src/OfflineQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
538538
const distance = point.radiansTo(centerPoint);
539539
return distance <= maxDistance;
540540
}
541-
break;
541+
return false;
542542
}
543543
case '$geoIntersects': {
544544
const polygon = new ParsePolygon(object[key].coordinates);

src/__tests__/LiveQueryClient-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,21 @@ describe('LiveQueryClient', () => {
758758
spy.mockRestore();
759759
});
760760

761+
it('can handle WebSocket disconnect if already disconnected', async () => {
762+
const liveQueryClient = new LiveQueryClient({
763+
applicationId: 'applicationId',
764+
serverURL: 'ws://test',
765+
javascriptKey: 'javascriptKey',
766+
masterKey: 'masterKey',
767+
sessionToken: 'sessionToken',
768+
});
769+
const spy = jest.spyOn(liveQueryClient, '_handleReconnect');
770+
liveQueryClient.state = 'disconnected';
771+
liveQueryClient._handleWebSocketClose();
772+
expect(liveQueryClient._handleReconnect).toHaveBeenCalledTimes(0);
773+
spy.mockRestore();
774+
});
775+
761776
it('can subscribe', async () => {
762777
const liveQueryClient = new LiveQueryClient({
763778
applicationId: 'applicationId',
@@ -888,6 +903,31 @@ describe('LiveQueryClient', () => {
888903
expect(liveQueryClient.socket.send).toHaveBeenCalledTimes(0);
889904
});
890905

906+
it('cannot subscribe on connection error', async () => {
907+
const liveQueryClient = new LiveQueryClient({
908+
applicationId: 'applicationId',
909+
serverURL: 'ws://test',
910+
javascriptKey: 'javascriptKey',
911+
masterKey: 'masterKey',
912+
sessionToken: 'sessionToken',
913+
});
914+
liveQueryClient.socket = {
915+
send: jest.fn(),
916+
};
917+
const query = new ParseQuery('Test');
918+
query.equalTo('key', 'value');
919+
920+
const subscription = liveQueryClient.subscribe(query);
921+
liveQueryClient.connectPromise.reject(new Error('Unable to connect'));
922+
liveQueryClient.connectPromise.catch(() => {});
923+
try {
924+
await subscription.subscribePromise;
925+
expect(true).toBeFalse();
926+
} catch (e) {
927+
expect(e.message).toBe('Unable to connect');
928+
}
929+
});
930+
891931
it('can resubscribe', async () => {
892932
const liveQueryClient = new LiveQueryClient({
893933
applicationId: 'applicationId',

src/__tests__/ObjectStateMutations-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ describe('ObjectStateMutations', () => {
199199
expect(objectCache).toEqual({ data: '{"count":5}' });
200200
});
201201

202+
it('can commit nested changes from the server', () => {
203+
const serverData = {};
204+
const objectCache = {};
205+
ObjectStateMutations.commitServerChanges(serverData, objectCache, {
206+
'name.foo': 'bar',
207+
data: { count: 5 },
208+
});
209+
expect(serverData).toEqual({ name: { foo: 'bar' }, data: { count: 5 } });
210+
expect(objectCache).toEqual({ data: '{"count":5}' });
211+
});
212+
202213
it('can generate a default state for implementations', () => {
203214
expect(ObjectStateMutations.defaultState()).toEqual({
204215
serverData: {},

src/__tests__/OfflineQuery-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,33 @@ describe('OfflineQuery', () => {
848848
expect(matchesQuery(q.className, obj3, [], q)).toBe(false);
849849
});
850850

851+
it('should not support invalid $geoWithin query', () => {
852+
const sacramento = new ParseObject('Location');
853+
sacramento.set('location', new ParseGeoPoint(38.52, -121.5));
854+
sacramento.set('name', 'Sacramento');
855+
856+
const honolulu = new ParseObject('Location');
857+
honolulu.set('location', new ParseGeoPoint(21.35, -157.93));
858+
honolulu.set('name', 'Honolulu');
859+
860+
const sf = new ParseObject('Location');
861+
sf.set('location', new ParseGeoPoint(37.75, -122.68));
862+
sf.set('name', 'San Francisco');
863+
864+
const points = [
865+
new ParseGeoPoint(37.85, -122.33),
866+
new ParseGeoPoint(37.85, -122.9),
867+
new ParseGeoPoint(37.68, -122.9),
868+
new ParseGeoPoint(37.68, -122.33),
869+
];
870+
const q = new ParseQuery('Location');
871+
q._addCondition('location', '$geoWithin', { $unknown: points });
872+
873+
expect(matchesQuery(q.className, sacramento, [], q)).toBe(false);
874+
expect(matchesQuery(q.className, honolulu, [], q)).toBe(false);
875+
expect(matchesQuery(q.className, sf, [], q)).toBe(false);
876+
});
877+
851878
it('should validate query', () => {
852879
let query = new ParseQuery('TestObject');
853880
query.equalTo('foo', 'bar');

src/__tests__/ParseObject-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,13 +2302,14 @@ describe('ParseObject', () => {
23022302
});
23032303
const p = new ParseObject('Person');
23042304
p.id = 'pid';
2305-
const result = p.destroy().then(() => {
2305+
const result = p.destroy({ sessionToken: 't_1234' }).then(() => {
23062306
expect(xhr.open.mock.calls[0]).toEqual([
23072307
'POST',
23082308
'https://api.parse.com/1/classes/Person/pid',
23092309
true,
23102310
]);
23112311
expect(JSON.parse(xhr.send.mock.calls[0])._method).toBe('DELETE');
2312+
expect(JSON.parse(xhr.send.mock.calls[0])._SessionToken).toBe('t_1234');
23122313
});
23132314
jest.runAllTicks();
23142315
await flushPromises();

src/__tests__/ParseUser-test.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ describe('ParseUser', () => {
832832
});
833833
});
834834

835-
it('removes the current user from disk when destroyed', done => {
835+
it('removes the current user from disk when destroyed', async () => {
836836
ParseUser.enableUnsafeCurrentUser();
837837
ParseUser._clearCache();
838838
Storage._clear();
@@ -848,25 +848,21 @@ describe('ParseUser', () => {
848848
ajax() {},
849849
});
850850

851-
ParseUser.signUp('destroyed', 'password')
852-
.then(u => {
853-
expect(u.isCurrent()).toBe(true);
854-
CoreManager.setRESTController({
855-
request() {
856-
return Promise.resolve({}, 200);
857-
},
858-
ajax() {},
859-
});
860-
return u.destroy();
861-
})
862-
.then(() => {
863-
expect(ParseUser.current()).toBe(null);
864-
return ParseUser.currentAsync();
865-
})
866-
.then(current => {
867-
expect(current).toBe(null);
868-
done();
869-
});
851+
const u = await ParseUser.signUp('destroyed', 'password');
852+
expect(u.isCurrent()).toBe(true);
853+
CoreManager.setRESTController({
854+
request() {
855+
return Promise.resolve({}, 200);
856+
},
857+
ajax() {},
858+
});
859+
await u.destroy();
860+
861+
expect(ParseUser.current()).toBe(null);
862+
const current = await ParseUser.currentAsync();
863+
864+
expect(current).toBe(null);
865+
await u.destroy();
870866
});
871867

872868
it('updates the current user on disk when fetched', done => {
@@ -1531,6 +1527,7 @@ describe('ParseUser', () => {
15311527

15321528
user.set('authData', { customAuth: true });
15331529
expect(user._isLinked(provider)).toBe(true);
1530+
expect(user._isLinked('customAuth')).toBe(true);
15341531

15351532
user.set('authData', 1234);
15361533
expect(user._isLinked(provider)).toBe(false);

0 commit comments

Comments
 (0)