Skip to content

Commit

Permalink
Added tests and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgiffy committed Mar 6, 2019
1 parent c27e5ba commit 144cddd
Show file tree
Hide file tree
Showing 12 changed files with 421 additions and 50 deletions.
2 changes: 1 addition & 1 deletion routes/api/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ router.get('/get/:id', (req, res, next) => {
router.post('/filter', (req, res) => {
Activity.find(res.body, (err, activities) => {
if (err) return res.json({ success: false, error: err });
return res.json(activities);
return res.json({ success: true, data: activities });
});
});

Expand Down
2 changes: 1 addition & 1 deletion routes/api/admins.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ router.post('/get', (req, res) => {
router.post('/filter', (req, res) => {
Admin.find(res.body, (err, admins) => {
if (err) return res.json({ success: false, error: err });
return res.json(admins);
return res.json({ success: true, data: admins });
});
});

Expand Down
2 changes: 1 addition & 1 deletion routes/api/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ router.post('/get', (req, res) => {
router.post('/filter', (req, res) => {
Member.find(req.body, (err, members) => {
if (err) return res.json({ success: false, error: err });
return res.json(members);
return res.json({ success: true, data: members });
});
});

Expand Down
2 changes: 1 addition & 1 deletion routes/api/seniorCenters.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ router.get('/get/:id', (req, res) => {
router.post('/filter', (req, res) => {
SeniorCenter.find(res.body, (err, seniorCenters) => {
if (err) return res.json({ success: false, error: err });
return res.json(seniorCenters);
return res.json({ success: true, data: seniorCenters });
});
});

Expand Down
4 changes: 2 additions & 2 deletions routes/api/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ router.get('/get/:id', (req, res, next) => {
router.post('/filter', (req, res) => {
Service.find(res.body, (err, services) => {
if (err) return res.json({ success: false, error: err });
return res.json(services);
return res.json({ success: true, data: services });
});
});

Expand All @@ -63,7 +63,7 @@ router.post('/add', (req, res) => {
const newService = new Service({
name: req.body.name,
time: req.body.time,
duration: req.body.time,
duration: req.body.duration,
date: req.body.date,
admins: req.body.admins,
volunteers: req.body.volunteers,
Expand Down
2 changes: 1 addition & 1 deletion routes/api/volunteers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ router.delete('/delete/:id', (req, res) => {
router.post('/filter', (req, res) => {
Volunteer.find(res.body, (err, volunteers) => {
if (err) return res.json({ success: false, error: err });
return res.json(volunteers);
return res.json({ success: true, data: volunteers });
});
});

Expand Down
64 changes: 60 additions & 4 deletions test/activites_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ after(function() {

describe('Activities suite /ADD, /GET, /GET/:ID,/DELETE', () => {
it('it should add a new service', done => {
let testActivity = {
let testActivity1 = {
name: 'ice climbing',
time: '10AM-12PM',
duration: '2 Hours',
Expand All @@ -41,12 +41,35 @@ describe('Activities suite /ADD, /GET, /GET/:ID,/DELETE', () => {
seniorCenter: 'The one around the corner'
};

let testActivity2 = {
name: 'skiing',
time: '10AM-12PM',
duration: '6 Hours',
date: 'Sunday',
admins: '11234',
volunteers: 'The Dude',
members: 'Karin',
seniorCenter: 'Good one'
};
chai.request(server)
.post('/api/activities/add')
.send(testActivity1)
.end();

chai.request(server)
.post('/api/activities/add')
.send(testActivity)
.send(testActivity2)
.end((err, res) => {
res.should.have.status(200);

res.body.should.have.property('_id');
res.body.should.have.property('name').eql('skiing');
res.body.should.have.property('time').eql('10AM-12PM');
res.body.should.have.property('duration').eql('6 Hours');
res.body.should.have.property('date').eql('Sunday');
res.body.should.have.property('admins').eql(['11234']);
res.body.should.have.property('volunteers').eql(['The Dude']);
res.body.should.have.property('members').eql(['Karin']);
res.body.should.have.property('seniorCenter').eql('Good one');
done();
});
});
Expand All @@ -58,6 +81,24 @@ describe('Activities suite /ADD, /GET, /GET/:ID,/DELETE', () => {
res.should.have.status(200);
res.body.should.have.property('success').eql(true);
tempId = res.body.data[0]._id;
res.body.data[1].should.have.property('_id');
res.body.data[1].should.have.property('name').eql('skiing');
res.body.data[1].should.have.property('time').eql('10AM-12PM');
res.body.data[1].should.have.property('duration').eql('6 Hours');
res.body.data[1].should.have.property('date').eql('Sunday');
res.body.data[1].should.have.property('admins').eql(['11234']);
res.body.data[1].should.have.property('volunteers').eql(['The Dude']);
res.body.data[1].should.have.property('members').eql(['Karin']);
res.body.data[1].should.have.property('seniorCenter').eql('Good one');

res.body.data[0].should.have.property('name').eql('ice climbing');
res.body.data[0].should.have.property('time').eql('10AM-12PM');
res.body.data[0].should.have.property('duration').eql('2 Hours');
res.body.data[0].should.have.property('date').eql('Saturday');
res.body.data[0].should.have.property('admins').eql(['Bill']);
res.body.data[0].should.have.property('volunteers').eql(['Sandy']);
res.body.data[0].should.have.property('members').eql(['Peepsuuu']);
res.body.data[0].should.have.property('seniorCenter').eql('The one around the corner');
done();
});
});
Expand All @@ -67,6 +108,14 @@ describe('Activities suite /ADD, /GET, /GET/:ID,/DELETE', () => {
.get('/api/activities/get/' + tempId)
.end((err, res) => {
res.should.have.status(200);
res.body.should.have.property('name').eql('ice climbing');
res.body.should.have.property('time').eql('10AM-12PM');
res.body.should.have.property('duration').eql('2 Hours');
res.body.should.have.property('date').eql('Saturday');
res.body.should.have.property('admins').eql(['Bill']);
res.body.should.have.property('volunteers').eql(['Sandy']);
res.body.should.have.property('members').eql(['Peepsuuu']);
res.body.should.have.property('seniorCenter').eql('The one around the corner');
done();
});
});
Expand All @@ -80,7 +129,14 @@ describe('Activities suite /ADD, /GET, /GET/:ID,/DELETE', () => {
.send(request)
.end((err, res) => {
res.should.have.status(200);

res.body.data[0].should.have.property('name').eql('ice climbing');
res.body.data[0].should.have.property('time').eql('10AM-12PM');
res.body.data[0].should.have.property('duration').eql('2 Hours');
res.body.data[0].should.have.property('date').eql('Saturday');
res.body.data[0].should.have.property('admins').eql(['Bill']);
res.body.data[0].should.have.property('volunteers').eql(['Sandy']);
res.body.data[0].should.have.property('members').eql(['Peepsuuu']);
res.body.data[0].should.have.property('seniorCenter').eql('The one around the corner');
done();
});
});
Expand Down
57 changes: 53 additions & 4 deletions test/admin_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ after(function() {

describe('Admin API suite /GET,/REGISTER,/GET/:ID,/LOGIN,/DELETE admins', () => {
it('it should create a new admin', done => {
var admin = {
const admin1 = {
firstName: 'testy',
lastName: 'boy',
email: 'test@gmail.com',
Expand All @@ -40,12 +40,30 @@ describe('Admin API suite /GET,/REGISTER,/GET/:ID,/LOGIN,/DELETE admins', () =>
superAdmin: true
};

const admin2 = {
firstName: 'testy',
lastName: 'boy2',
email: 'test2@gmail.com',
password: 'greatpassword2!@',
password2: 'greatpassword2!@',
seniorCenter: 'test center2'
};

chai.request(server)
.post('/api/admins/register')
.send(admin)
.send(admin2)
.end();

chai.request(server)
.post('/api/admins/register')
.send(admin1)
.end((err, res) => {
res.should.have.status(200);

res.body.should.have.property('_id');
res.body.should.have.property('firstName').eql('testy');
res.body.should.have.property('lastName').eql('boy');
res.body.should.have.property('email').eql('test@gmail.com');
res.body.should.have.property('seniorCenter').eql('test center');
done();
});
});
Expand All @@ -61,6 +79,7 @@ describe('Admin API suite /GET,/REGISTER,/GET/:ID,/LOGIN,/DELETE admins', () =>
.end((err, res) => {
res.should.have.status(200);
res.body.should.have.property('success').eql(true);
res.body.should.have.property('token');

done();
});
Expand All @@ -72,7 +91,24 @@ describe('Admin API suite /GET,/REGISTER,/GET/:ID,/LOGIN,/DELETE admins', () =>
.end((err, res) => {
res.should.have.status(200);
res.body.should.have.property('success').eql(true);
tempId = res.body.data[0]._id;
tempId = res.body.data[1]._id;
res.body.should.have.property('data');
res.body.data[1].should.have.property('_id');
res.body.data[1].should.have.property('firstName').eql('testy');
res.body.data[1].should.have.property('lastName').eql('boy');
res.body.data[1].should.have.property('email').eql('test@gmail.com');
res.body.data[1].should.have.property('password');
res.body.data[1].should.have.property('superAdmin').eql(true);
res.body.data[1].should.have.property('seniorCenter').eql('test center');

res.body.data[0].should.have.property('_id');
res.body.data[0].should.have.property('firstName').eql('testy');
res.body.data[0].should.have.property('lastName').eql('boy2');
res.body.data[0].should.have.property('email').eql('test2@gmail.com');
res.body.data[0].should.have.property('password');
res.body.data[0].should.have.property('superAdmin').eql(false);
res.body.data[0].should.have.property('seniorCenter').eql('test center2');

done();
});
});
Expand All @@ -82,6 +118,12 @@ describe('Admin API suite /GET,/REGISTER,/GET/:ID,/LOGIN,/DELETE admins', () =>
.get('/api/admins/get/' + tempId)
.end((err, res) => {
res.should.have.status(200);
res.body.should.not.have.property('data');
res.body.should.have.property('_id');
res.body.should.have.property('firstName').eql('testy');
res.body.should.have.property('lastName').eql('boy');
res.body.should.have.property('email').eql('test@gmail.com');
res.body.should.have.property('seniorCenter').eql('test center');
done();
});
});
Expand All @@ -108,6 +150,13 @@ describe('Admin API suite /GET,/REGISTER,/GET/:ID,/LOGIN,/DELETE admins', () =>
.send(request)
.end((err, res) => {
res.should.have.status(200);
res.body.data[0].should.have.property('_id');
res.body.data[0].should.have.property('firstName').eql('testy');
res.body.data[0].should.have.property('lastName').eql('boy2');
res.body.data[0].should.have.property('email').eql('test2@gmail.com');
res.body.data[0].should.have.property('password');
res.body.data[0].should.have.property('superAdmin').eql(false);
res.body.data[0].should.have.property('seniorCenter');
done();
});
});
Expand Down

0 comments on commit 144cddd

Please sign in to comment.