Skip to content

improve a test case (related to #6590) #6629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 24 additions & 45 deletions spec/EnableExpressErrorHandler.spec.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,33 @@
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;

const parseServer = ParseServer.ParseServer(
it('should call the default handler in case of error, like updating a non existing object', async (done) => {
const parseServer = await reconfigureServer(
Object.assign({}, defaultConfiguration, {
appId: appId,
masterKey: masterKey,
serverURL: serverUrl,
enableExpressErrorHandler: true,
serverStartComplete: () => {
expect(Parse.applicationId).toEqual('anOtherTestApp');
const app = express();
app.use('/parse', parseServer);

server = app.listen(12667);

app.use(function(err, req, res, next) {
expect(err.message).toBe('Object not found.');
next(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 => {
expect(response).toBeDefined();
expect(response.status).toEqual(500);
})
.then(() => {
server.close(done);
});
},
})
);
parseServer.app.use(function (err, req, res, next) {
expect(err.message).toBe('Object not found.');
next(err);
});

try {
await request({
method: 'PUT',
url: defaultConfiguration.serverURL + '/classes/AnyClass/nonExistingId',
headers: {
'X-Parse-Application-Id': defaultConfiguration.appId,
'X-Parse-Master-Key': defaultConfiguration.masterKey,
'Content-Type': 'application/json',
},
body: { someField: 'blablabla' },
});
fail('Should throw error');
} catch (response) {
expect(response).toBeDefined();
expect(response.status).toEqual(500);
parseServer.server.close(done);
}
});
});