Skip to content

Instantly share code, notes, and snippets.

@yomigeek
Last active July 24, 2018 07:29
Show Gist options
  • Save yomigeek/78850fbab6f9a743b24a0d35fe7c7584 to your computer and use it in GitHub Desktop.
Save yomigeek/78850fbab6f9a743b24a0d35fe7c7584 to your computer and use it in GitHub Desktop.
T.D.D for Authors' Haven - Team Elven(Abayomi Olaoye)
// Developer: Abayomi Olaoye
// Test to edit/update a user profile
import { describe, it } from 'mocha';
import chai, { expect } from 'chai';
import chaiHttp from 'chai-http';
import index from '../index';
const should = chai.should();
chai.use(chaiHttp);
// check empty username
describe('User Edit Profile API Tests', () => {
it('should fail on username field empty PUT /api/user', (done) => {
chai.request(index)
.put('/api/user')
.set('x-access-token', token)
.send({
username: '',
email: '[email protected]',
password: '12345',
image: 'http://appurl/image/pic.svg',
bio: 'Always a good guy'
})
.end((err, res) => {
res.should.have.status(400);
res.should.be.json;
res.body.should.be.a('object');
res.body.should.have.property('status');
res.body.should.have.property('message');
res.body.status.should.equal('failed');
res.body.errors.should.be.a('object');
res.body.errors.should.have.property('username');
res.body.errors.username.should.be.a('array');
done();
});
});
// check empty email
it('should fail on email field empty PUT /api/user', (done) => {
chai.request(index)
.put('/api/user')
.set('x-access-token', token)
.send({
username: 'oyomy',
email: '',
password: '12345',
image: 'http://appurl/image/pic.svg',
bio: 'Always a good guy'
})
.end((err, res) => {
res.should.have.status(400);
res.should.be.json;
res.body.should.be.a('object');
res.body.should.have.property('status');
res.body.should.have.property('message');
res.body.status.should.equal('failed');
res.body.errors.should.be.a('object');
res.body.errors.should.have.property('email');
res.body.errors.email.should.be.a('array');
done();
});
});
});
@Oluwafayokemi
Copy link

Oluwafayokemi commented Jul 23, 2018

Nice Work! You should take into consideration, returning an error message for the user to relate with.
I think you should also try to write a test for the success.

@Veraclins
Copy link

Nice Work Yomi.

@chukwuemekachm
Copy link

Weldone. Well formatted and in-depth.

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