-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support Idempotency * fix tests * Improve coverage * Handle network retry * More Tests * Clean up
- Loading branch information
Showing
12 changed files
with
569 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
const clear = require('./clear'); | ||
const Parse = require('../../node'); | ||
|
||
const Item = Parse.Object.extend('IdempotencyItem'); | ||
const RESTController = Parse.CoreManager.getRESTController(); | ||
|
||
const XHR = RESTController._getXHR(); | ||
function DuplicateXHR(requestId) { | ||
function XHRWrapper() { | ||
const xhr = new XHR(); | ||
const send = xhr.send; | ||
xhr.send = function () { | ||
this.setRequestHeader('X-Parse-Request-Id', requestId); | ||
send.apply(this, arguments); | ||
} | ||
return xhr; | ||
} | ||
return XHRWrapper; | ||
} | ||
|
||
describe('Idempotency', () => { | ||
beforeEach((done) => { | ||
Parse.initialize('integration', null, 'notsosecret'); | ||
Parse.CoreManager.set('SERVER_URL', 'http://localhost:1337/parse'); | ||
Parse.Storage._clear(); | ||
RESTController._setXHR(XHR); | ||
clear().then(() => { | ||
done(); | ||
}); | ||
}); | ||
|
||
it('handle duplicate cloud code function request', async () => { | ||
RESTController._setXHR(DuplicateXHR('1234')); | ||
await Parse.Cloud.run('CloudFunctionIdempotency'); | ||
await expectAsync(Parse.Cloud.run('CloudFunctionIdempotency')).toBeRejectedWithError('Duplicate request'); | ||
await expectAsync(Parse.Cloud.run('CloudFunctionIdempotency')).toBeRejectedWithError('Duplicate request'); | ||
|
||
const query = new Parse.Query(Item); | ||
const results = await query.find(); | ||
expect(results.length).toBe(1); | ||
}); | ||
|
||
it('handle duplicate job request', async () => { | ||
RESTController._setXHR(DuplicateXHR('1234')); | ||
const params = { startedBy: 'Monty Python' }; | ||
const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params); | ||
await expectAsync(Parse.Cloud.startJob('CloudJob1', params)).toBeRejectedWithError('Duplicate request'); | ||
|
||
const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId); | ||
expect(jobStatus.get('status')).toBe('succeeded'); | ||
expect(jobStatus.get('params').startedBy).toBe('Monty Python'); | ||
}); | ||
|
||
it('handle duplicate POST / PUT request', async () => { | ||
RESTController._setXHR(DuplicateXHR('1234')); | ||
const testObject = new Parse.Object('IdempotentTest'); | ||
await testObject.save(); | ||
await expectAsync(testObject.save()).toBeRejectedWithError('Duplicate request'); | ||
|
||
RESTController._setXHR(DuplicateXHR('5678')); | ||
testObject.set('foo', 'bar'); | ||
await testObject.save(); | ||
await expectAsync(testObject.save()).toBeRejectedWithError('Duplicate request'); | ||
|
||
const query = new Parse.Query('IdempotentTest'); | ||
const results = await query.find(); | ||
expect(results.length).toBe(1); | ||
expect(results[0].get('foo')).toBe('bar'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
const Parse = require('../../node'); | ||
|
||
module.exports = function() { | ||
return Parse._ajax('GET', 'http://localhost:1337/clear', ''); | ||
/** | ||
* Destroys all data in the database | ||
* Calls /clear route in integration/test/server.js | ||
* | ||
* @param {boolean} fast set to true if it's ok to just drop objects and not indexes. | ||
*/ | ||
module.exports = function(fast = true) { | ||
return Parse._ajax('GET', `http://localhost:1337/clear/${fast}`, ''); | ||
}; |
Oops, something went wrong.