Skip to content

Instantly share code, notes, and snippets.

@Danielshow
Last active November 22, 2018 15:40
Show Gist options
  • Save Danielshow/37721cfc28c72936b04be4eecfb2a341 to your computer and use it in GitHub Desktop.
Save Danielshow/37721cfc28c72936b04be4eecfb2a341 to your computer and use it in GitHub Desktop.
import { expect, should } from 'chai';
const url = '../index';
const testObject = {
emptyEmail: {
email: '',
password: 'tuij'
},
wrongEmailFormat: {
email: 'danielopeyemi*',
password: 'opeyemi'
},
correctInput: {
email: 'danielshotonwa@email.com',
password: 'opeyemi'
}
};
descibe('API Endpoint to Login Users on medium.com', () => {
it('Should return error if email field is empty', () => {
chai.request(url)
.post('/auth/signin')
.send(testObject.emptyEmail)
.then((res) => {
expect(res).to.have.status(400);
res.body.should.have.property('message').eql('Email field is empty');
});
});
it('Should return error if email syntax is wrong', () => {
chai.request(url)
.post('/auth/signin')
.send(testObject.wrongEmailFormat)
.then((res) => {
expect(res).to.have.status(400);
res.body.should.have.property('message').eql('Email format is wrong');
});
});
it('Should return ok if email and password field is correct', () => {
chai.request(url)
.post('/auth/signin')
.send(testObject.correctInput)
.then((res) => {
expect(res).to.have.status(200);
res.body.should.have.property('message').eql('Login Successful');
});
});
})
@davidshare
Copy link

Looks good to me.

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