Skip to content

Commit 5e121e4

Browse files
committed
Merge branch 'master' into allow-custom-id
2 parents 3fd7e3c + 801dcd6 commit 5e121e4

9 files changed

+70
-41
lines changed

integration/test/ParseObjectTest.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,6 @@ describe('Parse Object', () => {
414414
assert.equal(result.get('objectField').unknown, 20);
415415
});
416416

417-
it('ignore set nested fields on new object', async () => {
418-
const obj = new TestObject();
419-
obj.set('objectField.number', 5);
420-
assert.deepEqual(obj._getPendingOps()[0], {});
421-
assert.equal(obj.get('objectField'), undefined);
422-
423-
await obj.save();
424-
assert.equal(obj.get('objectField'), undefined);
425-
});
426-
427417
it('can set nested fields two levels', async () => {
428418
const obj = new TestObject({ objectField: { foo: { bar: 5 } } });
429419
assert.equal(obj.get('objectField').foo.bar, 5);

integration/test/ParseQueryTest.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ describe('Parse Query', () => {
11581158
});
11591159
});
11601160

1161-
it('can test case insensitive regex', done => {
1161+
it('can test case insensitive matches', done => {
11621162
const obj = new TestObject();
11631163
obj.set('myString', 'hockey');
11641164
obj
@@ -1175,6 +1175,32 @@ describe('Parse Query', () => {
11751175
});
11761176
});
11771177

1178+
it('can test case insensitive startsWith', async () => {
1179+
const obj = new TestObject();
1180+
obj.set('myString', 'basketball');
1181+
await obj.save();
1182+
1183+
const query = new Parse.Query(TestObject);
1184+
query.startsWith('myString', 'baSKet', 'i');
1185+
const results = await query.find();
1186+
1187+
assert.strictEqual(results.length, 1);
1188+
assert.strictEqual(results[0].get('myString'), 'basketball');
1189+
});
1190+
1191+
it('can test case insensitive endsWith', async () => {
1192+
const obj = new TestObject();
1193+
obj.set('myString', 'basketball');
1194+
await obj.save();
1195+
1196+
const query = new Parse.Query(TestObject);
1197+
query.endsWith('myString', 'tBAll', 'i');
1198+
const results = await query.find();
1199+
1200+
assert.strictEqual(results.length, 1);
1201+
assert.strictEqual(results[0].get('myString'), 'basketball');
1202+
});
1203+
11781204
it('fails for invalid regex options', done => {
11791205
const query = new Parse.Query(TestObject);
11801206
query.matches('myString', 'football', 'some invalid thing');

src/EventuallyQueue.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,14 @@ const EventuallyQueue = {
308308
}
309309
polling = setInterval(() => {
310310
const RESTController = CoreManager.getRESTController();
311-
RESTController.ajax('GET', CoreManager.get('SERVER_URL')).catch(error => {
312-
if (error !== 'Unable to connect to the Parse API') {
313-
this.stopPoll();
314-
return this.sendQueue();
315-
}
316-
});
311+
RESTController.request('GET', 'health')
312+
.then(({ status }) => {
313+
if (status === 'ok') {
314+
this.stopPoll();
315+
return this.sendQueue();
316+
}
317+
})
318+
.catch(e => e);
317319
}, ms);
318320
},
319321

src/Parse.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ const Parse = {
8080
CoreManager.setLocalDatastoreController(controller);
8181
},
8282

83+
/**
84+
* Returns information regarding the current server's health
85+
*
86+
* @returns {Promise}
87+
* @static
88+
*/
89+
getServerHealth() {
90+
return CoreManager.getRESTController().request('GET', 'health');
91+
},
92+
8393
/**
8494
* @member {string} Parse.applicationId
8595
* @static

src/ParseObject.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -750,15 +750,6 @@ class ParseObject {
750750

751751
const currentAttributes = this.attributes;
752752

753-
// Only set nested fields if exists
754-
const serverData = this._getServerData();
755-
if (typeof key === 'string' && key.includes('.')) {
756-
const field = key.split('.')[0];
757-
if (!serverData[field]) {
758-
return this;
759-
}
760-
}
761-
762753
// Calculate new values
763754
const newValues = {};
764755
for (const attr in newOps) {

src/ParseQuery.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,13 +1573,14 @@ class ParseQuery {
15731573
*
15741574
* @param {string} key The key that the string to match is stored in.
15751575
* @param {string} prefix The substring that the value must start with.
1576+
* @param {string} modifiers The regular expression mode.
15761577
* @returns {Parse.Query} Returns the query, so you can chain this call.
15771578
*/
1578-
startsWith(key: string, prefix: string): ParseQuery {
1579+
startsWith(key: string, prefix: string, modifiers: string): ParseQuery {
15791580
if (typeof prefix !== 'string') {
15801581
throw new Error('The value being searched for must be a string.');
15811582
}
1582-
return this._addCondition(key, '$regex', this._regexStartWith(prefix));
1583+
return this.matches(key, this._regexStartWith(prefix), modifiers);
15831584
}
15841585

15851586
/**
@@ -1588,13 +1589,14 @@ class ParseQuery {
15881589
*
15891590
* @param {string} key The key that the string to match is stored in.
15901591
* @param {string} suffix The substring that the value must end with.
1592+
* @param {string} modifiers The regular expression mode.
15911593
* @returns {Parse.Query} Returns the query, so you can chain this call.
15921594
*/
1593-
endsWith(key: string, suffix: string): ParseQuery {
1595+
endsWith(key: string, suffix: string, modifiers: string): ParseQuery {
15941596
if (typeof suffix !== 'string') {
15951597
throw new Error('The value being searched for must be a string.');
15961598
}
1597-
return this._addCondition(key, '$regex', quote(suffix) + '$');
1599+
return this.matches(key, quote(suffix) + '$', modifiers);
15981600
}
15991601

16001602
/**

src/__tests__/EventuallyQueue-test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ const RESTController = require('../RESTController');
5252
const Storage = require('../Storage');
5353
const mockXHR = require('./test_helpers/mockXHR');
5454

55+
CoreManager.setInstallationController({
56+
currentInstallationId() {
57+
return Promise.resolve('iid');
58+
},
59+
});
60+
5561
function flushPromises() {
5662
return new Promise(resolve => setImmediate(resolve));
5763
}
@@ -400,7 +406,7 @@ describe('EventuallyQueue', () => {
400406

401407
it('can poll server', async () => {
402408
jest.spyOn(EventuallyQueue, 'sendQueue').mockImplementationOnce(() => {});
403-
RESTController._setXHR(mockXHR([{ status: 107, response: { error: 'ok' } }]));
409+
RESTController._setXHR(mockXHR([{ status: 200, response: { status: 'ok' } }]));
404410
EventuallyQueue.poll();
405411
expect(EventuallyQueue.isPolling()).toBe(true);
406412
jest.runOnlyPendingTimers();

src/__tests__/Parse-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ describe('Parse module', () => {
168168
Parse.allowCustomObjectId = false;
169169
});
170170

171+
it('getServerHealth', () => {
172+
const controller = {
173+
request: jest.fn(),
174+
ajax: jest.fn(),
175+
};
176+
CoreManager.setRESTController(controller);
177+
Parse.getServerHealth();
178+
const [method, path] = controller.request.mock.calls[0];
179+
expect(method).toBe('GET');
180+
expect(path).toBe('health');
181+
});
182+
171183
it('_request', () => {
172184
const controller = {
173185
request: jest.fn(),

src/__tests__/ParseObject-test.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -699,16 +699,6 @@ describe('ParseObject', () => {
699699
expect(o.get('objectField').letter).toEqual('a');
700700
});
701701

702-
it('ignore set nested field on new object', () => {
703-
const o = new ParseObject('Person');
704-
o.set('objectField.number', 20);
705-
706-
expect(o.attributes).toEqual({});
707-
expect(o.op('objectField.number') instanceof SetOp).toBe(false);
708-
expect(o.dirtyKeys()).toEqual([]);
709-
expect(o._getSaveJSON()).toEqual({});
710-
});
711-
712702
it('can add elements to an array field', () => {
713703
const o = new ParseObject('Schedule');
714704
o.add('available', 'Monday');

0 commit comments

Comments
 (0)