Skip to content

Instantly share code, notes, and snippets.

@idmega2000
Last active November 24, 2018 15:01
Show Gist options
  • Save idmega2000/7f4eda8077c29e1672decda133a20ef9 to your computer and use it in GitHub Desktop.
Save idmega2000/7f4eda8077c29e1672decda133a20ef9 to your computer and use it in GitHub Desktop.
import index from '../../index';
import supertest from 'supertest';
import assert from 'assert';
import jwt from 'jsonwebtoken';
const path = '/api/v1/articles';
const request = supertest(index);
const token = jwt.sign({
userId: '10',
userEmail: 'andela@yesmail.com'
}, process.env.JWT_KEY);
describe('Get Article', () => {
it('should return error when given an article id that is not an integer',
(done) => {
request.get(`${path}/@re`)
.set('Authorization', `Bearer ${token}`)
.end((err, res) => {
assert.equal(res.statusCode, 400);
assert.equal(res.body.error, 'Article Id should be integer');
done();
});
});
it('should return error when the given Article Id is not found',
(done) => {
request.get(`${path}/46`)
.set('Authorization', `Bearer ${token}`)
.end((err, res) => {
assert.equal(res.statusCode, 404);
assert.equal(res.body.error, 'Article Id not found');
done();
});
});
it('should return article details when given a valid article id',
(done) => {
request.get(`${path}/1`)
.set('Authorization', `Bearer ${token}`)
.end((err, res) => {
assert.equal(res.statusCode, 200);
assert.equal(res.body.article.title, 'The Journey At Andela so far');
assert.equal(res.body.article.imageLink, 'https://res.cloudinary.com/demo/image/upload/.jpg');
done();
});
});
});
@JohnMadakin
Copy link

JohnMadakin commented Nov 22, 2018

Nice job Idris... But I think your test should use mock data which includes a UUID in the URL path

@davidshare
Copy link

Nice Job Idris!

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