Files
kami-parse-server/spec/EnableExpressErrorHandler.spec.js
Florent Vilmart 045d941aef Remove request and request-promise from dev dependencies (#5077)
* removes from emailverificationtoken spec

* updates winston

* Updates ValidationAndPasswordsReset

* Use local request in schemas

* Removes request in rest.spec

* Removes request from PushRouter0

* removes request from public API

* removes request from index.spec

* Removes request form parse.push spec

* removes request from ParseInstallation spec

* Removes from ParseHooks

* removes request from ParseGlobalConfig.spec

* Removes request from ParseAPI.spec.js

* removes request from LogsRouter

* removes in features

* Filters undefined headers instead of crashing

* Removes request from ParseUser spec

* Removes usage of request in ParseFile.spec.js

* Removes request from AuthAdapters.js

* removes request-promise from ParseGeoPoint.spec

* Removes request-promise from ParseQuery spec

* remove request-promise from UserPII

* removes request-promise from EnableExpressErrorHandler

* Updates RevocableSessionUpgrade spec

* Update RestQuery

* Removes read preferenceOptionM

* ensure we forward auth from URL

* use request in CloudCode.spec.js

* Removes request-promise from JobSchedule.spec

* Removes rp from VerifyUserPassword.spec.js

* Removes rp from PasswordPolicy spec

* Removes rp from ParsePolygon spec

* Removes rp from fullTextSearch spec

* Removes rp from PArseQuery.Aggregate

* Ensure we properly forward errors

* Removes request and request-promise
2018-09-24 17:07:51 -04:00

66 lines
2.1 KiB
JavaScript

const ParseServer = require('../lib/index');
const express = require('express');
const request = require('../lib/request');
describe('Enable express error handler', () => {
it('should call the default handler in case of error, like updating a non existing object', done => {
const serverUrl = 'http://localhost:12667/parse';
const appId = 'anOtherTestApp';
const masterKey = 'anOtherTestMasterKey';
let server;
let lastError;
const parseServer = ParseServer.ParseServer(
Object.assign({}, defaultConfiguration, {
appId: appId,
masterKey: masterKey,
serverURL: serverUrl,
enableExpressErrorHandler: true,
__indexBuildCompletionCallbackForTests: promise => {
promise.then(() => {
expect(Parse.applicationId).toEqual('anOtherTestApp');
const app = express();
app.use('/parse', parseServer);
server = app.listen(12667);
app.use(function(err, req, res, next) {
next;
lastError = err;
});
request({
method: 'PUT',
url: serverUrl + '/classes/AnyClass/nonExistingId',
headers: {
'X-Parse-Application-Id': appId,
'X-Parse-Master-Key': masterKey,
'Content-Type': 'application/json',
},
body: { someField: 'blablabla' },
})
.then(() => {
fail('Should throw error');
})
.catch(response => {
const reqError = response.data;
expect(reqError).toBeDefined();
expect(lastError).toBeDefined();
expect(lastError.code).toEqual(101);
expect(lastError.message).toEqual('Object not found.');
expect(lastError.code).toEqual(reqError.code);
expect(lastError.message).toEqual(reqError.error);
})
.then(() => {
server.close(done);
});
});
},
})
);
});
});