|
1 |
| -const ParseServer = require('../lib/index'); |
2 |
| -const express = require('express'); |
3 | 1 | const request = require('../lib/request');
|
4 | 2 |
|
5 | 3 | 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( |
13 | 6 | Object.assign({}, defaultConfiguration, {
|
14 |
| - appId: appId, |
15 |
| - masterKey: masterKey, |
16 |
| - serverURL: serverUrl, |
17 | 7 | 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 |
| - }, |
51 | 8 | })
|
52 | 9 | );
|
| 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 | + } |
53 | 32 | });
|
54 | 33 | });
|
0 commit comments