Last active
July 24, 2018 05:45
-
-
Save veeqtor/9e80a931937af3a385b59aa6a73a341f to your computer and use it in GitHub Desktop.
Test cases for create article route authentication
This file contains 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
const payload = { | |
"article": { | |
"title": "How to train your dragon", | |
"description": "Ever wonder how?", | |
"body": "You have to believe", | |
"tagList": ["reactjs", "angularjs", "dragons"] | |
} | |
} | |
it('Should not be able to create article on an invalid token or expired token', (done) => { | |
chai.request(app) | |
.post('/api/articles') | |
.set({ Authorization: 'Bearer invalid/expired jwt token' }) | |
.send(payload) | |
.end((err, res) => { | |
Expect(res.statusCode).to.equal(401); | |
Expect(res.body.errors).to.be.an('object'); | |
Expect(res.body.errors).to.have.property('body'); | |
Expect(res.body.errors.body).to.be.an('array'); | |
done(); | |
}); | |
Good job on your TDD, great initiative on thinking about the possible scenarios, I, however, think the error body should include a specific message pointing towards lack of authorization.
Great job bro. Keep raising the TDD bar high.
Nice job on testing for an expired or invalid token. Keep it up and reflect on more edge cases.
Good approach! You made sure only authenticated users can create an article, that's good practice, keep it up
Good job on testing for edge cases, however I feel your test should have a describe block as this helps with grouping and differentiating test cases.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job for testing on for a valid token in creating a new article. This will ensure that only a logged In user will be able to create an article.