added updated dockerfiles and ric workflow
[it/otf.git] / otf-frontend / server / test / app.test.js
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 const assert = require('assert');\r
18 const rp = require('request-promise');\r
19 const url = require('url');\r
20 const app = require('../src/app');\r
21 \r
22 const port = app.get('port') || 3030;\r
23 const getUrl = pathname => url.format({\r
24         hostname: app.get('host') || 'localhost',\r
25         protocol: 'http',\r
26         port,\r
27         pathname\r
28 });\r
29 \r
30 describe('Feathers application tests', () => {\r
31         before(function (done) {\r
32                 this.server = app.listen(port);\r
33                 this.server.once('listening', () => done());\r
34         });\r
35 \r
36         after(function (done) {\r
37                 this.server.close(done);\r
38         });\r
39 \r
40         it('starts and shows the index page', () => {\r
41                 return rp(getUrl()).then(body =>\r
42                         assert.ok(body.indexOf('<html>') !== -1)\r
43                 );\r
44         });\r
45 \r
46         describe('404', function () {\r
47                 it('shows a 404 HTML page', () => {\r
48                         return rp({\r
49                                 url: getUrl('path/to/nowhere'),\r
50                                 headers: {\r
51                                         'Accept': 'text/html'\r
52                                 }\r
53                         }).catch(res => {\r
54                                 assert.strictEqual(res.statusCode, 404);\r
55                                 assert.ok(res.error.indexOf('<html>') !== -1);\r
56                         });\r
57                 });\r
58 \r
59                 it('shows a 404 JSON error without stack trace', () => {\r
60                         return rp({\r
61                                 url: getUrl('path/to/nowhere'),\r
62                                 json: true\r
63                         }).catch(res => {\r
64                                 assert.strictEqual(res.statusCode, 404);\r
65                                 assert.strictEqual(res.error.code, 404);\r
66                                 assert.strictEqual(res.error.message, 'Page not found');\r
67                                 assert.strictEqual(res.error.name, 'NotFound');\r
68                         });\r
69                 });\r
70         });\r
71 });\r