Skip to content

Instantly share code, notes, and snippets.

@veeqtor
Last active July 24, 2018 05:45
Show Gist options
  • Save veeqtor/9e80a931937af3a385b59aa6a73a341f to your computer and use it in GitHub Desktop.
Save veeqtor/9e80a931937af3a385b59aa6a73a341f to your computer and use it in GitHub Desktop.
Test cases for create article route authentication
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();
});
@OKiMaureen
Copy link

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.

@ascii-dev
Copy link

Great job bro. Keep raising the TDD bar high.

@Lumexralph
Copy link

Nice job on testing for an expired or invalid token. Keep it up and reflect on more edge cases.

@Oloyedesinmiloluwa
Copy link

Good approach! You made sure only authenticated users can create an article, that's good practice, keep it up

@anneKay
Copy link

anneKay commented Jul 24, 2018

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