Skip to content

Commit

Permalink
Merge pull request #36 from FAC-11/express-tests
Browse files Browse the repository at this point in the history
Express tests
  • Loading branch information
rebecacalvoquintero authored Aug 17, 2017
2 parents 302a670 + 31c759b commit 9010a00
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "node ./tests/express-test.js | tap-spec",
"start:watch": "nodemon ./src/index.js"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.get = (req, res, next) => {
},
data: stuff.rows
});
console.log('this is out stuff: ', stuff);
// console.log('this is out stuff: ', stuff);
// res.rows??
})
.catch((stuff, text)=>{
Expand Down
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'
]
48 changes: 48 additions & 0 deletions tests/express-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 we get 404 on /error endpoint
test('404 on "/error" endpoint', (t) => {
supertest(app)
.get('/error')
.expect(404)
.expect('Content-Type', /json/)
.end((err, res) => {
t.same(res.statusCode, 404, 'Status code is 404');
t.end();
})
})

// check we get 404 on non-existing endpoint
test('404 when endpoint does not exist', (t) => {
supertest(app)
.get('/bsdjkhgablsg')
.expect(404)
.expect('Content-Type', /json/)
.end((err, res) => {
t.same(res.statusCode, 404, 'Status code is 404');
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 9010a00

Please sign in to comment.