Skip to content

Instantly share code, notes, and snippets.

@anneKay
Forked from Oloyedesinmiloluwa/createArticle.test.js
Last active July 24, 2018 14:55
Show Gist options
  • Save anneKay/3aa558d3ccf03fec7ce7525e62c2ca7c to your computer and use it in GitHub Desktop.
Save anneKay/3aa558d3ccf03fec7ce7525e62c2ca7c to your computer and use it in GitHub Desktop.
Fargo Team TDD activity
import expect from 'expect';
import request from 'supertest';
import app from './../app';
// Test for creating an article
describe ('POST api/articles', () => {
const article = {
title: 'the title',
body: '',
description: 'the description',
image: 'https://image.jpg'
}
it('should not create an article if body field is empty', (done) => {
request(app)
.post('api/articles')
.set('authentication', 'JWTtoken')
.send(article)
.expect(400)
.expect((res, err) => {
expect(res.body.error).toExist();
expect(res.body.error[0].body.message).toBe('body field can not be empty');
})
.end(done);
});
});
@klevamane
Copy link

Good job testing for empty article body. This will ensure that an article cannot be created if the body is empty.

@ascii-dev
Copy link

ascii-dev commented Jul 23, 2018

I think you should look into your expect statement. First I feel the HTTP error code should not be 200, given the fact that the request was not successfully created. ¡Chao!

@Lumexralph
Copy link

Lumexralph commented Jul 23, 2018

Nice job on testing for when an article's description field is empty. Keep it up and reflect on more edge cases especially on the error message.

@veeqtor
Copy link

veeqtor commented Jul 23, 2018

Nice work!, but I feel you can actually be specific on the expect(400) so we will know that we are expecting a status code of 400.

@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 the body field being empty.

@Oloyedesinmiloluwa
Copy link

Nice attempt! You checked for empty body, I bet no user will be able to create an article without a body with this test case, that's fine, keep it up.

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