Skip to content

Commit

Permalink
feat(api): create default api rout
Browse files Browse the repository at this point in the history
- write tests for GET /api/v1/
- write code to make tests pass

[Finishes #160296446]
  • Loading branch information
akhilome committed Sep 6, 2018
1 parent eaf02a4 commit 7810ff2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';
import router from './routes/routes';

const app = express();

Expand All @@ -8,6 +9,8 @@ app.get('/', (req, res) => {
});
});

app.use('/api/v1', router);

app.listen(3000);

export default app;
11 changes: 11 additions & 0 deletions server/routes/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import express from 'express';

const router = express.Router();

router.get('/', (req, res) => {
res.status(200).json({
message: 'Welcome to the fast food fast API!',
});
});

export default router;
28 changes: 28 additions & 0 deletions tests/routes/routes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import chai from 'chai';
import 'chai/register-should';
import dirtyChai from 'dirty-chai';
import chaiHttp from 'chai-http';
import app from '../../server/index';

chai.use(chaiHttp);
chai.use(dirtyChai);

describe('GET /api/v1/', () => {
it('should respond with a 200 status code', (done) => {
chai.request(app)
.get('/api/v1')
.end((err, res) => {
res.should.have.a.status(200);
done();
});
});

it('should return an object with a message property', (done) => {
chai.request(app)
.get('/api/v1')
.end((err, res) => {
res.body.should.be.an('object').that.has.a.property('message').which.is.not.empty();
done();
});
});
});

0 comments on commit 7810ff2

Please sign in to comment.