Skip to content

Instantly share code, notes, and snippets.

@mystere10
Last active March 13, 2019 16:40
Show Gist options
  • Save mystere10/9bd7675e4216d43e344c3010e617c9e7 to your computer and use it in GitHub Desktop.
Save mystere10/9bd7675e4216d43e344c3010e617c9e7 to your computer and use it in GitHub Desktop.
Comment for test
import chai from 'chai';
import chaiHttp from 'chai-http';
import server from '../index.js';
chai.should();
chai.use(chaiHttp);
let clinentToken;
describe('Tests for comments', () => {
it('should login ', (done) => {
const cred = {
username: 'clet',
password: '1234',
};
chai.request(server)
.post('/api/v1/auth/login')
.send(cred)
.then((res) => {
clientToken = res.body.token;
});
});
it('should create a comment', (done) => {
const comment = {
body: 'It takes a Jacobian',
};
chai.request(server)
.post('/api/articles/1/comments')
.send(comment)
.set('Authorization', `Bearer, ${clientToken}`)
.end((err, res) => {
res.should.have.status(201);
res.body.should.be.a('object');
res.body.should.have.property('comment');
res.body.comment.should.have.property('createdAt').eql('2016-02-18T03:22:56.637Z');
res.body.comment.should.have.property('updatedAt').eql('2016-02-18T03:22:56.637Z');
res.body.comment.should.have.property('body').eql('It takes a Jacobian');
res.body.comment.author.should.be.a('object');
res.body.comment.author.should.have.property('username').eql('It takes a Jacobian');
res.body.comment.author.should.have.property('bio').eql('jake');
res.body.comment.author.should.have.property('image').eql('https://i.stack.imgur.com/xHWG8.jpg');
res.body.comment.author.should.have.property('following').eql(false);
done(err);
});
});
});
@jnkindi
Copy link

jnkindi commented Mar 13, 2019

You should test values in the sent variable not rewrite the value but reference the variable values.

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