added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / test / app.test.js
diff --git a/otf-frontend/server/test/app.test.js b/otf-frontend/server/test/app.test.js
new file mode 100644 (file)
index 0000000..67338c3
--- /dev/null
@@ -0,0 +1,55 @@
+const assert = require('assert');\r
+const rp = require('request-promise');\r
+const url = require('url');\r
+const app = require('../src/app');\r
+\r
+const port = app.get('port') || 3030;\r
+const getUrl = pathname => url.format({\r
+       hostname: app.get('host') || 'localhost',\r
+       protocol: 'http',\r
+       port,\r
+       pathname\r
+});\r
+\r
+describe('Feathers application tests', () => {\r
+       before(function (done) {\r
+               this.server = app.listen(port);\r
+               this.server.once('listening', () => done());\r
+       });\r
+\r
+       after(function (done) {\r
+               this.server.close(done);\r
+       });\r
+\r
+       it('starts and shows the index page', () => {\r
+               return rp(getUrl()).then(body =>\r
+                       assert.ok(body.indexOf('<html>') !== -1)\r
+               );\r
+       });\r
+\r
+       describe('404', function () {\r
+               it('shows a 404 HTML page', () => {\r
+                       return rp({\r
+                               url: getUrl('path/to/nowhere'),\r
+                               headers: {\r
+                                       'Accept': 'text/html'\r
+                               }\r
+                       }).catch(res => {\r
+                               assert.strictEqual(res.statusCode, 404);\r
+                               assert.ok(res.error.indexOf('<html>') !== -1);\r
+                       });\r
+               });\r
+\r
+               it('shows a 404 JSON error without stack trace', () => {\r
+                       return rp({\r
+                               url: getUrl('path/to/nowhere'),\r
+                               json: true\r
+                       }).catch(res => {\r
+                               assert.strictEqual(res.statusCode, 404);\r
+                               assert.strictEqual(res.error.code, 404);\r
+                               assert.strictEqual(res.error.message, 'Page not found');\r
+                               assert.strictEqual(res.error.name, 'NotFound');\r
+                       });\r
+               });\r
+       });\r
+});\r