added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / test / app.test.js
1 const assert = require('assert');\r
2 const rp = require('request-promise');\r
3 const url = require('url');\r
4 const app = require('../src/app');\r
5 \r
6 const port = app.get('port') || 3030;\r
7 const getUrl = pathname => url.format({\r
8         hostname: app.get('host') || 'localhost',\r
9         protocol: 'http',\r
10         port,\r
11         pathname\r
12 });\r
13 \r
14 describe('Feathers application tests', () => {\r
15         before(function (done) {\r
16                 this.server = app.listen(port);\r
17                 this.server.once('listening', () => done());\r
18         });\r
19 \r
20         after(function (done) {\r
21                 this.server.close(done);\r
22         });\r
23 \r
24         it('starts and shows the index page', () => {\r
25                 return rp(getUrl()).then(body =>\r
26                         assert.ok(body.indexOf('<html>') !== -1)\r
27                 );\r
28         });\r
29 \r
30         describe('404', function () {\r
31                 it('shows a 404 HTML page', () => {\r
32                         return rp({\r
33                                 url: getUrl('path/to/nowhere'),\r
34                                 headers: {\r
35                                         'Accept': 'text/html'\r
36                                 }\r
37                         }).catch(res => {\r
38                                 assert.strictEqual(res.statusCode, 404);\r
39                                 assert.ok(res.error.indexOf('<html>') !== -1);\r
40                         });\r
41                 });\r
42 \r
43                 it('shows a 404 JSON error without stack trace', () => {\r
44                         return rp({\r
45                                 url: getUrl('path/to/nowhere'),\r
46                                 json: true\r
47                         }).catch(res => {\r
48                                 assert.strictEqual(res.statusCode, 404);\r
49                                 assert.strictEqual(res.error.code, 404);\r
50                                 assert.strictEqual(res.error.message, 'Page not found');\r
51                                 assert.strictEqual(res.error.name, 'NotFound');\r
52                         });\r
53                 });\r
54         });\r
55 });\r