diff --git a/test/api-acceptance/admin/integrations_spec.js b/test/api-acceptance/admin/integrations_spec.js index 8c2fe2cb6a..eb6e651230 100644 --- a/test/api-acceptance/admin/integrations_spec.js +++ b/test/api-acceptance/admin/integrations_spec.js @@ -135,8 +135,8 @@ describe('Integrations API', function () { }); }); - it('Can successfully get a created integration', function (done) { - request.post(localUtils.API.getApiQuery('integrations/')) + it('Can successfully get a created integration', function () { + return request.post(localUtils.API.getApiQuery('integrations/')) .set('Origin', config.get('url')) .send({ integrations: [{ @@ -144,22 +144,18 @@ describe('Integrations API', function () { }] }) .expect(201) - .end(function (err, {body}) { - if (err) { - return done(err); - } + .then(function ({body}) { const [createdIntegration] = body.integrations; - request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) + return createdIntegration; + }) + .then((createdIntegration) => { + return request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, {body}) { - if (err) { - return done(err); - } - + .then(function ({body}) { should.equal(body.integrations.length, 1); const [integration] = body.integrations; @@ -169,13 +165,12 @@ describe('Integrations API', function () { should.equal(integration.slug, createdIntegration.slug); should.equal(integration.description, createdIntegration.description); should.equal(integration.icon_image, createdIntegration.icon_image); - done(); }); }); }); - it('Can successfully get *all* created integrations with api_keys', function (done) { - request.post(localUtils.API.getApiQuery('integrations/')) + it('Can successfully get *all* created integrations with api_keys', function () { + return request.post(localUtils.API.getApiQuery('integrations/')) .set('Origin', config.get('url')) .send({ integrations: [{ @@ -183,51 +178,40 @@ describe('Integrations API', function () { }] }) .expect(201) - .end(function (err) { - if (err) { - return done(err); - } - request.post(localUtils.API.getApiQuery('integrations/')) + .then(function () { + return request.post(localUtils.API.getApiQuery('integrations/')) .set('Origin', config.get('url')) .send({ integrations: [{ name: 'Winter-(is)-great' }] }) - .expect(201) - .end(function (err) { - if (err) { - return done(err); - } + .expect(201); + }) + .then(function () { + return request.get(localUtils.API.getApiQuery(`integrations/?include=api_keys&limit=all`)) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) + .expect(200) + .then(function ({body}) { + // This is the only page + should.equal(body.meta.pagination.page, 1); + should.equal(body.meta.pagination.pages, 1); + should.equal(body.meta.pagination.next, null); + should.equal(body.meta.pagination.prev, null); - request.get(localUtils.API.getApiQuery(`integrations/?include=api_keys&limit=all`)) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - .expect(200) - .end(function (err, {body}) { - if (err) { - return done(err); - } - - // This is the only page - should.equal(body.meta.pagination.page, 1); - should.equal(body.meta.pagination.pages, 1); - should.equal(body.meta.pagination.next, null); - should.equal(body.meta.pagination.prev, null); - - body.integrations.forEach((integration) => { - should.exist(integration.api_keys); - }); - - done(); - }); + body.integrations.forEach((integration) => { + should.exist(integration.api_keys); + }); }); }); }); - it('Can successfully edit a created integration', function (done) { - request.post(localUtils.API.getApiQuery('integrations/')) + it('Can successfully edit a created integration', function () { + let createdIntegration; + + return request.post(localUtils.API.getApiQuery('integrations/')) .set('Origin', config.get('url')) .send({ integrations: [{ @@ -235,12 +219,10 @@ describe('Integrations API', function () { }] }) .expect(201) - .end(function (err, {body}) { - if (err) { - return done(err); - } - const [createdIntegration] = body.integrations; - request.put(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) + .then(function ({body}) { + [createdIntegration] = body.integrations; + + return request.put(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) .set('Origin', config.get('url')) .send({ integrations: [{ @@ -248,35 +230,30 @@ describe('Integrations API', function () { description: 'Finally got round to writing this...' }] }) - .expect(200) - .end(function (err) { - if (err) { - return done(err); - } + .expect(200); + }) + .then(function () { + return request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) + .expect(200); + }) + .then(function ({body}) { + const [updatedIntegration] = body.integrations; - request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - .expect(200) - .end(function (err, {body}) { - if (err) { - return done(err); - } - - const [updatedIntegration] = body.integrations; - - should.equal(updatedIntegration.id, createdIntegration.id); - should.equal(updatedIntegration.name, 'Awesome Integration Name'); - should.equal(updatedIntegration.description, 'Finally got round to writing this...'); - done(); - }); - }); + should.equal(updatedIntegration.id, createdIntegration.id); + should.equal(updatedIntegration.name, 'Awesome Integration Name'); + should.equal(updatedIntegration.description, 'Finally got round to writing this...'); }); }); - it('Can successfully refresh an integration api key', function (done) { - request.post(localUtils.API.getApiQuery('integrations/?include=api_keys')) + it('Can successfully refresh an integration api key', function () { + let createdIntegration; + let apiKeys; + let adminApiKey; + + return request.post(localUtils.API.getApiQuery('integrations/?include=api_keys')) .set('Origin', config.get('url')) .send({ integrations: [{ @@ -284,60 +261,53 @@ describe('Integrations API', function () { }] }) .expect(201) - .end(function (err, {body}) { - if (err) { - return done(err); - } - const [createdIntegration] = body.integrations; - const apiKeys = createdIntegration.api_keys; - const adminApiKey = apiKeys.find(key => key.type === 'admin'); - request.post(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/api_key/${adminApiKey.id}/refresh`)) + .then(function ({body}) { + [createdIntegration] = body.integrations; + apiKeys = createdIntegration.api_keys; + adminApiKey = apiKeys.find(key => key.type === 'admin'); + + return request.post(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/api_key/${adminApiKey.id}/refresh`)) .set('Origin', config.get('url')) .send({ integrations: [{ id: createdIntegration.id }] }) + .expect(200); + }) + .then(function () { + return request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/?include=api_keys`)) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) + .expect(200); + }) + .then(function ({body}) { + const [updatedIntegration] = body.integrations; + const updatedAdminApiKey = updatedIntegration.api_keys.find(key => key.type === 'admin'); + should.equal(updatedIntegration.id, createdIntegration.id); + updatedAdminApiKey.secret.should.not.eql(adminApiKey.secret); + }) + .then(() => { + return request.get(localUtils.API.getApiQuery(`actions/?filter=resource_id:${adminApiKey.id}&include=actor`)) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err) { - if (err) { - return done(err); - } - - request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/?include=api_keys`)) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - .expect(200) - .end(function (err, {body}) { - if (err) { - return done(err); - } - - const [updatedIntegration] = body.integrations; - const updatedAdminApiKey = updatedIntegration.api_keys.find(key => key.type === 'admin'); - should.equal(updatedIntegration.id, createdIntegration.id); - updatedAdminApiKey.secret.should.not.eql(adminApiKey.secret); - request.get(localUtils.API.getApiQuery(`actions/?filter=resource_id:${adminApiKey.id}&include=actor`)) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - .expect(200) - .end(function (err, {body}) { - const actions = body.actions; - const refreshedAction = actions.find((action) => { - return action.event === 'refreshed'; - }); - should.exist(refreshedAction); - done(); - }); - }); + .then(function ({body}) { + const actions = body.actions; + const refreshedAction = actions.find((action) => { + return action.event === 'refreshed'; + }); + should.exist(refreshedAction); }); }); }); - it('Can successfully add and delete a created integrations webhooks', function (done) { - request.post(localUtils.API.getApiQuery('integrations/')) + it('Can successfully add and delete a created integrations webhooks', function () { + let createdIntegration; + + return request.post(localUtils.API.getApiQuery('integrations/')) .set('Origin', config.get('url')) .send({ integrations: [{ @@ -345,12 +315,10 @@ describe('Integrations API', function () { }] }) .expect(201) - .end(function (err, {body}) { - if (err) { - return done(err); - } - const [createdIntegration] = body.integrations; - request.put(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) + .then(function ({body}) { + [createdIntegration] = body.integrations; + + return request.put(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) .set('Origin', config.get('url')) .send({ integrations: [{ @@ -360,65 +328,48 @@ describe('Integrations API', function () { }] }] }) + .expect(200); + }) + .then(function () { + return request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/?include=webhooks`)) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) + .expect(200); + }) + .then(function ({body}) { + const [updatedIntegration] = body.integrations; + + should.equal(updatedIntegration.webhooks.length, 1); + + const webhook = updatedIntegration.webhooks[0]; + should.equal(webhook.integration_id, updatedIntegration.id); + + return request.put(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) + .set('Origin', config.get('url')) + .send({ + integrations: [{ + webhooks: [] + }] + }) + .expect(200); + }) + .then(function () { + return request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/?include=webhooks`)) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err) { - if (err) { - return done(err); - } + .then(function ({body}) { + const [updatedIntegration] = body.integrations; - request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/?include=webhooks`)) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - .expect(200) - .end(function (err, {body}) { - if (err) { - return done(err); - } - - const [updatedIntegration] = body.integrations; - - should.equal(updatedIntegration.webhooks.length, 1); - - const webhook = updatedIntegration.webhooks[0]; - should.equal(webhook.integration_id, updatedIntegration.id); - - request.put(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) - .set('Origin', config.get('url')) - .send({ - integrations: [{ - webhooks: [] - }] - }) - .expect(200) - .end(function (err) { - if (err) { - return done(err); - } - - request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/?include=webhooks`)) - .set('Origin', config.get('url')) - .expect('Content-Type', /json/) - .expect('Cache-Control', testUtils.cacheRules.private) - .expect(200) - .end(function (err, {body}) { - if (err) { - return done(err); - } - - const [updatedIntegration] = body.integrations; - - should.equal(updatedIntegration.webhooks.length, 0); - done(); - }); - }); - }); + should.equal(updatedIntegration.webhooks.length, 0); }); }); }); - it('Can succesfully delete a created integration', function (done) { - request.post(localUtils.API.getApiQuery('integrations/')) + it('Can succesfully delete a created integration', function () { + return request.post(localUtils.API.getApiQuery('integrations/')) .set('Origin', config.get('url')) .send({ integrations: [{ @@ -426,24 +377,16 @@ describe('Integrations API', function () { }] }) .expect(201) - .end(function (err, {body}) { - if (err) { - return done(err); - } + .then(function ({body}) { const [createdIntegration] = body.integrations; - request.del(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) + return request.del(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) .set('Origin', config.get('url')) .expect(204) - .end(function (err) { - if (err) { - return done(err); - } - - request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) + .then(function () { + return request.get(localUtils.API.getApiQuery(`integrations/${createdIntegration.id}/`)) .set('Origin', config.get('url')) - .expect(404) - .end(done); + .expect(404); }); }); }); diff --git a/test/api-acceptance/admin/settings_spec.js b/test/api-acceptance/admin/settings_spec.js index aae9273d9f..4438f265b8 100644 --- a/test/api-acceptance/admin/settings_spec.js +++ b/test/api-acceptance/admin/settings_spec.js @@ -87,16 +87,12 @@ describe('Settings API', function () { }); }); - it('Can edit a setting', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('Can edit a setting', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { const jsonResponse = res.body; const changedValue = []; @@ -172,19 +168,15 @@ describe('Settings API', function () { should.exist(jsonResponse); should.exist(jsonResponse.settings); - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(settingToChange) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, res) { - if (err) { - return done(err); - } - - const putBody = res.body; - res.headers['x-cache-invalidate'].should.eql('/*'); + .then(function ({body, headers}) { + const putBody = body; + headers['x-cache-invalidate'].should.eql('/*'); should.exist(putBody); putBody.settings[0].key.should.eql('title'); @@ -239,7 +231,6 @@ describe('Settings API', function () { should.equal(putBody.settings[15].value, 'Pacific/Auckland'); localUtils.API.checkResponse(putBody, 'settings'); - done(); }); }); }); diff --git a/test/api-acceptance/admin/users_spec.js b/test/api-acceptance/admin/users_spec.js index 6827c24edc..bc677f2834 100644 --- a/test/api-acceptance/admin/users_spec.js +++ b/test/api-acceptance/admin/users_spec.js @@ -200,8 +200,8 @@ describe('User API', function () { }); }); - it('can edit a user', function (done) { - request.put(localUtils.API.getApiQuery('users/me/')) + it('can edit a user', function () { + return request.put(localUtils.API.getApiQuery('users/me/')) .set('Origin', config.get('url')) .send({ users: [{ @@ -212,11 +212,7 @@ describe('User API', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { const putBody = res.body; res.headers['x-cache-invalidate'].should.eql('/*'); should.exist(putBody.users[0]); @@ -226,7 +222,7 @@ describe('User API', function () { should.not.exist(putBody.users[0].password); - models.User.findOne({id: putBody.users[0].id}) + return models.User.findOne({id: putBody.users[0].id}) .then((user) => { return models.User.isPasswordCorrect({ plainPassword: 'mynewfancypasswordwhichisnotallowed', @@ -236,7 +232,6 @@ describe('User API', function () { .then(Promise.reject) .catch((err) => { err.code.should.eql('PASSWORD_INCORRECT'); - done(); }); }); }); @@ -285,14 +280,14 @@ describe('User API', function () { }) .select(); }) - .then((models) => { - models.length.should.eql(0); + .then((rolesUsersModels) => { + rolesUsersModels.length.should.eql(0); return db.knex('roles_users') .select(); }) - .then((models) => { - models.length.should.greaterThan(0); + .then((rolesUsers) => { + rolesUsers.length.should.greaterThan(0); }); }); diff --git a/test/api-acceptance/content/settings_spec.js b/test/api-acceptance/content/settings_spec.js index 2cc5ff6869..a6814751ef 100644 --- a/test/api-acceptance/content/settings_spec.js +++ b/test/api-acceptance/content/settings_spec.js @@ -86,14 +86,14 @@ describe('Settings Content API', function () { // Object.keys(settings).length.should.equal(22); Object.keys(settings).should.deepEqual(defaultSettingsKeys); // Verify that we are returning the defaults for each value - _.forEach(settings, (value, key) => { + _.forEach(settings, (value, settingsKey) => { // `url` does not come from the settings cache - if (key === 'url') { + if (settingsKey === 'url') { should(value).eql(`${config.get('url')}/`); return; } - let defaultKey = _.findKey(publicSettings, v => v === key); + let defaultKey = _.findKey(publicSettings, v => v === settingsKey); let defaultValue = _.find(flattenedPublicSettings, setting => setting.key === defaultKey).defaultValue; // Convert empty strings to null diff --git a/test/regression/api/canary/admin/identities_spec.js b/test/regression/api/canary/admin/identities_spec.js index 913d9d5854..9d91d801b0 100644 --- a/test/regression/api/canary/admin/identities_spec.js +++ b/test/regression/api/canary/admin/identities_spec.js @@ -12,7 +12,6 @@ let request; const verifyJWKS = (endpoint, token) => { return new Promise((resolve, reject) => { - const jwksClient = require('jwks-rsa'); const client = jwksClient({ jwksUri: endpoint }); diff --git a/test/regression/api/canary/admin/settings_spec.js b/test/regression/api/canary/admin/settings_spec.js index 637cecdd25..defe94a9cb 100644 --- a/test/regression/api/canary/admin/settings_spec.js +++ b/test/regression/api/canary/admin/settings_spec.js @@ -399,18 +399,13 @@ describe('Settings API (canary)', function () { }); }); - it('can toggle member setting', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('can toggle member setting', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { const jsonResponse = res.body; - const changedValue = []; const settingToChange = { settings: [ @@ -424,25 +419,19 @@ describe('Settings API (canary)', function () { should.exist(jsonResponse); should.exist(jsonResponse.settings); - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(settingToChange) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, res) { - if (err) { - return done(err); - } - - const putBody = res.body; - res.headers['x-cache-invalidate'].should.eql('/*'); + .then(function ({body, headers}) { + const putBody = body; + headers['x-cache-invalidate'].should.eql('/*'); should.exist(putBody); putBody.settings[0].key.should.eql('labs'); putBody.settings[0].value.should.eql(JSON.stringify({subscribers: false, members: false})); - - done(); }); }); }); @@ -507,16 +496,12 @@ describe('Settings API (canary)', function () { }); }); - it('Will transform "1"', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('Will transform "1"', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { const jsonResponse = res.body; const settingToChange = { @@ -531,26 +516,21 @@ describe('Settings API (canary)', function () { should.exist(jsonResponse); should.exist(jsonResponse.settings); - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(settingToChange) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, res) { - if (err) { - return done(err); - } - - const putBody = res.body; - res.headers['x-cache-invalidate'].should.eql('/*'); + .then(function ({body, headers}) { + const putBody = body; + headers['x-cache-invalidate'].should.eql('/*'); should.exist(putBody); putBody.settings[0].key.should.eql('is_private'); putBody.settings[0].value.should.eql(true); localUtils.API.checkResponse(putBody, 'settings'); - done(); }); }); }); @@ -629,36 +609,28 @@ describe('Settings API (canary)', function () { }); }); - it('should not be able to edit settings', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('should not be able to edit settings', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; const newValue = 'new value'; should.exist(jsonResponse); should.exist(jsonResponse.settings); jsonResponse.settings = [{key: 'visibility', value: 'public'}]; - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(403) - .end(function (err, res) { - if (err) { - return done(err); - } - - jsonResponse = res.body; - should.not.exist(res.headers['x-cache-invalidate']); + .then(function ({body, headers}) { + jsonResponse = body; + should.not.exist(headers['x-cache-invalidate']); should.exist(jsonResponse.errors); testUtils.API.checkResponseValue(jsonResponse.errors[0], [ 'message', @@ -670,8 +642,6 @@ describe('Settings API (canary)', function () { 'code', 'id' ]); - - done(); }); }); }); @@ -699,36 +669,27 @@ describe('Settings API (canary)', function () { }); }); - it('should not be able to edit settings', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('should not be able to edit settings', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; - const newValue = 'new value'; should.exist(jsonResponse); should.exist(jsonResponse.settings); jsonResponse.settings = [{key: 'visibility', value: 'public'}]; - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(403) - .end(function (err, res) { - if (err) { - return done(err); - } - - jsonResponse = res.body; - should.not.exist(res.headers['x-cache-invalidate']); + .then(function ({body, headers}) { + jsonResponse = body; + should.not.exist(headers['x-cache-invalidate']); should.exist(jsonResponse.errors); testUtils.API.checkResponseValue(jsonResponse.errors[0], [ 'message', @@ -740,8 +701,6 @@ describe('Settings API (canary)', function () { 'code', 'id' ]); - - done(); }); }); }); diff --git a/test/regression/api/v2/admin/settings_spec.js b/test/regression/api/v2/admin/settings_spec.js index 183771da71..af7cc346c9 100644 --- a/test/regression/api/v2/admin/settings_spec.js +++ b/test/regression/api/v2/admin/settings_spec.js @@ -359,16 +359,12 @@ describe('Settings API (v2)', function () { }); }); - it('can toggle member setting', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('can toggle member setting', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { const jsonResponse = res.body; const changedValue = []; @@ -384,25 +380,19 @@ describe('Settings API (v2)', function () { should.exist(jsonResponse); should.exist(jsonResponse.settings); - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(settingToChange) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, res) { - if (err) { - return done(err); - } - - const putBody = res.body; - res.headers['x-cache-invalidate'].should.eql('/*'); + .then(function ({body, headers}) { + const putBody = body; + headers['x-cache-invalidate'].should.eql('/*'); should.exist(putBody); putBody.settings[0].key.should.eql('labs'); putBody.settings[0].value.should.eql(JSON.stringify({subscribers: false, members: false})); - - done(); }); }); }); @@ -427,36 +417,28 @@ describe('Settings API (v2)', function () { }); }); - it('can\'t edit non existent setting', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('can\'t edit non existent setting', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; const newValue = 'new value'; should.exist(jsonResponse); should.exist(jsonResponse.settings); jsonResponse.settings = [{key: 'testvalue', value: newValue}]; - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(404) - .end(function (err, res) { - if (err) { - return done(err); - } - - jsonResponse = res.body; - should.not.exist(res.headers['x-cache-invalidate']); + .then(function ({body, headers}) { + jsonResponse = body; + should.not.exist(headers['x-cache-invalidate']); should.exist(jsonResponse.errors); testUtils.API.checkResponseValue(jsonResponse.errors[0], [ 'message', @@ -468,21 +450,16 @@ describe('Settings API (v2)', function () { 'code', 'id' ]); - done(); }); }); }); - it('Will transform "1"', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('Will transform "1"', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { const jsonResponse = res.body; const settingToChange = { @@ -503,20 +480,15 @@ describe('Settings API (v2)', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, res) { - if (err) { - return done(err); - } - - const putBody = res.body; - res.headers['x-cache-invalidate'].should.eql('/*'); + .then(function ({body, headers}) { + const putBody = body; + headers['x-cache-invalidate'].should.eql('/*'); should.exist(putBody); putBody.settings[0].key.should.eql('is_private'); putBody.settings[0].value.should.eql(true); localUtils.API.checkResponse(putBody, 'settings'); - done(); }); }); }); @@ -595,36 +567,28 @@ describe('Settings API (v2)', function () { }); }); - it('should not be able to edit settings', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('should not be able to edit settings', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; - const newValue = 'new value'; + should.exist(jsonResponse); should.exist(jsonResponse.settings); jsonResponse.settings = [{key: 'visibility', value: 'public'}]; - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(403) - .end(function (err, res) { - if (err) { - return done(err); - } - - jsonResponse = res.body; - should.not.exist(res.headers['x-cache-invalidate']); + .then(function ({body, headers}) { + jsonResponse = body; + should.not.exist(headers['x-cache-invalidate']); should.exist(jsonResponse.errors); testUtils.API.checkResponseValue(jsonResponse.errors[0], [ 'message', @@ -636,8 +600,6 @@ describe('Settings API (v2)', function () { 'code', 'id' ]); - - done(); }); }); }); @@ -665,36 +627,27 @@ describe('Settings API (v2)', function () { }); }); - it('should not be able to edit settings', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('should not be able to edit settings', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; - const newValue = 'new value'; should.exist(jsonResponse); should.exist(jsonResponse.settings); jsonResponse.settings = [{key: 'visibility', value: 'public'}]; - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(403) - .end(function (err, res) { - if (err) { - return done(err); - } - - jsonResponse = res.body; - should.not.exist(res.headers['x-cache-invalidate']); + .then(function ({body, headers}) { + jsonResponse = body; + should.not.exist(headers['x-cache-invalidate']); should.exist(jsonResponse.errors); testUtils.API.checkResponseValue(jsonResponse.errors[0], [ 'message', @@ -706,8 +659,6 @@ describe('Settings API (v2)', function () { 'code', 'id' ]); - - done(); }); }); }); diff --git a/test/regression/api/v3/admin/settings_spec.js b/test/regression/api/v3/admin/settings_spec.js index 46c61bba40..8230e4695d 100644 --- a/test/regression/api/v3/admin/settings_spec.js +++ b/test/regression/api/v3/admin/settings_spec.js @@ -322,18 +322,13 @@ describe('Settings API (v3)', function () { }); }); - it('can toggle member setting', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('can toggle member setting', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { const jsonResponse = res.body; - const changedValue = []; const settingToChange = { settings: [ @@ -347,25 +342,19 @@ describe('Settings API (v3)', function () { should.exist(jsonResponse); should.exist(jsonResponse.settings); - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(settingToChange) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, res) { - if (err) { - return done(err); - } - - const putBody = res.body; - res.headers['x-cache-invalidate'].should.eql('/*'); + .then(function ({body, headers}) { + const putBody = body; + headers['x-cache-invalidate'].should.eql('/*'); should.exist(putBody); putBody.settings[0].key.should.eql('labs'); putBody.settings[0].value.should.eql(JSON.stringify({subscribers: false, members: false})); - - done(); }); }); }); @@ -390,36 +379,28 @@ describe('Settings API (v3)', function () { }); }); - it('can\'t edit non existent setting', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('can\'t edit non existent setting', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; const newValue = 'new value'; should.exist(jsonResponse); should.exist(jsonResponse.settings); jsonResponse.settings = [{key: 'testvalue', value: newValue}]; - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(404) - .end(function (err, res) { - if (err) { - return done(err); - } - - jsonResponse = res.body; - should.not.exist(res.headers['x-cache-invalidate']); + .then(function ({body, headers}) { + jsonResponse = body; + should.not.exist(headers['x-cache-invalidate']); should.exist(jsonResponse.errors); testUtils.API.checkResponseValue(jsonResponse.errors[0], [ 'message', @@ -431,21 +412,16 @@ describe('Settings API (v3)', function () { 'code', 'id' ]); - done(); }); }); }); - it('Will transform "1"', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('Will transform "1"', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { const jsonResponse = res.body; const settingToChange = { @@ -460,26 +436,21 @@ describe('Settings API (v3)', function () { should.exist(jsonResponse); should.exist(jsonResponse.settings); - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(settingToChange) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(200) - .end(function (err, res) { - if (err) { - return done(err); - } - - const putBody = res.body; - res.headers['x-cache-invalidate'].should.eql('/*'); + .then(function ({body, headers}) { + const putBody = body; + headers['x-cache-invalidate'].should.eql('/*'); should.exist(putBody); putBody.settings[0].key.should.eql('is_private'); putBody.settings[0].value.should.eql(true); localUtils.API.checkResponse(putBody, 'settings'); - done(); }); }); }); @@ -558,36 +529,27 @@ describe('Settings API (v3)', function () { }); }); - it('should not be able to edit settings', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('should not be able to edit settings', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; - const newValue = 'new value'; should.exist(jsonResponse); should.exist(jsonResponse.settings); jsonResponse.settings = [{key: 'visibility', value: 'public'}]; - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(403) - .end(function (err, res) { - if (err) { - return done(err); - } - - jsonResponse = res.body; - should.not.exist(res.headers['x-cache-invalidate']); + .then(function ({body, headers}) { + jsonResponse = body; + should.not.exist(headers['x-cache-invalidate']); should.exist(jsonResponse.errors); testUtils.API.checkResponseValue(jsonResponse.errors[0], [ 'message', @@ -599,8 +561,6 @@ describe('Settings API (v3)', function () { 'code', 'id' ]); - - done(); }); }); }); @@ -628,36 +588,28 @@ describe('Settings API (v3)', function () { }); }); - it('should not be able to edit settings', function (done) { - request.get(localUtils.API.getApiQuery('settings/')) + it('should not be able to edit settings', function () { + return request.get(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) - .end(function (err, res) { - if (err) { - return done(err); - } - + .then(function (res) { let jsonResponse = res.body; const newValue = 'new value'; should.exist(jsonResponse); should.exist(jsonResponse.settings); jsonResponse.settings = [{key: 'visibility', value: 'public'}]; - request.put(localUtils.API.getApiQuery('settings/')) + return request.put(localUtils.API.getApiQuery('settings/')) .set('Origin', config.get('url')) .send(jsonResponse) .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(403) - .end(function (err, res) { - if (err) { - return done(err); - } - - jsonResponse = res.body; - should.not.exist(res.headers['x-cache-invalidate']); + .then(function ({body, headers}) { + jsonResponse = body; + should.not.exist(headers['x-cache-invalidate']); should.exist(jsonResponse.errors); testUtils.API.checkResponseValue(jsonResponse.errors[0], [ 'message', @@ -669,8 +621,6 @@ describe('Settings API (v3)', function () { 'code', 'id' ]); - - done(); }); }); }); diff --git a/test/unit/adapters/scheduling/post-scheduling/index_spec.js b/test/unit/adapters/scheduling/post-scheduling/index_spec.js index cc8476d7e1..ca60372d64 100644 --- a/test/unit/adapters/scheduling/post-scheduling/index_spec.js +++ b/test/unit/adapters/scheduling/post-scheduling/index_spec.js @@ -39,8 +39,8 @@ describe.skip('Scheduling: Post Scheduling', function () { return Promise.resolve({posts: scope.scheduledPosts}); }); - sinon.stub(events, 'onMany').callsFake(function (events, stubDone) { - events.forEach(function (event) { + sinon.stub(events, 'onMany').callsFake(function (stubedEvents, stubDone) { + stubedEvents.forEach(function (event) { scope.events[event] = stubDone; }); }); diff --git a/test/unit/api/shared/http_spec.js b/test/unit/api/shared/http_spec.js index e4723ac1d8..0e754e1444 100644 --- a/test/unit/api/shared/http_spec.js +++ b/test/unit/api/shared/http_spec.js @@ -58,12 +58,12 @@ describe('Unit: api/shared/http', function () { }); it('api response is fn', function (done) { - const response = sinon.stub().callsFake(function (req, res, next) { - should.exist(req); - should.exist(res); - should.exist(next); + const response = sinon.stub().callsFake(function (_req, _res, _next) { + should.exist(_req); + should.exist(_res); + should.exist(_next); apiImpl.calledOnce.should.be.true(); - res.json.called.should.be.false(); + _res.json.called.should.be.false(); done(); }); diff --git a/test/unit/api/shared/pipeline_spec.js b/test/unit/api/shared/pipeline_spec.js index e762f373ba..3906868c83 100644 --- a/test/unit/api/shared/pipeline_spec.js +++ b/test/unit/api/shared/pipeline_spec.js @@ -213,7 +213,7 @@ describe('Unit: api/shared/pipeline', function () { shared.pipeline.STAGES.serialisation.input.resolves(); shared.pipeline.STAGES.permissions.resolves(); shared.pipeline.STAGES.query.resolves('response'); - shared.pipeline.STAGES.serialisation.output.callsFake(function (response, apiUtils, apiConfig, apiImpl, frame) { + shared.pipeline.STAGES.serialisation.output.callsFake(function (response, _apiUtils, apiConfig, apiImpl, frame) { frame.response = response; }); diff --git a/test/unit/apps/amp/amp_content_spec.js b/test/unit/apps/amp/amp_content_spec.js index 8ef7010b48..37108857cb 100644 --- a/test/unit/apps/amp/amp_content_spec.js +++ b/test/unit/apps/amp/amp_content_spec.js @@ -62,8 +62,8 @@ describe('{{amp_content}} helper', function () { amperizeCache[1].should.have.property('amp', testData.html); // call it again, to make it fetch from cache ampCachedResult = ampContentHelper.call(testData); - ampCachedResult.then(function (rendered) { - should.exist(rendered); + ampCachedResult.then(function (cachedResult) { + should.exist(cachedResult); should.exist(amperizeCache); amperizeCache[1].should.have.property('updated_at', 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)'); amperizeCache[1].should.have.property('amp', testData.html); @@ -97,14 +97,14 @@ describe('{{amp_content}} helper', function () { // call it again with different values to fetch from Amperize and not from cache ampResult = ampContentHelper.call(testData2); - ampResult.then(function (rendered) { - should.exist(rendered); + ampResult.then(function (cachedResult) { + should.exist(cachedResult); should.exist(amperizeCache); // it should not have the old value, amperizeCache[1].should.not.have.property('Wed Jul 30 2016 18:17:22 GMT+0200 (CEST)'); // only the new one - rendered.string.should.equal(testData2.html); + cachedResult.string.should.equal(testData2.html); amperizeCache[1].should.have.property('updated_at', 'Wed Jul 30 2016 18:17:22 GMT+0200 (CEST)'); amperizeCache[1].should.have.property('amp', testData2.html); done(); diff --git a/test/unit/apps/amp/router_spec.js b/test/unit/apps/amp/router_spec.js index 46f89206e4..002d60eac1 100644 --- a/test/unit/apps/amp/router_spec.js +++ b/test/unit/apps/amp/router_spec.js @@ -58,8 +58,8 @@ describe('Unit - apps/amp/lib/router', function () { describe('fn: renderer', function () { it('should render default amp page when theme has no amp template', function (done) { - helpers.renderer.callsFake(function (req, res, data) { - res.routerOptions.defaultTemplate.should.eql(defaultPath); + helpers.renderer.callsFake(function (_req, _res, data) { + _res.routerOptions.defaultTemplate.should.eql(defaultPath); data.should.eql({post: {title: 'test'}}); done(); }); @@ -93,8 +93,6 @@ describe('Unit - apps/amp/lib/router', function () { }); describe('fn: getPostData', function () { - let res; - let req; let entryLookupStub; let post; diff --git a/test/unit/data/meta/paginated_url_spec.js b/test/unit/data/meta/paginated_url_spec.js index 7b80178473..821e99d715 100644 --- a/test/unit/data/meta/paginated_url_spec.js +++ b/test/unit/data/meta/paginated_url_spec.js @@ -5,13 +5,12 @@ const urlUtils = require('../../../utils/urlUtils'); describe('getPaginatedUrl', function () { let data; - let getTestUrls; beforeEach(function () { data = {}; }); - getTestUrls = function getTestUrls() { + const getTestUrls = function getTestUrls() { return { next: getPaginatedUrl('next', data, true), prev: getPaginatedUrl('prev', data, true), diff --git a/test/unit/helpers/foreach_spec.js b/test/unit/helpers/foreach_spec.js index 3238330c7d..fbd0cc81ee 100644 --- a/test/unit/helpers/foreach_spec.js +++ b/test/unit/helpers/foreach_spec.js @@ -31,8 +31,8 @@ describe('{{#foreach}} helper', function () { }; }); - function runTest(self, context, options) { - helpers.foreach.call(self, context, options); + function runTest(self, _context, _options) { + helpers.foreach.call(self, _context, _options); } it('should not populate data if no private data is supplied (array)', function () { @@ -567,14 +567,14 @@ describe('{{#foreach}} helper', function () { }); it('should output nothing if all tags are internal', function () { - const tagArrayHash = { + const internalTagArrayHash = { tags: [ {name: 'first', visibility: 'internal'}, {name: 'second', visibility: 'internal'} ] }; - const tagObjectHash = { + const internalTagObjectHash = { tags: { first: {name: 'first', visibility: 'internal'}, second: {name: 'second', visibility: 'internal'} @@ -584,8 +584,8 @@ describe('{{#foreach}} helper', function () { const templateString = '