Skip to content

Commit

Permalink
wrote basic tests for express server
Browse files Browse the repository at this point in the history
checking status code on all routes is 200
relates #2
  • Loading branch information
Jen-Harris committed Aug 17, 2017
1 parent ee949d7 commit 31c759b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
10 changes: 10 additions & 0 deletions tests/endpoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = [
'/',
'/browse',
'/congratulations',
'/new-idea',
'/browse/1',
'/browse/2',
'/browse/3',
'/browse/4'
]
37 changes: 19 additions & 18 deletions tests/express-test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
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) => {
t.equals(1, 1, 'one should equal one');
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();
})
})
Expand All @@ -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<endpoints.length; i++){
test(`check if status code of ${endpoints[i]} is 200`, (t) => {
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();
})
})
}

0 comments on commit 31c759b

Please sign in to comment.