From d94a2ac0889a232670eac98788f67cabd8513e29 Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Tue, 20 Oct 2020 16:37:58 +0100 Subject: [PATCH 1/9] improve test --- src/test/authTest.js | 246 +++++++++++++++++++++---------------------- 1 file changed, 123 insertions(+), 123 deletions(-) diff --git a/src/test/authTest.js b/src/test/authTest.js index d4c1879..d90d535 100644 --- a/src/test/authTest.js +++ b/src/test/authTest.js @@ -66,132 +66,132 @@ 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) => { + 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) => { + 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) => { + 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) => { + 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) => { + 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) => { + 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(); + }); + }); +}); From e8f1f1e876c1f7f476bed17b5f79832240d283d9 Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Tue, 20 Oct 2020 17:20:38 +0100 Subject: [PATCH 2/9] increase time out count --- package.json | 2 +- src/test/courseTest.js | 406 ++++++++++++++++++++--------------------- 2 files changed, 204 insertions(+), 204 deletions(-) diff --git a/package.json b/package.json index 71853e8..dcf35ae 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 -r @babel/register --recursive src/test/ --exit -timeout 100000", "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/courseTest.js b/src/test/courseTest.js index 158e670..b335d0b 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(); + }); + }); +}); -// 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(); + }); + }); +}); describe('Create Courses Tests', () => { it('Should return 401 if token is not provided', (done) => { @@ -94,152 +94,152 @@ describe('Create Courses Tests', () => { }); }); -// 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(); + }); + }); +}); -// 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(); + }); + }); +}); -// 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(); + }); + }); +}); -// 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(); + }); + }); +}); -// 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(); + }); + }); +}); -// 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(); + }); + }); +}); -// 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(); + }); + }); +}); From 38d2a0f7fbd2944a55a604459af04a8b6270e502 Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Tue, 20 Oct 2020 18:19:33 +0100 Subject: [PATCH 3/9] Remove timeout --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dcf35ae..6d7d937 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 100000", + "test": " set NODE_ENV=test&& npm run reset-db&& nyc mocha -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", From a0649b5d801130384bb0c1e2469e0731fc8e250c Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Tue, 20 Oct 2020 18:48:47 +0100 Subject: [PATCH 4/9] modify test script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6d7d937..c53ba4e 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 ", + "test": " set NODE_ENV=test&& npm run reset-db&& nyc mocha --timeout 10000 -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", From aea035c24a764673c16b9bc175f56102e6a3e8a1 Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Tue, 20 Oct 2020 19:23:52 +0100 Subject: [PATCH 5/9] modifies test files --- package.json | 2 +- src/test/authTest.js | 20 ++++++++++---------- src/test/courseTest.js | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index c53ba4e..6d7d937 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 --timeout 10000 -r @babel/register --recursive src/test/ --exit ", + "test": " set NODE_ENV=test&& npm run reset-db&& nyc mocha -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 d90d535..3102649 100644 --- a/src/test/authTest.js +++ b/src/test/authTest.js @@ -24,7 +24,7 @@ describe('Signup Error', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Signup Error', () => { @@ -42,7 +42,7 @@ describe('Signup Error', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Signup Error', () => { @@ -63,7 +63,7 @@ describe('Signup Error', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe(`POST ${userEndPoint}signup`, () => { @@ -85,7 +85,7 @@ describe(`POST ${userEndPoint}signup`, () => { res.body.data.should.have.property('email'); done(); }); - }); + }).timeout(15000); }); describe('Signup Error', () => { @@ -103,7 +103,7 @@ describe('Signup Error', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Signin Error', () => { @@ -121,7 +121,7 @@ describe('Signin Error', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Signin Error', () => { @@ -139,7 +139,7 @@ describe('Signin Error', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Signin Errror', () => { @@ -156,7 +156,7 @@ describe('Signin Errror', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Signin Error', () => { @@ -173,7 +173,7 @@ describe('Signin Error', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('User Login tests', () => { @@ -193,5 +193,5 @@ describe('User Login tests', () => { res.body.data.should.have.property('tokens'); done(); }); - }); + }).timeout(15000); }); diff --git a/src/test/courseTest.js b/src/test/courseTest.js index b335d0b..f1c86ab 100644 --- a/src/test/courseTest.js +++ b/src/test/courseTest.js @@ -34,7 +34,7 @@ describe('Create Courses Tests', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Create Courses Tests', () => { @@ -69,7 +69,7 @@ describe('Create Courses Tests', () => { res.body.data.should.have.property('endDate'); done(); }); - }); + }).timeout(15000); }); describe('Create Courses Tests', () => { @@ -91,7 +91,7 @@ describe('Create Courses Tests', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Create Courses Tests', () => { @@ -113,7 +113,7 @@ describe('Create Courses Tests', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Create Courses', () => { @@ -134,7 +134,7 @@ describe('Create Courses', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Create Courses', () => { @@ -155,7 +155,7 @@ describe('Create Courses', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Ceate Courses', () => { @@ -176,7 +176,7 @@ describe('Ceate Courses', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Create Courses Tests', () => { @@ -197,7 +197,7 @@ describe('Create Courses Tests', () => { res.body.should.have.property('error'); done(); }); - }); + }).timeout(15000); }); describe('Get requests for both user and admin', () => { @@ -220,7 +220,7 @@ describe('Get requests for both user and admin', () => { res.body.data[0].should.have.property('endDate'); done(); }); - }); + }).timeout(15000); }); describe('Register a courses', () => { @@ -241,5 +241,5 @@ describe('Register a courses', () => { res.body.data.should.have.property('registeredOn'); done(); }); - }); + }).timeout(15000); }); From 01a998c68cd3e9ea9018491ebca272d967badcc1 Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Tue, 20 Oct 2020 19:43:33 +0100 Subject: [PATCH 6/9] refactor test files --- src/test/authTest.js | 182 ++++++++++++++++++------------------- src/test/courseTest.js | 200 ++++++++++++++++++++--------------------- 2 files changed, 191 insertions(+), 191 deletions(-) diff --git a/src/test/authTest.js b/src/test/authTest.js index 3102649..e02ef02 100644 --- a/src/test/authTest.js +++ b/src/test/authTest.js @@ -66,81 +66,81 @@ describe('Signup Error', () => { }).timeout(15000); }); -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(); - }); - }).timeout(15000); -}); +// 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(); +// }); +// }).timeout(15000); +// }); -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(); - }); - }).timeout(15000); -}); +// 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(); +// }); +// }).timeout(15000); +// }); -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(); - }); - }).timeout(15000); -}); +// 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(); +// }); +// }).timeout(15000); +// }); -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(); - }); - }).timeout(15000); -}); +// 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(); +// }); +// }).timeout(15000); +// }); describe('Signin Errror', () => { it('Should return 400 if email is not provided', (done) => { @@ -176,22 +176,22 @@ describe('Signin Error', () => { }).timeout(15000); }); -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(); - }); - }).timeout(15000); -}); +// 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(); +// }); +// }).timeout(15000); +// }); diff --git a/src/test/courseTest.js b/src/test/courseTest.js index f1c86ab..b53768b 100644 --- a/src/test/courseTest.js +++ b/src/test/courseTest.js @@ -9,68 +9,68 @@ chai.use(chaiHttp); const apiEndPoint = '/api/v1/'; const adminEmail = 'victorawotidebe@gmail.com'; -const notAdminEmail = 'rmissen0@adobe.com'; +// const notAdminEmail = 'rmissen0@adobe.com'; const token = Utils.generateToken({ email: adminEmail }); -const nonAdminToken = Utils.generateToken({ email: notAdminEmail }); +// 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(); - }); - }).timeout(15000); -}); +// 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(); - }); - }).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(); +// }); +// }).timeout(15000); +// }); describe('Create Courses Tests', () => { it('Should return 401 if token is not provided', (done) => { @@ -200,46 +200,46 @@ describe('Create Courses Tests', () => { }).timeout(15000); }); -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('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(); - }); - }).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(); +// }); +// }).timeout(15000); +// }); From 0ad3011c6e4d6a666a06a0a24057076404b51e6a Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Thu, 22 Oct 2020 15:48:53 +0100 Subject: [PATCH 7/9] ammend test file --- package.json | 2 +- src/test/authTest.js | 201 ++++++++++++++++--------------- src/test/courseTest.js | 260 ++++++++++++++++++++--------------------- 3 files changed, 236 insertions(+), 227 deletions(-) diff --git a/package.json b/package.json index 6d7d937..0ffc139 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 ", + "test": " set NODE_ENV=test&& npm run reset-db&& nyc mocha -r @babel/register --recursive src/test/ --exit --timeout 100000", "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 e02ef02..c00aead 100644 --- a/src/test/authTest.js +++ b/src/test/authTest.js @@ -19,12 +19,13 @@ 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'); done(); }); - }).timeout(15000); + }); }); describe('Signup Error', () => { @@ -37,12 +38,13 @@ 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'); done(); }); - }).timeout(15000); + }); }); describe('Signup Error', () => { @@ -58,89 +60,93 @@ 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'); done(); }); - }).timeout(15000); + }); }); -// 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(); -// }); -// }).timeout(15000); -// }); +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(); -// }); -// }).timeout(15000); -// }); +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(); -// }); -// }).timeout(15000); -// }); +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(); -// }); -// }).timeout(15000); -// }); +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) => { @@ -151,12 +157,13 @@ describe('Signin Errror', () => { .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(); }); - }).timeout(15000); + }); }); describe('Signin Error', () => { @@ -168,30 +175,32 @@ describe('Signin Error', () => { .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(); }); - }).timeout(15000); + }); }); -// 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(); -// }); -// }).timeout(15000); -// }); +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 b53768b..189a0b8 100644 --- a/src/test/courseTest.js +++ b/src/test/courseTest.js @@ -1,16 +1,16 @@ -import chai from 'chai'; -import chaiHttp from 'chai-http'; -import app from '../app'; -import Utils from '../utils'; +// import chai from 'chai'; +// import chaiHttp from 'chai-http'; +// import app from '../app'; +// import Utils from '../utils'; -chai.should(); +// chai.should(); -chai.use(chaiHttp); +// chai.use(chaiHttp); -const apiEndPoint = '/api/v1/'; -const adminEmail = 'victorawotidebe@gmail.com'; +// const apiEndPoint = '/api/v1/'; +// const adminEmail = 'victorawotidebe@gmail.com'; // const notAdminEmail = 'rmissen0@adobe.com'; -const token = Utils.generateToken({ email: adminEmail }); +// const token = Utils.generateToken({ email: adminEmail }); // const nonAdminToken = Utils.generateToken({ email: notAdminEmail }); // describe('Create Courses Tests', () => { @@ -72,133 +72,133 @@ const token = Utils.generateToken({ email: adminEmail }); // }).timeout(15000); // }); -describe('Create Courses Tests', () => { - it('Should return 401 if token is not provided', (done) => { - const course = { - courseTitle: 'Facility Management', - memberFees: 105000, - nonMemberFees: 115000, - startDate: 10, - endDate: 13, - }; - chai - .request(app) - .post(`${apiEndPoint}courses`) - .send(course) - .end((err, res) => { - res.should.have.status(401); - res.body.should.be.a('object'); - res.body.should.have.property('error'); - done(); - }); - }).timeout(15000); -}); +// describe('Create Courses Tests', () => { +// it('Should return 401 if token is not provided', (done) => { +// const course = { +// courseTitle: 'Facility Management', +// memberFees: 105000, +// nonMemberFees: 115000, +// startDate: 10, +// endDate: 13, +// }; +// chai +// .request(app) +// .post(`${apiEndPoint}courses`) +// .send(course) +// .end((err, res) => { +// res.should.have.status(401); +// res.body.should.be.a('object'); +// 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(); - }); - }).timeout(15000); -}); +// 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(); - }); - }).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(); +// }); +// }).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(); - }); - }).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(); +// }); +// }).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(); - }); - }).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(); +// }); +// }).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(); - }); - }).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(); +// }); +// }).timeout(15000); +// }); // describe('Get requests for both user and admin', () => { // it('should return 200 and get all courses', (done) => { From 74e0a2a7a66b0d906dab9a1afa6d4a5265ec9f5e Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Sun, 25 Oct 2020 17:33:33 +0100 Subject: [PATCH 8/9] test files updated --- package.json | 2 +- src/test/courseTest.js | 460 ++++++++++++++++++++--------------------- 2 files changed, 231 insertions(+), 231 deletions(-) diff --git a/package.json b/package.json index 0ffc139..e951054 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 100000", + "test": " set NODE_ENV=test&& npm run reset-db&& nyc mocha --timeout 10000 -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/courseTest.js b/src/test/courseTest.js index 189a0b8..f1c86ab 100644 --- a/src/test/courseTest.js +++ b/src/test/courseTest.js @@ -1,245 +1,245 @@ -// import chai from 'chai'; -// import chaiHttp from 'chai-http'; -// import app from '../app'; -// import Utils from '../utils'; +import chai from 'chai'; +import chaiHttp from 'chai-http'; +import app from '../app'; +import Utils from '../utils'; -// chai.should(); +chai.should(); -// chai.use(chaiHttp); +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 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 }); -// 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(); -// }); -// }).timeout(15000); -// }); + 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(); -// }); -// }).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(); + }); + }).timeout(15000); +}); -// describe('Create Courses Tests', () => { -// it('Should return 401 if token is not provided', (done) => { -// const course = { -// courseTitle: 'Facility Management', -// memberFees: 105000, -// nonMemberFees: 115000, -// startDate: 10, -// endDate: 13, -// }; -// chai -// .request(app) -// .post(`${apiEndPoint}courses`) -// .send(course) -// .end((err, res) => { -// res.should.have.status(401); -// res.body.should.be.a('object'); -// res.body.should.have.property('error'); -// done(); -// }); -// }).timeout(15000); -// }); +describe('Create Courses Tests', () => { + it('Should return 401 if token is not provided', (done) => { + const course = { + courseTitle: 'Facility Management', + memberFees: 105000, + nonMemberFees: 115000, + startDate: 10, + endDate: 13, + }; + chai + .request(app) + .post(`${apiEndPoint}courses`) + .send(course) + .end((err, res) => { + res.should.have.status(401); + res.body.should.be.a('object'); + 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(); -// }); -// }).timeout(15000); -// }); + 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(); -// }); -// }).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(); + }); + }).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(); -// }); -// }).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(); + }); + }).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(); -// }); -// }).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(); + }); + }).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(); -// }); -// }).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(); + }); + }).timeout(15000); +}); -// 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('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(); -// }); -// }).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(); + }); + }).timeout(15000); +}); From 8781ff764120df60755851b1c4070e68ae20e7f7 Mon Sep 17 00:00:00 2001 From: temisan otokuefor Date: Wed, 28 Oct 2020 01:49:15 +0100 Subject: [PATCH 9/9] new update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e951054..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 --timeout 10000 -r @babel/register --recursive src/test/ --exit", + "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",