From 7aa5bb68930bb848b4f85a4f0577d95f60b0a8df Mon Sep 17 00:00:00 2001 From: Gavriel R-H Date: Fri, 17 Jan 2020 13:32:33 -0500 Subject: [PATCH 1/3] Update chai tests to use return Promise syntax to avoid done() timeout pitfalls (#102) --- routes/events.js | 2 +- test/routes/auth.js | 25 +++--- test/routes/committees.js | 35 ++++----- test/routes/events.js | 154 ++++++++++++++----------------------- test/routes/memberships.js | 139 +++++++++++++-------------------- test/routes/officers.js | 113 +++++++++++---------------- test/routes/quotes.js | 25 +++--- test/routes/tags.js | 10 +-- test/routes/users.js | 65 ++++++---------- 9 files changed, 221 insertions(+), 347 deletions(-) diff --git a/routes/events.js b/routes/events.js index a356bc8..a2d0dac 100644 --- a/routes/events.js +++ b/routes/events.js @@ -35,7 +35,7 @@ router } }) .post(needs('events', 'create'), (req, res, next) => { - Event.create(req.body, { fields: ['name', 'startDate', 'endDate', 'description', 'location', 'image', 'committeeName'] }) + Event.create(req.body, { fields: ['name', 'startDate', 'endDate', 'description', 'location', 'link', 'image', 'committeeName'] }) .then(event => res.status(201).send(event)) .catch((err) => { err.status = 422; diff --git a/test/routes/auth.js b/test/routes/auth.js index 522946b..2719db3 100644 --- a/test/routes/auth.js +++ b/test/routes/auth.js @@ -10,57 +10,54 @@ import { token } from '../helpers'; describe('INTEGRATION TESTS: AUTH', function () { describe('GET /', function () { - it('Denies Unauthenticated Users', function (done) { + it('Denies Unauthenticated Users', function () { const expected = { error: 'not logged in', }; - request(app) + return request(app) .get('/api/v2/auth') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Gets the Current Logged In User', function (done) { + it('Gets the Current Logged In User', function () { const expected = { firstName: 'Test', lastName: 'User', dce: 'abc1234', }; - request(app) + return request(app) .get('/api/v2/auth') .set('Authorization', `Bearer ${token}`) .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('GET /googleClientID', function () { - it('Gets the Google Client ID', function (done) { + it('Gets the Google Client ID', function () { const expected = { token: nconf.get('auth').google.id, }; - request(app) + return request(app) .get('/api/v2/auth/googleClientID') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('POST /:provider', function () { - it('Sends a Refresh Token', function (done) { - request(app) + it('Sends a Refresh Token', function () { + return request(app) .post('/api/v2/auth/refresh') .set('Authorization', `Bearer ${token}`) .expect(200) @@ -69,22 +66,20 @@ describe('INTEGRATION TESTS: AUTH', function () { // not be the same as the original token. expect(response.body.token).to.not.be.undefined; // eslint-disable-line no-unused-expressions expect(response.body).to.not.deep.equal({ token }); - done(); }); }); - it('Does Not Support Unknown Providers', function (done) { + it('Does Not Support Unknown Providers', function () { const expected = { error: 'invalid provider', }; - request(app) + return request(app) .post('/api/v2/auth/unknown') .set('Authorization', `Bearer ${token}`) .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); diff --git a/test/routes/committees.js b/test/routes/committees.js index 4c53a69..1ff0ef3 100644 --- a/test/routes/committees.js +++ b/test/routes/committees.js @@ -9,7 +9,7 @@ import nconf from '../../config'; describe('INTEGRATION TESTS: COMMITTEES', function () { describe('GET /', function () { - it('Returns Committees', function (done) { + it('Returns Committees', function () { const expected = { total: 4, perPage: nconf.get('pagination:perPage'), @@ -42,16 +42,15 @@ describe('INTEGRATION TESTS: COMMITTEES', function () { ], }; - request(app) + return request(app) .get('/api/v2/committees') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by an Existing Name', function (done) { + it('Filters by an Existing Name', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -66,16 +65,15 @@ describe('INTEGRATION TESTS: COMMITTEES', function () { ], }; - request(app) + return request(app) .get('/api/v2/committees?name=Technology') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by an Non-existent Name', function (done) { + it('Filters by an Non-existent Name', function () { const expected = { total: 0, perPage: nconf.get('pagination:perPage'), @@ -83,16 +81,15 @@ describe('INTEGRATION TESTS: COMMITTEES', function () { data: [], }; - request(app) + return request(app) .get('/api/v2/committees?name=Nope') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Active', function (done) { + it('Filters by Active', function () { const expected = { total: 2, perPage: nconf.get('pagination:perPage'), @@ -113,17 +110,16 @@ describe('INTEGRATION TESTS: COMMITTEES', function () { ], }; - request(app) + return request(app) .get(`/api/v2/committees?active=${encodeURIComponent('2017-12-05T05:00:00.000Z')}`) .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); // See: https://github.com/rit-sse/node-api/issues/67 - it('Filters by Active When Multiple Officers Are Assigned to the Same Committee', function (done) { + it('Filters by Active When Multiple Officers Are Assigned to the Same Committee', function () { const expected = { total: 2, perPage: nconf.get('pagination:perPage'), @@ -144,18 +140,17 @@ describe('INTEGRATION TESTS: COMMITTEES', function () { ], }; - request(app) + return request(app) .get(`/api/v2/committees?active=${encodeURIComponent('2017-01-05T05:00:00.000Z')}`) .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('GET /:id', function () { - it('Finds a Specific Committee', function (done) { + it('Finds a Specific Committee', function () { const expected = { name: 'Technology', description: 'tech', @@ -163,26 +158,24 @@ describe('INTEGRATION TESTS: COMMITTEES', function () { updatedAt: '2017-12-01T05:00:00.000Z', }; - request(app) + return request(app) .get('/api/v2/committees/Technology') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Does Not Find a Committee That Does Not Exist', function (done) { + it('Does Not Find a Committee That Does Not Exist', function () { const expected = { error: 'Committee not found', }; - request(app) + return request(app) .get('/api/v2/committees/Nope') .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); diff --git a/test/routes/events.js b/test/routes/events.js index a8928eb..210d1e4 100644 --- a/test/routes/events.js +++ b/test/routes/events.js @@ -16,7 +16,7 @@ import { describe('INTEGRATION TESTS: EVENTS', function () { describe('GET /', function () { - it('Returns Events When Accepting JSON', function (done) { + it('Returns Events When Accepting JSON', function () { const expected = { total: 3, perPage: nconf.get('pagination:perPage'), @@ -82,12 +82,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { Promise.all([ nakedURL, jsonExtension, - ]).then(() => { - done(); - }); + ]); }); - it('Filters by an Existing Name', function (done) { + it('Filters by an Existing Name', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -116,11 +114,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { delete event.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by an Non-existent Name', function (done) { + it('Filters by an Non-existent Name', function () { const expected = { total: 0, perPage: nconf.get('pagination:perPage'), @@ -133,11 +130,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by an Existing Committee', function (done) { + it('Filters by an Existing Committee', function () { const expected = { total: 2, perPage: nconf.get('pagination:perPage'), @@ -166,7 +162,7 @@ describe('INTEGRATION TESTS: EVENTS', function () { ], }; - request(app) + return request(app) .get('/api/v2/events?committee=Talks') .expect(200) .then((response) => { @@ -176,11 +172,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { delete event.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by an Non-existent Committee', function (done) { + it('Filters by an Non-existent Committee', function () { const expected = { total: 0, perPage: nconf.get('pagination:perPage'), @@ -188,16 +183,15 @@ describe('INTEGRATION TESTS: EVENTS', function () { data: [], }; - request(app) + return request(app) .get('/api/v2/events?committee=Unknown') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by an Existing Location', function (done) { + it('Filters by an Existing Location', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -216,7 +210,7 @@ describe('INTEGRATION TESTS: EVENTS', function () { ], }; - request(app) + return request(app) .get('/api/v2/events?location=GOL-1440') .expect(200) .then((response) => { @@ -226,11 +220,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { delete event.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by an Non-existent Location', function (done) { + it('Filters by an Non-existent Location', function () { const expected = { total: 0, perPage: nconf.get('pagination:perPage'), @@ -238,16 +231,15 @@ describe('INTEGRATION TESTS: EVENTS', function () { data: [], }; - request(app) + return request(app) .get('/api/v2/events?location=Unknown') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Between', function (done) { + it('Filters by Between', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -266,7 +258,7 @@ describe('INTEGRATION TESTS: EVENTS', function () { ], }; - request(app) + return request(app) .get(`/api/v2/events?between=${encodeURIComponent('2017-07-01T05:00:00.000Z')}/${encodeURIComponent('2017-11-01T05:00:00.000Z')}`) .expect(200) .then((response) => { @@ -276,11 +268,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { delete event.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Before', function (done) { + it('Filters by Before', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -299,7 +290,7 @@ describe('INTEGRATION TESTS: EVENTS', function () { ], }; - request(app) + return request(app) .get(`/api/v2/events?before=${encodeURIComponent('2017-07-01T05:00:00.000Z')}`) .expect(200) .then((response) => { @@ -309,11 +300,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { delete event.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by After', function (done) { + it('Filters by After', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -332,7 +322,7 @@ describe('INTEGRATION TESTS: EVENTS', function () { ], }; - request(app) + return request(app) .get(`/api/v2/events?after=${encodeURIComponent('2017-11-01T05:00:00.000Z')}`) .expect(200) .then((response) => { @@ -342,11 +332,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { delete event.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Featured', function (done) { + it('Filters by Featured', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -365,7 +354,7 @@ describe('INTEGRATION TESTS: EVENTS', function () { ], }; - request(app) + return request(app) .get('/api/v2/events?featured') .expect(200) .then((response) => { @@ -375,11 +364,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { delete event.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Sort', function (done) { + it('Filters by Sort', function () { const expected = { total: 3, perPage: nconf.get('pagination:perPage'), @@ -418,7 +406,7 @@ describe('INTEGRATION TESTS: EVENTS', function () { ], }; - request(app) + return request(app) .get('/api/v2/events?sort=DESC') .expect(200) .then((response) => { @@ -428,11 +416,10 @@ describe('INTEGRATION TESTS: EVENTS', function () { delete event.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Returns a Calendar Event When Accepting ICS', function (done) { + it('Returns a Calendar Event When Accepting ICS', function () { const expected = `BEGIN:VCALENDAR CALSCALE:GREGORIAN @@ -492,46 +479,42 @@ END:VCALENDAR`; expect(response.text).to.deep.equal(expected); }); - Promise.all([ + return Promise.all([ nakedURL, icsExtension, - ]).then(() => { - done(); - }); + ]); }); - it('Does Not Accept Requests Not Accepting JSON or ICS', function (done) { + it('Does Not Accept Requests Not Accepting JSON or ICS', function () { const expected = { error: 'xml is not acceptable', }; - request(app) + return request(app) .get('/api/v2/events') .set('accept', 'xml') .expect(406) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('POST /', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .post('/api/v2/events') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need Low Permissions be an Officer or Primary Officer const expected = { error: 'User does not have permission: create events', @@ -566,16 +549,14 @@ END:VCALENDAR`; .send(eventInput) .expect(201); - Promise.all([ + return Promise.all([ userHigh, primaryLow, officerLow, - ]).then(() => { - done(); - }); + ]); }); - it('Creates an Event', function (done) { + it('Creates an Event', function () { const expected = { name: 'A Cool Talk', committeeName: 'Talks', @@ -587,7 +568,7 @@ END:VCALENDAR`; link: null, }; - request(app) + return request(app) .post('/api/v2/events') .set('Authorization', `Bearer ${token}`) .send(expected) @@ -597,16 +578,15 @@ END:VCALENDAR`; delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Start Date to be Before End Date', function (done) { + it('Requires Start Date to be Before End Date', function () { const expected = { error: 'Validation error: Start date must be before the end date', }; - request(app) + return request(app) .post('/api/v2/events') .set('Authorization', `Bearer ${token}`) .send({ @@ -619,29 +599,27 @@ END:VCALENDAR`; .expect(422) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Errors When Insufficient Fields Provided', function (done) { + it('Errors When Insufficient Fields Provided', function () { const expected = { error: 'notNull Violation: name cannot be null,\nnotNull Violation: startDate cannot be null,\nnotNull Violation: endDate cannot be null,\nnotNull Violation: location cannot be null', }; - request(app) + return request(app) .post('/api/v2/events') .set('Authorization', `Bearer ${token}`) .send({}) .expect(422) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('GET /:id', function () { - it('Gets a Specific Event', function (done) { + it('Gets a Specific Event', function () { const expected = { id: 1, name: 'Review Session', @@ -654,7 +632,7 @@ END:VCALENDAR`; description: null, }; - request(app) + return request(app) .get('/api/v2/events/1') .set('Authorization', `Bearer ${token}`) .expect(200) @@ -662,42 +640,39 @@ END:VCALENDAR`; delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Does Not Find a Non-existent Event', function (done) { + it('Does Not Find a Non-existent Event', function () { const expected = { error: 'Event not found', }; - request(app) + return request(app) .get('/api/v2/events/100') .set('Authorization', `Bearer ${token}`) .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('PUT /:id', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .put('/api/v2/events/1') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need High Permissions be an Officer or Primary Officer const expected = { error: 'User does not have permission: update events', @@ -744,18 +719,16 @@ END:VCALENDAR`; .send(eventInput) .expect(200); - Promise.all([ + return Promise.all([ primaryLow, officerLow, userHigh, primaryHigh, officerHigh, - ]).then(() => { - done(); - }); + ]); }); - it('Updates a Specific Event', function (done) { + it('Updates a Specific Event', function () { const expected = { id: 1, name: 'Lunch and Learn', @@ -768,7 +741,7 @@ END:VCALENDAR`; image: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', }; - request(app) + return request(app) .put('/api/v2/events/1') .set('Authorization', `Bearer ${token}`) .send({ @@ -779,42 +752,39 @@ END:VCALENDAR`; delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Does Not Find and Update a Non-existent Event', function (done) { + it('Does Not Find and Update a Non-existent Event', function () { const expected = { error: 'Event not found', }; - request(app) + return request(app) .put('/api/v2/events/100') .set('Authorization', `Bearer ${token}`) .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('DELETE /:id', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .delete('/api/v2/events/1') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need High Permissions be an Officer or Primary Officer const expected = { error: 'User does not have permission: destroy events', @@ -855,18 +825,16 @@ END:VCALENDAR`; .set('Authorization', `Bearer ${highPermissionOfficerToken}`) .expect(204); - Promise.all([ + return Promise.all([ primaryLow, officerLow, userHigh, primaryHigh, officerHigh, - ]).then(() => { - done(); - }); + ]); }); - it('Deletes a Specific Event', function (done) { + it('Deletes a Specific Event', function () { request(app) .delete('/api/v2/events/1') .set('Authorization', `Bearer ${token}`) @@ -875,14 +843,11 @@ END:VCALENDAR`; request(app) .get('/api/v2/events/1') .set('Authorization', `Bearer ${token}`) - .expect(404) - .then(() => { - done(); - }); + .expect(404); }); }); - it('Does Not Find and Delete a Non-existent Event', function (done) { + it('Does Not Find and Delete a Non-existent Event', function () { const expected = { error: 'Event not found', }; @@ -893,7 +858,6 @@ END:VCALENDAR`; .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); diff --git a/test/routes/memberships.js b/test/routes/memberships.js index eeb1de1..e6da7d5 100644 --- a/test/routes/memberships.js +++ b/test/routes/memberships.js @@ -43,7 +43,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { }); describe('GET /', function () { - it('Gets Approved Memberships', function (done) { + it('Gets Approved Memberships', function () { const expected = { total: 2, perPage: nconf.get('pagination:perPage'), @@ -84,7 +84,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { ], }; - request(app) + return request(app) .get('/api/v2/memberships') .expect(200) .then((response) => { @@ -94,11 +94,10 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete membership.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need Low Permissions be Primary Officer for Pending and Denied const expected = { error: 'User does not have permission: unapproved memberships', @@ -156,7 +155,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { .get('/api/v2/memberships') .expect(200); - Promise.all([ + return Promise.all([ officerHigh, userHigh, primaryHigh, @@ -164,12 +163,10 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { userHigh2, primaryHigh2, anyone, - ]).then(() => { - done(); - }); + ]); }); - it('Filters by Reason', function (done) { + it('Filters by Reason', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -194,7 +191,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { ], }; - request(app) + return request(app) .get(`/api/v2/memberships?reason=${encodeURIComponent('Giving a Talk')}`) .expect(200) .then((response) => { @@ -204,11 +201,10 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete membership.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Committee', function (done) { + it('Filters by Committee', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -233,7 +229,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { ], }; - request(app) + return request(app) .get('/api/v2/memberships?committee=Talks') .expect(200) .then((response) => { @@ -243,11 +239,10 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete membership.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by User', function (done) { + it('Filters by User', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -272,7 +267,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { ], }; - request(app) + return request(app) .get('/api/v2/memberships?user=axy9999') .expect(200) .then((response) => { @@ -282,11 +277,10 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete membership.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Active (and Approved)', function (done) { + it('Filters by Active (and Approved)', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -311,7 +305,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { ], }; - request(app) + return request(app) .get(`/api/v2/memberships?active=${encodeURIComponent('2017-11-01T05:00:00.000Z')}`) .set('Authorization', `Bearer ${token}`) .expect(200) @@ -322,11 +316,10 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete membership.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Between Start Date (and Approved)', function (done) { + it('Filters by Between Start Date (and Approved)', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -351,7 +344,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { ], }; - request(app) + return request(app) .get(`/api/v2/memberships?between=${encodeURIComponent('2017-05-01T05:00:00.000Z')}/${encodeURIComponent('2017-09-01T05:00:00.000Z')}`) .set('Authorization', `Bearer ${token}`) .expect(200) @@ -362,11 +355,10 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete membership.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Pending', function (done) { + it('Filters by Pending', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -391,7 +383,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { ], }; - request(app) + return request(app) .get('/api/v2/memberships?approved=null') .set('Authorization', `Bearer ${token}`) .expect(200) @@ -402,11 +394,10 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete membership.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Denied', function (done) { + it('Filters by Denied', function () { const expected = { total: 0, perPage: nconf.get('pagination:perPage'), @@ -414,33 +405,31 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { data: [], }; - request(app) + return request(app) .get('/api/v2/memberships?approved=false') .set('Authorization', `Bearer ${token}`) .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('POST /', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .post('/api/v2/memberships') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need Low Permissions be an Officer or Primary Officer const expected = { error: 'User does not have permission: create memberships', @@ -475,16 +464,14 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { .send(membershipInput) .expect(201); - Promise.all([ + return Promise.all([ userHigh, primaryLow, officerLow, - ]).then(() => { - done(); - }); + ]); }); - it('Creates a Membership', function (done) { + it('Creates a Membership', function () { const expected = { reason: 'A Nice Person', startDate: '2017-06-15T05:00:00.000Z', @@ -502,7 +489,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { }, }; - request(app) + return request(app) .post('/api/v2/memberships') .set('Authorization', `Bearer ${token}`) .send({ @@ -518,29 +505,27 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Errors When Insufficient Fields Provided', function (done) { + it('Errors When Insufficient Fields Provided', function () { const expected = { error: 'notNull Violation: reason cannot be null', }; - request(app) + return request(app) .post('/api/v2/memberships') .set('Authorization', `Bearer ${token}`) .send({}) .expect(422) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('GET /:id', function () { - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need Low Permissions be Primary Officer const expected = { error: 'User does not have permission: unapproved memberships', @@ -568,16 +553,14 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { .set('Authorization', `Bearer ${token}`) .expect(200); - Promise.all([ + return Promise.all([ officerHigh, userHigh, primaryHigh, - ]).then(() => { - done(); - }); + ]); }); - it('Gets a Specific Membership', function (done) { + it('Gets a Specific Membership', function () { const expected = { id: 2, reason: 'Helping Out', @@ -596,7 +579,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { }, }; - request(app) + return request(app) .get('/api/v2/memberships/2') .set('Authorization', `Bearer ${token}`) .expect(200) @@ -604,42 +587,39 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Does Not Find a Non-existent Membership', function (done) { + it('Does Not Find a Non-existent Membership', function () { const expected = { error: 'Membership not found', }; - request(app) + return request(app) .get('/api/v2/memberships/100') .set('Authorization', `Bearer ${token}`) .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('PUT /:id', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .put('/api/v2/memberships/1') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need Low Permissions be Primary Officer const expected = { error: 'User does not have permission: update memberships', @@ -672,16 +652,14 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { .send(membershipInput) .expect(200); - Promise.all([ + return Promise.all([ officerHigh, userHigh, primaryHigh, - ]).then(() => { - done(); - }); + ]); }); - it('Updates a Specific Membership', function (done) { + it('Updates a Specific Membership', function () { const expected = { id: 2, reason: 'Because', @@ -700,7 +678,7 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { }, }; - request(app) + return request(app) .put('/api/v2/memberships/2') .set('Authorization', `Bearer ${token}`) .send({ @@ -711,42 +689,39 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Does Not Find and Update a Non-existent Membership', function (done) { + it('Does Not Find and Update a Non-existent Membership', function () { const expected = { error: 'Membership not found', }; - request(app) + return request(app) .put('/api/v2/memberships/100') .set('Authorization', `Bearer ${token}`) .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('DELETE /:id', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .delete('/api/v2/memberships/1') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need High Permissions be Primary Officer const expected = { error: 'User does not have permission: destroy memberships', @@ -782,18 +757,16 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { .set('Authorization', `Bearer ${token}`) .expect(204); - Promise.all([ + return Promise.all([ primaryLow, officerHigh, userHigh, primaryHigh, - ]).then(() => { - done(); - }); + ]); }); - it('Deletes a Specific Membership', function (done) { - request(app) + it('Deletes a Specific Membership', function () { + return request(app) .delete('/api/v2/memberships/1') .set('Authorization', `Bearer ${token}`) .expect(204) @@ -801,25 +774,21 @@ describe('INTEGRATION TESTS: MEMBERSHIPS', function () { request(app) .get('/api/v2/memberships/1') .set('Authorization', `Bearer ${token}`) - .expect(404) - .then(() => { - done(); - }); + .expect(404); }); }); - it('Does Not Find and Delete a Non-existent Membership', function (done) { + it('Does Not Find and Delete a Non-existent Membership', function () { const expected = { error: 'Membership not found', }; - request(app) + return request(app) .delete('/api/v2/memberships/100') .set('Authorization', `Bearer ${token}`) .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); diff --git a/test/routes/officers.js b/test/routes/officers.js index 39d8bd9..58db821 100644 --- a/test/routes/officers.js +++ b/test/routes/officers.js @@ -15,7 +15,7 @@ import { describe('INTEGRATION TESTS: OFFICERS', function () { describe('GET /', function () { - it('Gets Officers', function (done) { + it('Gets Officers', function () { const expected = { total: 5, perPage: nconf.get('pagination:perPage'), @@ -109,7 +109,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { ], }; - request(app) + return request(app) .get('/api/v2/officers') .expect(200) .then((response) => { @@ -119,11 +119,10 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete officer.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Title', function (done) { + it('Filters by Title', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -149,7 +148,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { ], }; - request(app) + return request(app) .get(`/api/v2/officers?title=${encodeURIComponent('Art Head')}`) .expect(200) .then((response) => { @@ -159,11 +158,10 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete officer.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Email', function (done) { + it('Filters by Email', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -189,7 +187,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { ], }; - request(app) + return request(app) .get('/api/v2/officers?email=art') .expect(200) .then((response) => { @@ -199,11 +197,10 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete officer.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by User', function (done) { + it('Filters by User', function () { const expected = { total: 2, perPage: nconf.get('pagination:perPage'), @@ -246,7 +243,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { ], }; - request(app) + return request(app) .get('/api/v2/officers?user=br4321') .expect(200) .then((response) => { @@ -256,11 +253,10 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete officer.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Primary', function (done) { + it('Filters by Primary', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -286,7 +282,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { ], }; - request(app) + return request(app) .get('/api/v2/officers?primary=true') .expect(200) .then((response) => { @@ -296,11 +292,10 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete officer.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Committee', function (done) { + it('Filters by Committee', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -326,7 +321,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { ], }; - request(app) + return request(app) .get('/api/v2/officers?committee=Technology') .expect(200) .then((response) => { @@ -336,11 +331,10 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete officer.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Active', function (done) { + it('Filters by Active', function () { const expected = { total: 3, perPage: nconf.get('pagination:perPage'), @@ -400,7 +394,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { ], }; - request(app) + return request(app) .get(`/api/v2/officers?active=${encodeURIComponent('2017-12-05T05:00:00.000Z')}`) .expect(200) .then((response) => { @@ -410,27 +404,25 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete officer.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('POST /', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .post('/api/v2/officers') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need High Permissions be Primary Officer const expected = { error: 'User does not have permission: create officers', @@ -476,14 +468,12 @@ describe('INTEGRATION TESTS: OFFICERS', function () { .send(officerInput) .expect(201); - Promise.all([ + return Promise.all([ primaryLow, userHigh, primaryHigh, officerHigh, - ]).then(() => { - done(); - }); + ]); }); xit('Creates a New Committee if there is No Officer belonging to that Committee', function (done) { @@ -496,12 +486,12 @@ describe('INTEGRATION TESTS: OFFICERS', function () { done(); }); - it('Errors When Insufficient Fields Provided', function (done) { + it('Errors When Insufficient Fields Provided', function () { const expected = { error: 'notNull Violation: title cannot be null,\nnotNull Violation: email cannot be null', }; - request(app) + return request(app) .post('/api/v2/officers') .set('Authorization', `Bearer ${token}`) .send({ @@ -510,13 +500,12 @@ describe('INTEGRATION TESTS: OFFICERS', function () { .expect(422) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('GET /:id', function () { - it('Gets a Specific Officer', function (done) { + it('Gets a Specific Officer', function () { const expected = { id: 2, title: 'Technology Head', @@ -536,7 +525,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { }, }; - request(app) + return request(app) .get('/api/v2/officers/2') .set('Authorization', `Bearer ${token}`) .expect(200) @@ -544,42 +533,39 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Does Not Find a Non-existent Officer', function (done) { + it('Does Not Find a Non-existent Officer', function () { const expected = { error: 'Officer not found', }; - request(app) + return request(app) .get('/api/v2/officers/100') .set('Authorization', `Bearer ${token}`) .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('PUT /:id', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .put('/api/v2/officers/1') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need High Permissions be Primary Officer const expected = { error: 'User does not have permission: update officers', @@ -620,17 +606,15 @@ describe('INTEGRATION TESTS: OFFICERS', function () { .send(officerInput) .expect(200); - Promise.all([ + return Promise.all([ primaryLow, userHigh, primaryHigh, officerHigh, - ]).then(() => { - done(); - }); + ]); }); - it('Updates a Specific Officer', function (done) { + it('Updates a Specific Officer', function () { const expected = { id: 2, title: 'Best Officer', @@ -650,7 +634,7 @@ describe('INTEGRATION TESTS: OFFICERS', function () { }, }; - request(app) + return request(app) .put('/api/v2/officers/2') .set('Authorization', `Bearer ${token}`) .send({ @@ -661,42 +645,39 @@ describe('INTEGRATION TESTS: OFFICERS', function () { delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Does Not Find and Update a Non-existent Officer', function (done) { + it('Does Not Find and Update a Non-existent Officer', function () { const expected = { error: 'Officer not found', }; - request(app) + return request(app) .put('/api/v2/officers/100') .set('Authorization', `Bearer ${token}`) .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('DELETE /:id', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .delete('/api/v2/officers/1') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need High Permissions be Primary Officer const expected = { error: 'User does not have permission: destroy officers', @@ -732,18 +713,16 @@ describe('INTEGRATION TESTS: OFFICERS', function () { .set('Authorization', `Bearer ${token}`) .expect(204); - Promise.all([ + return Promise.all([ primaryLow, officerHigh, userHigh, primaryHigh, - ]).then(() => { - done(); - }); + ]); }); - it('Deletes a Specific Officer', function (done) { - request(app) + it('Deletes a Specific Officer', function () { + return request(app) .delete('/api/v2/officers/1') .set('Authorization', `Bearer ${token}`) .expect(204) @@ -751,25 +730,21 @@ describe('INTEGRATION TESTS: OFFICERS', function () { request(app) .get('/api/v2/officers/1') .set('Authorization', `Bearer ${token}`) - .expect(404) - .then(() => { - done(); - }); + .expect(404); }); }); - it('Does Not Find and Delete a Non-existent Officer', function (done) { + it('Does Not Find and Delete a Non-existent Officer', function () { const expected = { error: 'Officer not found', }; - request(app) + return request(app) .delete('/api/v2/officers/100') .set('Authorization', `Bearer ${token}`) .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); diff --git a/test/routes/quotes.js b/test/routes/quotes.js index d3434f5..9024634 100644 --- a/test/routes/quotes.js +++ b/test/routes/quotes.js @@ -16,7 +16,7 @@ import { describe('INTEGRATION TESTS: QUOTES', function () { describe('GET /', function () { - it('Gets Approved Quotes (In Descending Order)', function (done) { + it('Gets Approved Quotes (In Descending Order)', function () { const expected = { total: 3, perPage: nconf.get('pagination:perPage'), @@ -43,7 +43,7 @@ describe('INTEGRATION TESTS: QUOTES', function () { ], }; - request(app) + return request(app) .get('/api/v2/qdb/quotes') .expect(200) .then((response) => { @@ -56,7 +56,6 @@ describe('INTEGRATION TESTS: QUOTES', function () { }); }); expect(response.body).to.deep.equal(expected); - done(); }); }); @@ -93,17 +92,16 @@ describe('INTEGRATION TESTS: QUOTES', function () { }); describe('POST /', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .post('/api/v2/qdb/quotes') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); @@ -122,19 +120,18 @@ describe('INTEGRATION TESTS: QUOTES', function () { done(); }); - it('Errors When Insufficient Fields Provided', function (done) { + it('Errors When Insufficient Fields Provided', function () { const expected = { error: 'notNull Violation: body cannot be null', }; - request(app) + return request(app) .post('/api/v2/qdb/quotes') .set('Authorization', `Bearer ${token}`) .send({}) .expect(422) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); @@ -157,17 +154,16 @@ describe('INTEGRATION TESTS: QUOTES', function () { }); describe('PUT /:id', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .put('/api/v2/qdb/quotes/1') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); @@ -198,17 +194,16 @@ describe('INTEGRATION TESTS: QUOTES', function () { }); describe('DELETE /:id', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .delete('/api/v2/qdb/quotes/1') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); diff --git a/test/routes/tags.js b/test/routes/tags.js index 552aafe..2e5ff3e 100644 --- a/test/routes/tags.js +++ b/test/routes/tags.js @@ -9,7 +9,7 @@ import nconf from '../../config'; describe('INTEGRATION TESTS: TAGS', function () { describe('GET /', function () { - it('Gets All Tags', function (done) { + it('Gets All Tags', function () { const expected = { total: 4, perPage: nconf.get('pagination:perPage'), @@ -30,7 +30,7 @@ describe('INTEGRATION TESTS: TAGS', function () { ], }; - request(app) + return request(app) .get('/api/v2/qdb/tags') .expect(200) .then((response) => { @@ -39,11 +39,10 @@ describe('INTEGRATION TESTS: TAGS', function () { delete tag.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Gets Only Active Tags', function (done) { + it('Gets Only Active Tags', function () { const expected = { total: 3, perPage: nconf.get('pagination:perPage'), @@ -61,7 +60,7 @@ describe('INTEGRATION TESTS: TAGS', function () { ], }; - request(app) + return request(app) .get('/api/v2/qdb/tags?active=true') .expect(200) .then((response) => { @@ -70,7 +69,6 @@ describe('INTEGRATION TESTS: TAGS', function () { delete tag.updatedAt; }); expect(response.body).to.deep.equal(expected); - done(); }); }); }); diff --git a/test/routes/users.js b/test/routes/users.js index b530f99..fe443e9 100644 --- a/test/routes/users.js +++ b/test/routes/users.js @@ -16,7 +16,7 @@ import { describe('INTEGRATION TESTS: USERS', function () { describe('GET /', function () { - it('Gets Users', function (done) { + it('Gets Users', function () { const expected = { total: 5, perPage: nconf.get('pagination:perPage'), @@ -65,16 +65,15 @@ describe('INTEGRATION TESTS: USERS', function () { ], }; - request(app) + return request(app) .get('/api/v2/users') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by First Name', function (done) { + it('Filters by First Name', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -91,16 +90,15 @@ describe('INTEGRATION TESTS: USERS', function () { ], }; - request(app) + return request(app) .get('/api/v2/users?firstName=Bob') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Filters by Last Name', function (done) { + it('Filters by Last Name', function () { const expected = { total: 1, perPage: nconf.get('pagination:perPage'), @@ -117,18 +115,17 @@ describe('INTEGRATION TESTS: USERS', function () { ], }; - request(app) + return request(app) .get('/api/v2/users?lastName=Lovelace') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('GET /:dce', function () { - it('Gets a Specific User by Their DCE', function (done) { + it('Gets a Specific User by Their DCE', function () { const expected = { firstName: 'Ada', lastName: 'Lovelace', @@ -138,46 +135,43 @@ describe('INTEGRATION TESTS: USERS', function () { updatedAt: '2017-01-01T05:00:00.000Z', }; - request(app) + return request(app) .get('/api/v2/users/axy9999') .expect(200) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Does Not Find a Non-existent User', function (done) { + it('Does Not Find a Non-existent User', function () { const expected = { error: 'User not found', }; - request(app) + return request(app) .get('/api/v2/users/xxx7777') .expect(404) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); }); describe('PUT /:dce', function () { - it('Requires Authentication', function (done) { + it('Requires Authentication', function () { const expected = { error: 'No authorization token was found', }; - request(app) + return request(app) .put('/api/v2/users/abc1234') .expect(401) .then((response) => { expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Requires Expected Permissions', function (done) { + it('Requires Expected Permissions', function () { // Need High Permissions and be an Officer or Primary Officer const expected = { error: 'User does not have permission: update users', @@ -224,19 +218,17 @@ describe('INTEGRATION TESTS: USERS', function () { }) .expect(200); - Promise.all([ + return Promise.all([ primaryLow, officerLow, userHigh, primaryHigh, officerHigh, - ]).then(() => { - done(); - }); + ]); }); // TODO: Implement this functionality - it("Updates a User's First Name if Provided in the Request Body", function (done) { + it("Updates a User's First Name if Provided in the Request Body", function () { const expected = { firstName: 'Robert', lastName: 'Ross', @@ -246,7 +238,7 @@ describe('INTEGRATION TESTS: USERS', function () { updatedAt: '2016-01-01T05:00:00.000Z', // NOTE: Expected to be different }; - request(app) + return request(app) .put('/api/v2/users/br4321') .set('Authorization', `Bearer ${token}`) .send({ @@ -260,16 +252,14 @@ describe('INTEGRATION TESTS: USERS', function () { delete response.body.updatedAt; delete expected.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }) .catch(() => { console.warn('Not Implemented.'); // eslint-disable-line no-console - done(); }); }); // TODO: Implement this functionality - it("Updates a User's Last Name if Provided in the Request Body", function (done) { + it("Updates a User's Last Name if Provided in the Request Body", function () { const expected = { firstName: 'Bob', lastName: 'Roberts', @@ -279,7 +269,7 @@ describe('INTEGRATION TESTS: USERS', function () { updatedAt: '2016-01-01T05:00:00.000Z', // NOTE: Expected to be different }; - request(app) + return request(app) .put('/api/v2/users/br4321') .set('Authorization', `Bearer ${token}`) .send({ @@ -293,15 +283,13 @@ describe('INTEGRATION TESTS: USERS', function () { delete response.body.updatedAt; delete expected.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }) .catch(() => { console.warn('Not Implemented.'); // eslint-disable-line no-console - done(); }); }); - it("Updates a User's First and Last Name if they were Not Previously Defined", function (done) { + it("Updates a User's First and Last Name if they were Not Previously Defined", function () { const expected = { firstName: 'Unknown', lastName: 'Jones', @@ -309,7 +297,7 @@ describe('INTEGRATION TESTS: USERS', function () { image: null, }; - request(app) + return request(app) .put('/api/v2/users/unk0000') .set('Authorization', `Bearer ${token}`) .send({ @@ -321,11 +309,10 @@ describe('INTEGRATION TESTS: USERS', function () { delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it("Updates a User's Image", function (done) { + it("Updates a User's Image", function () { const expected = { firstName: 'Bob', lastName: 'Ross', @@ -335,7 +322,7 @@ describe('INTEGRATION TESTS: USERS', function () { updatedAt: '2016-01-01T05:00:00.000Z', // NOTE: Expected to be different }; - request(app) + return request(app) .put('/api/v2/users/br4321') .set('Authorization', `Bearer ${token}`) .send({ @@ -349,11 +336,10 @@ describe('INTEGRATION TESTS: USERS', function () { delete response.body.updatedAt; delete expected.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); - it('Creates a New User if a User with the Provided DCE Does Not Exist', function (done) { + it('Creates a New User if a User with the Provided DCE Does Not Exist', function () { const expected = { firstName: 'John', lastName: 'Renner', @@ -361,7 +347,7 @@ describe('INTEGRATION TESTS: USERS', function () { image: null, }; - request(app) + return request(app) .put('/api/v2/users/jmr2258') .set('Authorization', `Bearer ${token}`) .send({ @@ -373,7 +359,6 @@ describe('INTEGRATION TESTS: USERS', function () { delete response.body.createdAt; delete response.body.updatedAt; expect(response.body).to.deep.equal(expected); - done(); }); }); }); From b1f3dbfbc2a9ace4f27499897c12066081ffa7c4 Mon Sep 17 00:00:00 2001 From: Gavriel R-H Date: Fri, 17 Jan 2020 13:32:53 -0500 Subject: [PATCH 2/3] Exclude officer field from committee model and requests (#103) --- models/committee.js | 2 ++ routes/committees.js | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/models/committee.js b/models/committee.js index d98d172..ee67894 100644 --- a/models/committee.js +++ b/models/committee.js @@ -24,6 +24,8 @@ export default sequelize.define('committees', { return { include: [{ model: Officer.scope({ method: ['active', date] }), + attributes: [], + includeIgnoreAttributes: false, }], }; }, diff --git a/routes/committees.js b/routes/committees.js index 20c8a85..64d50da 100644 --- a/routes/committees.js +++ b/routes/committees.js @@ -13,16 +13,20 @@ router Committee .scope(scopes) .findAndCountAll() - .then(result => res.send({ - total: result.count, - perPage: req.query.perPage, - currentPage: req.query.page, - data: result.rows.map((committee) => { + .then(result => { + const uniqueCommittees = {}; + result.rows.forEach((committee) => { const c = committee.get({ plain: true }); Reflect.deleteProperty(c, 'officer'); - return c; - }), - })) + uniqueCommittees[c.name] = c; + }); + return res.send({ + total: Object.keys(uniqueCommittees).length, + perPage: req.query.perPage, + currentPage: req.query.page, + data: Object.values(uniqueCommittees), + }) + }) .catch(err => next(err)); }); From dc5f52755d34f553e1899b3ae3d7d32117d313e0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2020 13:42:46 +0000 Subject: [PATCH 3/3] Bump handlebars from 4.1.2 to 4.7.2 Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.1.2 to 4.7.2. - [Release notes](https://github.com/wycats/handlebars.js/releases) - [Changelog](https://github.com/wycats/handlebars.js/blob/master/release-notes.md) - [Commits](https://github.com/wycats/handlebars.js/compare/v4.1.2...v4.7.2) Signed-off-by: dependabot[bot] --- package-lock.json | 53 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 96fbb96..1a305de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3808,7 +3808,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -3826,11 +3827,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3843,15 +3846,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3954,7 +3960,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3964,6 +3971,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3976,17 +3984,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4003,6 +4014,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -4075,7 +4087,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -4085,6 +4098,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -4160,7 +4174,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -4190,6 +4205,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4207,6 +4223,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4245,11 +4262,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.3", - "bundled": true + "bundled": true, + "optional": true } } }, @@ -4513,6 +4532,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz", "integrity": "sha1-gTg9ctsFT8zPUzbaqQLxgvbtuyg=", + "optional": true, "requires": { "is-glob": "^2.0.0" } @@ -4912,9 +4932,9 @@ } }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.2.tgz", + "integrity": "sha512-4PwqDL2laXtTWZghzzCtunQUTLbo31pcCJrd/B/9JP8XbhVzpS5ZXuKqlOzsd1rtcaLo4KqAn8nl8mkknS4MHw==", "dev": true, "requires": { "neo-async": "^2.6.0", @@ -5526,7 +5546,8 @@ "is-extglob": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz", - "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=" + "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=", + "optional": true }, "is-finite": { "version": "1.0.2", @@ -5548,6 +5569,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz", "integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=", + "optional": true, "requires": { "is-extglob": "^1.0.0" } @@ -7862,6 +7884,7 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", + "optional": true, "requires": { "remove-trailing-separator": "^1.0.1" }