Skip to content

Commit

Permalink
[Feature #159068410] Add /GET entries endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
olusoladavid committed Jul 19, 2018
1 parent a5f41df commit d983b34
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions server/controllers/getAllEntries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import entries from '../db/entries';

const getAllEntries = (req, res) => {
res.status(200).json(entries);
};

export default getAllEntries;
9 changes: 6 additions & 3 deletions server/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import express from 'express';
// import Entry from '../models/entry';
import getAllEntries from '../controllers/getAllEntries';

const router = express.Router();

/* GET home page. */
/* GET API base */
router.get('/', (req, res) => {
res.json({ Hello: 'World' });
res.json({ MyDiary: 'API v1' });
});

/* GET all user entries */
router.get('/entries', getAllEntries);

export default router;
20 changes: 17 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// import http from 'http';
// import assert from 'assert';
import chai from 'chai';
import chaiHttp from 'chai-http';
import app from '../server/index';
import entries from '../server/db/entries';

const { expect } = chai;
chai.use(chaiHttp);

describe('API base', () => {

describe('/GET API base', () => {
it('should return 200', (done) => {
chai
.request(app)
Expand All @@ -18,3 +18,17 @@ describe('API base', () => {
});
});
});

describe('/GET entry', () => {
it('it should GET all entries', (done) => {
chai
.request(app)
.get('/api/v1/entries')
.end((err, res) => {
expect(res).to.have.status(200);
expect(res.body).to.be.an('array');
expect(res.body.length).to.be.eql(entries.length);
done();
});
});
});

0 comments on commit d983b34

Please sign in to comment.