Skip to content

Instantly share code, notes, and snippets.

@JohnMadakin
Created November 22, 2018 13:43
Show Gist options
  • Save JohnMadakin/62a0a23cbfb4365995f7d24ccef34d5a to your computer and use it in GitHub Desktop.
Save JohnMadakin/62a0a23cbfb4365995f7d24ccef34d5a to your computer and use it in GitHub Desktop.
import expect from 'expect';
import request from 'supertest';
import app from '../index';
describe('Test for Signup', () => {
it('should login users', (done) => {
const userDetail = {
username: 'christain5',
password: 'password@1',
};
request(app).post('/api/v1/auth/login')
.send(userDetail)
.expect(200)
.expect((res) => {
expect(res.body.message).toEqual('you have successfully signed in');
expect(res.body.status).toEqual('Success');
})
.end(done);
});
it('should reject users with empty username', (done) => {
const userDetail = {
username: ' ',
password: 'password@1',
};
request(app).post('/api/v1/auth/login')
.send(userDetail)
.expect(400)
.expect((res) => {
expect(res.body.message).toEqual('invalid username');
})
.end(done);
});
it('should reject users with invalid username format', (done) => {
const userDetail = {
username: '1234903TY',
password: 'password@1',
};
request(app).post('/api/v1/auth/login')
.send(userDetail)
.expect(400)
.expect((res) => {
expect(res.body.message).toEqual('invalid username format');
})
.end(done);
});
it('should reject users with invalid password', (done) => {
const userDetail = {
username: 'christain5',
password: 'password@',
};
request(app).post('/api/v1/auth/login')
.send(userDetail)
.expect(400)
.expect((res) => {
expect(res.body.message).toEqual('invalid password');
})
.end(done);
});
});
@gbols
Copy link

gbols commented Nov 22, 2018

Nice one

@Danielshow
Copy link

Nice one Edafe, code structure is great.

@idmega2000
Copy link

Nice one

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