Skip to content

Commit

Permalink
[chore 165713687] Integrate Coveralls and Codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
sengayire committed Apr 30, 2019
1 parent 58c9147 commit 6253493
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ plugins:
eslint:
enabled: true
exclude_patterns:
- "config/"
- "models/"
- "dist/"
- "src/config/"
- "src/models/"
- "src/dist/"
- "features/"
- "**/node_modules/"
- "script/"
Expand Down
4 changes: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SECRET_KEY = secretkey
DATABASE_DEV_URL = postgres://username:password@localhost:5432/database_name
DATABASE_TEST_URL = postgres://username:password@localhost:5432/database_name
DATABASE_URL_DEV = postgres://username:password@localhost:5432/database_name
DATABASE_URL_TEST = postgres://username:password@localhost:5432/database_name

DB_NAME_DEV=authorhavens_dev
DB_HOST_DEV=localhost
Expand Down
10 changes: 10 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"reporter": [
"lcov",
"text"
],
"exclude": [
"src/migartions",
"src/helpers"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/andela/ninjas-ah-backend.svg?branch=ch-create-db-models-165663486)](https://travis-ci.org/andela/ninjas-ah-backend) [![Coverage Status](https://coveralls.io/repos/github/andela/ninjas-ah-backend/badge.svg?branch=ch-create-db-models-165663486)](https://coveralls.io/github/andela/ninjas-ah-backend?branch=ch-create-db-models-165663486)
[![Build Status](https://travis-ci.org/andela/ninjas-ah-backend.svg?branch=develop)](https://travis-ci.org/andela/ninjas-ah-backend) [![Coverage Status](https://coveralls.io/repos/github/andela/ninjas-ah-backend/badge.svg?branch=develop)](https://coveralls.io/github/andela/ninjas-ah-backend?branch=develop) [![Maintainability](https://api.codeclimate.com/v1/badges/4635ecd43e1b06546534/maintainability)](https://codeclimate.com/github/andela/ninjas-ah-backend/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/4635ecd43e1b06546534/test_coverage)](https://codeclimate.com/github/andela/ninjas-ah-backend/test_coverage)

Authors Haven - A Social platform for the creative at heart.
=======
Expand Down
127 changes: 127 additions & 0 deletions src/tests/users.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import chai from 'chai';
import chaiHttp from 'chai-http';
import app from '../app';

chai.use(chaiHttp);
chai.should();

// test to sign up new user
describe('user signup', () => {
it('Should register new user', (done) => {
const user = {
firstName: 'giramata',
lastName: 'hababagabo',
otherName: 'wamata',
email: 'sengaprince@gmail.com',
password: '123456',
phoneNumber: '0788990672',
passportUrl: 'www.google.rw',
};
chai.request(app)
.post('/api/v1/users/auth/signup')
.send(user)
.end((err, res) => {
res.body.should.be.an('object');
res.body.should.have.property('status').equal(201);
res.body.should.have.property('token');
res.body.should.have.property('data');
done();
});
});
it('Should fail to register new user if exists', (done) => {
const user = {
firstName: 'Bobo',
lastName: 'NIYO',
otherName: 'ynwa',
email: 'bobo12@gmail.com',
password: '123456',
phoneNumber: '0783200000',
passportUrl: 'www.go.rw',
};
chai.request(app)
.post('/api/v1/users/auth/signup')
.send(user)
.end((err, res) => {
res.body.should.be.an('object');
res.body.should.have.property('status').equal(409);
res.body.should.have.property('error').equal('User already exist');
done();
});
});
});

it('Should fail to register with invalid email', (done) => {
const user = {
firstName: 'Bobo',
lastName: 'NIYO',
otherName: 'ynwa',
email: 'bobo12mail.com',
password: '123456',
phoneNumber: '0783200000',
passportUrl: 'www.go.rw',
};
chai.request(app)
.post('/api/v1/users/auth/signup')
.send(user)
.end((err, res) => {
res.body.should.be.an('object');
res.status.should.be.eql(400);
res.body.should.have.property('status').equal(400);
res.body.should.have.property('error').equal('Please enter a valid email address');
done();
});
});

// user sign in endpoint test
describe('test user login', () => {
// sign in user
it('login user', (done) => {
const user = {
email: 'bobo123@gmail.com',
password: '123456',
};
chai.request(app)
.post('/api/v1/users/auth/signin')
.send(user)
.end((err, res) => {
res.body.should.be.an('object');
res.status.should.be.eql(200);
res.body.should.have.property('status').equal(200);
res.body.data[0].should.have.property('token');
});
done();
});
it('fail to login with invalid email', (done) => {
const invalid = {
email: 'psengayire',
password: 'passw',
};
chai.request(app)
.post('/api/v1/users/auth/signin')
.send(invalid)
.end((err, res) => {
res.body.should.be.an('object');
res.status.should.be.eql(400);
res.body.should.have.property('message').eql('Please enter a valid email address');
});
done();
});

// test fail if user not exists

it('fail to login if user credentials are wrong', (done) => {
const notExist = {
email: 'fred1@email.com',
password: 'passw',
};
chai.request(app)
.post('/api/v1/users/auth/signin')
.send(notExist)
.end((err, res) => {
res.body.should.be.an('object');
res.status.should.be.eql(403);
res.body.should.have.property('status').equal(403);
});
done();
});
});

0 comments on commit 6253493

Please sign in to comment.