From 31c759b8aa0e715009e08d6ff63c657c88f11188 Mon Sep 17 00:00:00 2001 From: jen-harris Date: Thu, 17 Aug 2017 15:17:31 +0100 Subject: [PATCH] wrote basic tests for express server checking status code on all routes is 200 relates #2 --- tests/endpoints.js | 10 ++++++++++ tests/express-test.js | 37 +++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 tests/endpoints.js diff --git a/tests/endpoints.js b/tests/endpoints.js new file mode 100644 index 0000000..70af0e4 --- /dev/null +++ b/tests/endpoints.js @@ -0,0 +1,10 @@ +module.exports = [ +'/', +'/browse', +'/congratulations', +'/new-idea', +'/browse/1', +'/browse/2', +'/browse/3', +'/browse/4' +] diff --git a/tests/express-test.js b/tests/express-test.js index ccdb893..cbce079 100644 --- a/tests/express-test.js +++ b/tests/express-test.js @@ -1,6 +1,7 @@ const test = require('tape'); const supertest = require('supertest'); const app = require('./../src/app'); +const endpoints = require('./endpoints'); // check if tape works test('1 equals 1', (t) => { @@ -8,14 +9,14 @@ test('1 equals 1', (t) => { t.end(); }); -// check if supetest works -test('check if supertest works', (t) => { +// check we get 404 on /error endpoint +test('404 on "/error" endpoint', (t) => { supertest(app) - .get('/') - .expect(200) + .get('/error') + .expect(404) .expect('Content-Type', /json/) .end((err, res) => { - t.same(res.statusCode, 200, 'Status code is 200'); + t.same(res.statusCode, 404, 'Status code is 404'); t.end(); }) }) @@ -32,16 +33,16 @@ test('404 when endpoint does not exist', (t) => { }) }) -test('check prepopulated browse database table', (t) => { - supertest(app) - .get('/browse') - .expect(200) - .expect('Content-Type', /json/) - .end((err, res) => { - let expected = "Movie recommendation app"; - let actual = res; - console.log('res.rows ', res); - t.equals(actual, expected, 'Should be Movie recommendation app') - t.end(); - }) -}) +// looping through endpoints to check statusCode 200 +for(let i=0; i { + supertest(app) + .get(endpoints[i]) + .expect(200) + .expect('Content-Type', /json/) + .end((err, res) => { + t.same(res.statusCode, 200, `Status code of ${endpoints[i]} is 200`); + t.end(); + }) + }) +}