diff --git a/package.json b/package.json index 71853e8..5147439 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "node ./src/bin/www", "devstart": "set DEBUG=dev && babel-watch ./src/bin/dev", "build": "rm -rf dist && mkdir dist && babel src -s -d dist", - "test": " set NODE_ENV=test&& npm run reset-db&& nyc mocha -r @babel/register --recursive src/test/ --exit -timeout 10000", + "test": " set NODE_ENV=test&& npm run reset-db&& nyc mocha --timeout 2000 -r @babel/register --recursive src/test/ --exit", "migrate": "./node_modules/.bin/sequelize db:migrate", "drop-db": "./node_modules/.bin/sequelize db:migrate:undo:all", "seeders": "./node_modules/.bin/sequelize db:seed:all", diff --git a/src/test/authTest.js b/src/test/authTest.js index d4c1879..c00aead 100644 --- a/src/test/authTest.js +++ b/src/test/authTest.js @@ -19,6 +19,7 @@ describe('Signup Error', () => { .post(`${userEndPoint}signup`) .send(user) .end((err, res) => { + if (err) done(err); res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); @@ -37,6 +38,7 @@ describe('Signup Error', () => { .post(`${userEndPoint}signup`) .send(user) .end((err, res) => { + if (err) done(err); res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); @@ -58,6 +60,7 @@ describe('Signup Error', () => { .post(`${userEndPoint}signup`) .send(user) .end((err, res) => { + if (err) done(err); res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); @@ -66,132 +69,138 @@ describe('Signup Error', () => { }); }); -// describe(`POST ${userEndPoint}signup`, () => { -// it('Should create a new user', (done) => { -// const user = { -// email: 'temi@testmail.com', -// password: 'password', -// }; -// chai.request(app) -// .post(`${userEndPoint}signup`) -// .send(user) -// .end((err, res) => { -// res.should.have.status(201); -// res.body.should.be.a('object'); -// res.body.should.have.property('data'); -// res.body.data.should.be.a('object'); -// res.body.data.should.have.property('tokens'); -// res.body.data.should.have.property('id'); -// res.body.data.should.have.property('email'); -// done(); -// }); -// }); -// }); +describe(`POST ${userEndPoint}signup`, () => { + it('Should create a new user', (done) => { + const user = { + email: 'temi@testmail.com', + password: 'password', + }; + chai.request(app) + .post(`${userEndPoint}signup`) + .send(user) + .end((err, res) => { + if (err) done(err); + res.should.have.status(201); + res.body.should.be.a('object'); + res.body.should.have.property('data'); + res.body.data.should.be.a('object'); + res.body.data.should.have.property('tokens'); + res.body.data.should.have.property('id'); + res.body.data.should.have.property('email'); + done(); + }); + }); +}); -// describe('Signup Error', () => { -// it('Should return 409 if email already exists', (done) => { -// const user = { -// email: 'temi@testmail.com', -// password: 'password', -// }; -// chai.request(app) -// .post(`${userEndPoint}signup`) -// .send(user) -// .end((err, res) => { -// res.should.have.status(409); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Signup Error', () => { + it('Should return 409 if email already exists', (done) => { + const user = { + email: 'temi@testmail.com', + password: 'password', + }; + chai.request(app) + .post(`${userEndPoint}signup`) + .send(user) + .end((err, res) => { + if (err) done(err); + res.should.have.status(409); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); +}); -// describe('Signin Error', () => { -// it('Should deny access if wrong email is provided', (done) => { -// const login = { -// email: 'kcmykirl@gmail.com', -// password: 'pA55w0rd', -// }; -// chai.request(app) -// .post(`${userEndPoint}signin`) -// .send(login) -// .end((err, res) => { -// res.should.have.status(404); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Signin Error', () => { + it('Should deny access if wrong email is provided', (done) => { + const login = { + email: 'kcmykirl@gmail.com', + password: 'pA55w0rd', + }; + chai.request(app) + .post(`${userEndPoint}signin`) + .send(login) + .end((err, res) => { + if (err) done(err); + res.should.have.status(404); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); +}); -// describe('Signin Error', () => { -// it('Should deny access if wrong password is provided', (done) => { -// const login = { -// email: 'temi@testmail.com', -// password: 'passweod', -// }; -// chai.request(app) -// .post(`${userEndPoint}signin`) -// .send(login) -// .end((err, res) => { -// res.should.have.status(401); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Signin Error', () => { + it('Should deny access if wrong password is provided', (done) => { + const login = { + email: 'temi@testmail.com', + password: 'passweod', + }; + chai.request(app) + .post(`${userEndPoint}signin`) + .send(login) + .end((err, res) => { + res.should.have.status(401); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); +}); -// describe('Signin Errror', () => { -// it('Should return 400 if email is not provided', (done) => { -// const login = { -// password: 'password', -// }; -// chai.request(app) -// .post(`${userEndPoint}signin`) -// .send(login) -// .end((err, res) => { -// res.should.have.status(400); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Signin Errror', () => { + it('Should return 400 if email is not provided', (done) => { + const login = { + password: 'password', + }; + chai.request(app) + .post(`${userEndPoint}signin`) + .send(login) + .end((err, res) => { + if (err) done(err); + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); +}); -// describe('Signin Error', () => { -// it('Should return 400 if password is ommited', (done) => { -// const login = { -// email: 'temi@testmail.com', -// }; -// chai.request(app) -// .post(`${userEndPoint}signin`) -// .send(login) -// .end((err, res) => { -// res.should.have.status(400); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Signin Error', () => { + it('Should return 400 if password is ommited', (done) => { + const login = { + email: 'temi@testmail.com', + }; + chai.request(app) + .post(`${userEndPoint}signin`) + .send(login) + .end((err, res) => { + if (err) done(err); + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); +}); -// describe('User Login tests', () => { -// it('Should login a user successfully', (done) => { -// const login = { -// email: 'temi@testmail.com', -// password: 'password', -// }; -// chai.request(app) -// .post(`${userEndPoint}signin`) -// .send(login) -// .end((err, res) => { -// res.should.have.status(200); -// res.body.should.be.a('object'); -// res.body.should.have.property('data'); -// res.body.data.should.be.a('object'); -// res.body.data.should.have.property('tokens'); -// done(); -// }); -// }); -// }); +describe('User Login tests', () => { + it('Should login a user successfully', (done) => { + const login = { + email: 'temi@testmail.com', + password: 'password', + }; + chai.request(app) + .post(`${userEndPoint}signin`) + .send(login) + .end((err, res) => { + if (err) done(err); + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('data'); + res.body.data.should.be.a('object'); + res.body.data.should.have.property('tokens'); + done(); + }); + }); +}); diff --git a/src/test/courseTest.js b/src/test/courseTest.js index 158e670..f1c86ab 100644 --- a/src/test/courseTest.js +++ b/src/test/courseTest.js @@ -1,76 +1,76 @@ import chai from 'chai'; import chaiHttp from 'chai-http'; import app from '../app'; -// import Utils from '../utils'; +import Utils from '../utils'; chai.should(); chai.use(chaiHttp); const apiEndPoint = '/api/v1/'; -// const adminEmail = 'victorawotidebe@gmail.com'; -// const notAdminEmail = 'rmissen0@adobe.com'; -// const token = Utils.generateToken({ email: adminEmail }); -// const nonAdminToken = Utils.generateToken({ email: notAdminEmail }); +const adminEmail = 'victorawotidebe@gmail.com'; +const notAdminEmail = 'rmissen0@adobe.com'; +const token = Utils.generateToken({ email: adminEmail }); +const nonAdminToken = Utils.generateToken({ email: notAdminEmail }); -// describe('Create Courses Tests', () => { -// it('Should return 403 if user is not an admin', (done) => { -// const course = { -// CourseTitle: 'Facility Management', -// memberFees: 105000, -// nonmemberFee: 115000, -// startDate: 10, -// endDate: 13, -// }; +describe('Create Courses Tests', () => { + it('Should return 403 if user is not an admin', (done) => { + const course = { + CourseTitle: 'Facility Management', + memberFees: 105000, + nonmemberFee: 115000, + startDate: 10, + endDate: 13, + }; -// chai.request(app) -// .post(`${apiEndPoint}courses`) -// .set('Authorization', `Bearer ${nonAdminToken}`) -// .send(course) -// .end((err, res) => { -// if (err) done(err); -// res.should.have.status(403); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); + chai.request(app) + .post(`${apiEndPoint}courses`) + .set('Authorization', `Bearer ${nonAdminToken}`) + .send(course) + .end((err, res) => { + if (err) done(err); + res.should.have.status(403); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }).timeout(15000); +}); -// describe('Create Courses Tests', () => { -// it('Should Successfully Create a Course', (done) => { -// const course = { -// courseTitle: 'Facility Management', -// memberFees: 105000, -// nonMemberFees: 115000, -// startDate: 10, -// endDate: 13, -// duration: '10 weeks', -// venue: 'illupeju', -// }; -// chai.request(app) -// .post(`${apiEndPoint}courses`) -// .set('Authorization', `Bearer ${token}`) -// .send(course) -// .end((err, res) => { -// if (err) done(err); -// res.should.have.status(201); -// res.body.should.be.a('object'); -// res.body.should.have.property('status'); -// res.body.should.have.property('data'); -// res.body.data.should.be.a('object'); -// res.body.data.should.have.property('id'); -// res.body.data.should.have.property('courseTitle'); -// res.body.data.should.have.property('memberFees'); -// res.body.data.should.have.property('duration'); -// res.body.data.should.have.property('venue'); -// res.body.data.should.have.property('nonMemberFees'); -// res.body.data.should.have.property('startDate'); -// res.body.data.should.have.property('endDate'); -// done(); -// }); -// }); -// }); +describe('Create Courses Tests', () => { + it('Should Successfully Create a Course', (done) => { + const course = { + courseTitle: 'Facility Management', + memberFees: 105000, + nonMemberFees: 115000, + startDate: 10, + endDate: 13, + duration: '10 weeks', + venue: 'illupeju', + }; + chai.request(app) + .post(`${apiEndPoint}courses`) + .set('Authorization', `Bearer ${token}`) + .send(course) + .end((err, res) => { + if (err) done(err); + res.should.have.status(201); + res.body.should.be.a('object'); + res.body.should.have.property('status'); + res.body.should.have.property('data'); + res.body.data.should.be.a('object'); + res.body.data.should.have.property('id'); + res.body.data.should.have.property('courseTitle'); + res.body.data.should.have.property('memberFees'); + res.body.data.should.have.property('duration'); + res.body.data.should.have.property('venue'); + res.body.data.should.have.property('nonMemberFees'); + res.body.data.should.have.property('startDate'); + res.body.data.should.have.property('endDate'); + done(); + }); + }).timeout(15000); +}); describe('Create Courses Tests', () => { it('Should return 401 if token is not provided', (done) => { @@ -91,155 +91,155 @@ describe('Create Courses Tests', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); -// describe('Create Courses Tests', () => { -// it('Should return 400 if courseTitle isn\'t specified', (done) => { -// const course = { -// memberFees: 105000, -// nonmemberFee: 115000, -// startDate: 10, -// endDate: 13, -// }; +describe('Create Courses Tests', () => { + it('Should return 400 if courseTitle isn\'t specified', (done) => { + const course = { + memberFees: 105000, + nonmemberFee: 115000, + startDate: 10, + endDate: 13, + }; -// chai.request(app) -// .post(`${apiEndPoint}courses`) -// .set('Authorization', `Bearer ${token}`) -// .send(course) -// .end((err, res) => { -// res.should.have.status(400); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); + chai.request(app) + .post(`${apiEndPoint}courses`) + .set('Authorization', `Bearer ${token}`) + .send(course) + .end((err, res) => { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }).timeout(15000); +}); -// describe('Create Courses', () => { -// it('Should return 400 if memberFees isn\'t specified', (done) => { -// const course = { -// CourseTitle: 'Facility Management', -// nonmemberFee: 115000, -// startDate: 10, -// endDate: 13, -// }; -// chai.request(app) -// .post(`${apiEndPoint}courses`) -// .set('Authorization', `Bearer ${token}`) -// .send(course) -// .end((err, res) => { -// res.should.have.status(400); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Create Courses', () => { + it('Should return 400 if memberFees isn\'t specified', (done) => { + const course = { + CourseTitle: 'Facility Management', + nonmemberFee: 115000, + startDate: 10, + endDate: 13, + }; + chai.request(app) + .post(`${apiEndPoint}courses`) + .set('Authorization', `Bearer ${token}`) + .send(course) + .end((err, res) => { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }).timeout(15000); +}); -// describe('Create Courses', () => { -// it('Should return 400 if nonmemberFee isn\'t specified', (done) => { -// const course = { -// CourseTitle: 'Facility Management', -// memberFees: 105000, -// startDate: 10, -// endDate: 13, -// }; -// chai.request(app) -// .post(`${apiEndPoint}courses`) -// .set('Authorization', `Bearer ${token}`) -// .send(course) -// .end((err, res) => { -// res.should.have.status(400); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Create Courses', () => { + it('Should return 400 if nonmemberFee isn\'t specified', (done) => { + const course = { + CourseTitle: 'Facility Management', + memberFees: 105000, + startDate: 10, + endDate: 13, + }; + chai.request(app) + .post(`${apiEndPoint}courses`) + .set('Authorization', `Bearer ${token}`) + .send(course) + .end((err, res) => { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }).timeout(15000); +}); -// describe('Ceate Courses', () => { -// it('Should return 400 if endDate isn\'t specified', (done) => { -// const course = { -// CourseTitle: 'Facility Management', -// memberFees: 105000, -// nonmemberFee: 115000, -// startDate: 10, -// }; -// chai.request(app) -// .post(`${apiEndPoint}courses`) -// .set('Authorization', `Bearer ${token}`) -// .send(course) -// .end((err, res) => { -// res.should.have.status(400); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Ceate Courses', () => { + it('Should return 400 if endDate isn\'t specified', (done) => { + const course = { + CourseTitle: 'Facility Management', + memberFees: 105000, + nonmemberFee: 115000, + startDate: 10, + }; + chai.request(app) + .post(`${apiEndPoint}courses`) + .set('Authorization', `Bearer ${token}`) + .send(course) + .end((err, res) => { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }).timeout(15000); +}); -// describe('Create Courses Tests', () => { -// it('Should return 400 if startDate isn\'t specified', (done) => { -// const course = { -// CourseTitle: 'Facility Management', -// memberFees: 105000, -// nonmemberFee: 115000, -// endDate: 13, -// }; -// chai.request(app) -// .post(`${apiEndPoint}courses`) -// .set('Authorization', `Bearer ${token}`) -// .send(course) -// .end((err, res) => { -// res.should.have.status(400); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }); -// }); +describe('Create Courses Tests', () => { + it('Should return 400 if startDate isn\'t specified', (done) => { + const course = { + CourseTitle: 'Facility Management', + memberFees: 105000, + nonmemberFee: 115000, + endDate: 13, + }; + chai.request(app) + .post(`${apiEndPoint}courses`) + .set('Authorization', `Bearer ${token}`) + .send(course) + .end((err, res) => { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }).timeout(15000); +}); -// describe('Get requests for both user and admin', () => { -// it('should return 200 and get all courses', (done) => { -// chai.request(app) -// .get(`${apiEndPoint}courses`) -// .set('Authorization', `Bearer ${token}`) -// .send(token) -// .end((err, res) => { -// res.should.have.status(200); -// res.body.should.be.an('object'); -// res.body.should.have.property('status'); -// res.body.should.have.property('data'); -// res.body.data.should.be.an('array'); -// res.body.data[0].should.have.property('id'); -// res.body.data[0].should.have.property('courseTitle'); -// res.body.data[0].should.have.property('memberFees'); -// res.body.data[0].should.have.property('nonMemberFees'); -// res.body.data[0].should.have.property('startDate'); -// res.body.data[0].should.have.property('endDate'); -// done(); -// }); -// }); -// }); +describe('Get requests for both user and admin', () => { + it('should return 200 and get all courses', (done) => { + chai.request(app) + .get(`${apiEndPoint}course`) + .set('Authorization', `Bearer ${token}`) + .send(token) + .end((err, res) => { + res.should.have.status(200); + res.body.should.be.an('object'); + res.body.should.have.property('status'); + res.body.should.have.property('data'); + res.body.data.should.be.an('array'); + res.body.data[0].should.have.property('id'); + res.body.data[0].should.have.property('courseTitle'); + res.body.data[0].should.have.property('memberFees'); + res.body.data[0].should.have.property('nonMemberFees'); + res.body.data[0].should.have.property('startDate'); + res.body.data[0].should.have.property('endDate'); + done(); + }); + }).timeout(15000); +}); -// describe('Register a courses', () => { -// it('Should register a user for a course', (done) => { -// chai.request(app) -// .post(`${apiEndPoint}courses/2/register`) -// .set('Authorization', `Bearer ${token}`) -// .send(token) -// .end((err, res) => { -// res.should.have.status(201); -// res.body.should.be.an('object'); -// res.body.should.have.property('status'); -// res.body.should.have.property('data'); -// res.body.data.should.be.an('object'); -// res.body.data.should.have.property('id'); -// res.body.data.should.have.property('UserId'); -// res.body.data.should.have.property('courseId'); -// res.body.data.should.have.property('registeredOn'); -// done(); -// }); -// }); -// }); +describe('Register a courses', () => { + it('Should register a user for a course', (done) => { + chai.request(app) + .post(`${apiEndPoint}courses/2/register`) + .set('Authorization', `Bearer ${token}`) + .send(token) + .end((err, res) => { + res.should.have.status(201); + res.body.should.be.an('object'); + res.body.should.have.property('status'); + res.body.should.have.property('data'); + res.body.data.should.be.an('object'); + res.body.data.should.have.property('id'); + res.body.data.should.have.property('UserId'); + res.body.data.should.have.property('courseId'); + res.body.data.should.have.property('registeredOn'); + done(); + }); + }).timeout(15000); +});