Last active
November 24, 2018 15:01
-
-
Save idmega2000/7f4eda8077c29e1672decda133a20ef9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]' | |
}, 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(); | |
}); | |
}); | |
}); |
Nice job Idris... But I think your test should use mock data which includes a UUID in the URL path
Nice Job Idris!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one Idris. Love the fact that you are using an env for your JWT_SECRET. Kudos