X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=it%2Fotf.git;a=blobdiff_plain;f=otf-frontend%2Fserver%2Ftest%2Fapp.test.js;fp=otf-frontend%2Fserver%2Ftest%2Fapp.test.js;h=67338c31180596a14e7a302e2b6379ca8c5be3b1;hp=0000000000000000000000000000000000000000;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b diff --git a/otf-frontend/server/test/app.test.js b/otf-frontend/server/test/app.test.js new file mode 100644 index 0000000..67338c3 --- /dev/null +++ b/otf-frontend/server/test/app.test.js @@ -0,0 +1,55 @@ +const assert = require('assert'); +const rp = require('request-promise'); +const url = require('url'); +const app = require('../src/app'); + +const port = app.get('port') || 3030; +const getUrl = pathname => url.format({ + hostname: app.get('host') || 'localhost', + protocol: 'http', + port, + pathname +}); + +describe('Feathers application tests', () => { + before(function (done) { + this.server = app.listen(port); + this.server.once('listening', () => done()); + }); + + after(function (done) { + this.server.close(done); + }); + + it('starts and shows the index page', () => { + return rp(getUrl()).then(body => + assert.ok(body.indexOf('') !== -1) + ); + }); + + describe('404', function () { + it('shows a 404 HTML page', () => { + return rp({ + url: getUrl('path/to/nowhere'), + headers: { + 'Accept': 'text/html' + } + }).catch(res => { + assert.strictEqual(res.statusCode, 404); + assert.ok(res.error.indexOf('') !== -1); + }); + }); + + it('shows a 404 JSON error without stack trace', () => { + return rp({ + url: getUrl('path/to/nowhere'), + json: true + }).catch(res => { + assert.strictEqual(res.statusCode, 404); + assert.strictEqual(res.error.code, 404); + assert.strictEqual(res.error.message, 'Page not found'); + assert.strictEqual(res.error.name, 'NotFound'); + }); + }); + }); +});