Skip to content

Instantly share code, notes, and snippets.

@Joyce-O
Last active March 21, 2019 07:50
Show Gist options
  • Save Joyce-O/6330205e41ff6990d492724527076f81 to your computer and use it in GitHub Desktop.
Save Joyce-O/6330205e41ff6990d492724527076f81 to your computer and use it in GitHub Desktop.
Unit test for get tags api endpoint in the medium.com website
describe('Test for get tags endpoint', () => {
it('Should return status code 200 for success', (done) => {
chai.request(app)
.get('/api/tags')
.set('authorization', token)
.end((error, response) => {
expect(response).to.have.status(200);
done();
});
it('should return 404 for tags not found', (done) => {
chai.request(app)
.get('/api/tags')
.set('authorization', token)
.end((error, response) => {
expect(response).to.have.status(404);
expect(response.body.error).to.equal('tags not found');
done();
});
});
});
@innocentEdosa
Copy link

Hello Joyce,
Nice work. I think you might want to consider using async/await for asynchronous calls because it helps in making code cleaner and also makes error handling easier (try/catch).
Thanks

@kayroy247
Copy link

Good job with your test but I think you may need to improve on the following:

  1. Paying attention to details because from the specificaiton, the endpoint to get tags is "/api/tags" and not "/api/v1/tags" you used on line 4.
  2. You used the same endpoint for successfully getting tags on line 4 and also for tags endpoint that does not exist on 12.
  3. The indentation on line 9, 10, 18 and 20 are not consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment