Skip to content

Commit f412d7f

Browse files
authored
Merge branch 'alpha' into session_logout
2 parents f275357 + 7a89342 commit f412d7f

27 files changed

+2383
-4129
lines changed

integration/test/IdempotencyTest.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
11
'use strict';
2+
const originalFetch = global.fetch;
23

34
const Parse = require('../../node');
45
const sleep = require('./sleep');
5-
66
const Item = Parse.Object.extend('IdempotencyItem');
7-
const RESTController = Parse.CoreManager.getRESTController();
87

9-
const XHR = RESTController._getXHR();
10-
function DuplicateXHR(requestId) {
11-
function XHRWrapper() {
12-
const xhr = new XHR();
13-
const send = xhr.send;
14-
xhr.send = function () {
15-
this.setRequestHeader('X-Parse-Request-Id', requestId);
16-
send.apply(this, arguments);
17-
};
18-
return xhr;
19-
}
20-
return XHRWrapper;
8+
function DuplicateRequestId(requestId) {
9+
global.fetch = async (...args) => {
10+
const options = args[1];
11+
options.headers['X-Parse-Request-Id'] = requestId;
12+
return originalFetch(...args);
13+
};
2114
}
2215

2316
describe('Idempotency', () => {
24-
beforeEach(() => {
25-
RESTController._setXHR(XHR);
17+
afterEach(() => {
18+
global.fetch = originalFetch;
2619
});
2720

2821
it('handle duplicate cloud code function request', async () => {
29-
RESTController._setXHR(DuplicateXHR('1234'));
22+
DuplicateRequestId('1234');
3023
await Parse.Cloud.run('CloudFunctionIdempotency');
3124
await expectAsync(Parse.Cloud.run('CloudFunctionIdempotency')).toBeRejectedWithError(
3225
'Duplicate request'
3326
);
3427
await expectAsync(Parse.Cloud.run('CloudFunctionIdempotency')).toBeRejectedWithError(
3528
'Duplicate request'
3629
);
37-
3830
const query = new Parse.Query(Item);
3931
const results = await query.find();
4032
expect(results.length).toBe(1);
4133
});
4234

4335
it('handle duplicate job request', async () => {
44-
RESTController._setXHR(DuplicateXHR('1234'));
36+
DuplicateRequestId('1234');
4537
const params = { startedBy: 'Monty Python' };
4638
const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params);
4739
await expectAsync(Parse.Cloud.startJob('CloudJob1', params)).toBeRejectedWithError(
@@ -61,12 +53,12 @@ describe('Idempotency', () => {
6153
});
6254

6355
it('handle duplicate POST / PUT request', async () => {
64-
RESTController._setXHR(DuplicateXHR('1234'));
56+
DuplicateRequestId('1234');
6557
const testObject = new Parse.Object('IdempotentTest');
6658
await testObject.save();
6759
await expectAsync(testObject.save()).toBeRejectedWithError('Duplicate request');
6860

69-
RESTController._setXHR(DuplicateXHR('5678'));
61+
DuplicateRequestId('5678');
7062
testObject.set('foo', 'bar');
7163
await testObject.save();
7264
await expectAsync(testObject.save()).toBeRejectedWithError('Duplicate request');

integration/test/ParseDistTest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ for (const fileName of ['parse.js', 'parse.min.js']) {
2222
});
2323

2424
it('can save an object', async () => {
25-
const response = await page.evaluate(async () => {
25+
const objectId = await page.evaluate(async () => {
2626
const object = await new Parse.Object('TestObject').save();
2727
return object.id;
2828
});
29-
expect(response).toBeDefined();
30-
const obj = await new Parse.Query('TestObject').first();
29+
expect(objectId).toBeDefined();
30+
const obj = await new Parse.Query('TestObject').get(objectId);
3131
expect(obj).toBeDefined();
32-
expect(obj.id).toEqual(response);
32+
expect(obj.id).toEqual(objectId);
3333
});
3434

3535
it('can query an object', async () => {

integration/test/ParseFileTest.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ describe('Parse.File', () => {
4343
file.cancel();
4444
});
4545

46+
it('can get file upload / download progress', async () => {
47+
const file = new Parse.File('parse-js-test-file', [61, 170, 236, 120]);
48+
let progress = 0;
49+
await file.save({
50+
progress: (value, loaded, total) => {
51+
progress = value;
52+
expect(loaded).toBeDefined();
53+
expect(total).toBeDefined();
54+
},
55+
});
56+
expect(progress).toBe(1);
57+
progress = 0;
58+
file._data = null;
59+
await file.getData({
60+
progress: (value, loaded, total) => {
61+
progress = value;
62+
expect(loaded).toBeDefined();
63+
expect(total).toBeDefined();
64+
},
65+
});
66+
expect(progress).toBe(1);
67+
});
68+
4669
it('can not get data from unsaved file', async () => {
4770
const file = new Parse.File('parse-server-logo', [61, 170, 236, 120]);
4871
file._data = null;

integration/test/ParseLocalDatastoreTest.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ function runTest(controller) {
3838
Parse.initialize('integration');
3939
Parse.CoreManager.set('SERVER_URL', serverURL);
4040
Parse.CoreManager.set('MASTER_KEY', 'notsosecret');
41-
const RESTController = Parse.CoreManager.getRESTController();
42-
RESTController._setXHR(require('xmlhttprequest').XMLHttpRequest);
4341
Parse.enableLocalDatastore();
4442
});
4543

@@ -1082,8 +1080,6 @@ function runTest(controller) {
10821080
Parse.initialize('integration');
10831081
Parse.CoreManager.set('SERVER_URL', serverURL);
10841082
Parse.CoreManager.set('MASTER_KEY', 'notsosecret');
1085-
const RESTController = Parse.CoreManager.getRESTController();
1086-
RESTController._setXHR(require('xmlhttprequest').XMLHttpRequest);
10871083
Parse.enableLocalDatastore();
10881084

10891085
const numbers = [];

integration/test/ParseReactNativeTest.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const LocalDatastoreController =
88
const StorageController = require('../../lib/react-native/StorageController.default').default;
99
const RESTController = require('../../lib/react-native/RESTController').default;
1010

11-
RESTController._setXHR(require('xmlhttprequest').XMLHttpRequest);
12-
1311
describe('Parse React Native', () => {
1412
beforeEach(() => {
1513
// Set up missing controllers and configurations

0 commit comments

Comments
 (0)