Skip to content

Commit

Permalink
feat(get-menu): write tests for endpoint to get menu
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilome committed Oct 1, 2018
1 parent db6d56a commit d349203
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/routes/menu.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import chai from 'chai';
import 'chai/register-should';
import chaiHttp from 'chai-http';
import dirtyChai from 'dirty-chai';

import app from '../../server/index';
import {
seedData,
emptyTablesPromise,
populateUsersTablePromise,
populateMenuTablePromise,
generateValidToken,
} from '../seed/seed';

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

before(async () => {
await emptyTablesPromise;
await populateMenuTablePromise;
await populateUsersTablePromise;
});

describe('GET /menu', () => {
const { validUser } = seedData.users;

it('should get menu successfully if user is logged in', (done) => {
chai.request(app)
.get('/api/v1/menu')
.set('x-auth', generateValidToken(validUser))
.end((err, res) => {
if (err) done(err);

res.status.should.eql(200);
res.body.message.should.eql('menu fetched successfully');
res.body.menu.should.be.an('array');
done();
});
});

it('should not get menu if user not logged in', (done) => {
chai.request(app)
.get('/api/v1/menu')
.set('x-auth', '')
.end((err, res) => {
if (err) done(err);

res.status.should.eql(401);
res.body.status.should.eql('error');
done();
});
});
});

0 comments on commit d349203

Please sign in to comment.