Skip to content

Commit ea29542

Browse files
author
Gordon Sun
committed
improve a test case
1. do not need to create a new server, use the reconfigureServer tool 3. use async await
1 parent 7ccd6ce commit ea29542

File tree

1 file changed

+24
-45
lines changed

1 file changed

+24
-45
lines changed
Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,33 @@
1-
const ParseServer = require('../lib/index');
2-
const express = require('express');
31
const request = require('../lib/request');
42

53
describe('Enable express error handler', () => {
6-
it('should call the default handler in case of error, like updating a non existing object', done => {
7-
const serverUrl = 'http://localhost:12667/parse';
8-
const appId = 'anOtherTestApp';
9-
const masterKey = 'anOtherTestMasterKey';
10-
let server;
11-
12-
const parseServer = ParseServer.ParseServer(
4+
it('should call the default handler in case of error, like updating a non existing object', async (done) => {
5+
const parseServer = await reconfigureServer(
136
Object.assign({}, defaultConfiguration, {
14-
appId: appId,
15-
masterKey: masterKey,
16-
serverURL: serverUrl,
177
enableExpressErrorHandler: true,
18-
serverStartComplete: () => {
19-
expect(Parse.applicationId).toEqual('anOtherTestApp');
20-
const app = express();
21-
app.use('/parse', parseServer);
22-
23-
server = app.listen(12667);
24-
25-
app.use(function(err, req, res, next) {
26-
expect(err.message).toBe('Object not found.');
27-
next(err);
28-
});
29-
30-
request({
31-
method: 'PUT',
32-
url: serverUrl + '/classes/AnyClass/nonExistingId',
33-
headers: {
34-
'X-Parse-Application-Id': appId,
35-
'X-Parse-Master-Key': masterKey,
36-
'Content-Type': 'application/json',
37-
},
38-
body: { someField: 'blablabla' },
39-
})
40-
.then(() => {
41-
fail('Should throw error');
42-
})
43-
.catch(response => {
44-
expect(response).toBeDefined();
45-
expect(response.status).toEqual(500);
46-
})
47-
.then(() => {
48-
server.close(done);
49-
});
50-
},
518
})
529
);
10+
parseServer.app.use(function (err, req, res, next) {
11+
expect(err.message).toBe('Object not found.');
12+
next(err);
13+
});
14+
15+
try {
16+
await request({
17+
method: 'PUT',
18+
url: defaultConfiguration.serverURL + '/classes/AnyClass/nonExistingId',
19+
headers: {
20+
'X-Parse-Application-Id': defaultConfiguration.appId,
21+
'X-Parse-Master-Key': defaultConfiguration.masterKey,
22+
'Content-Type': 'application/json',
23+
},
24+
body: { someField: 'blablabla' },
25+
});
26+
fail('Should throw error');
27+
} catch (response) {
28+
expect(response).toBeDefined();
29+
expect(response.status).toEqual(500);
30+
parseServer.server.close(done);
31+
}
5332
});
5433
});

0 commit comments

Comments
 (0)