From 143921948de89baff21a800ae8e7dfaeef415b05 Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 19 Oct 2020 17:45:26 +1300 Subject: [PATCH] Fixed "no-shadow" eslint warning in tests refs https://github.com/TryGhost/eslint-plugin-ghost/commit/b6728ecb0f3385789497943648443cea5e3f8cf9 - The "no-shadow" eslint rune was introduced into ghost's eslint plugin (referenced commmit), which resulted in flood of warning in console output when linting the project codebase. - This cleanup is aiming to make any new linting issues more visible. Follow up commits will contain similar cleanups in other parts of the codebase --- .../api-acceptance/admin/integrations_spec.js | 333 ++++++++---------- test/api-acceptance/admin/settings_spec.js | 23 +- test/api-acceptance/admin/users_spec.js | 21 +- test/api-acceptance/content/settings_spec.js | 6 +- .../api/canary/admin/identities_spec.js | 1 - .../api/canary/admin/settings_spec.js | 97 ++--- test/regression/api/v2/admin/settings_spec.js | 119 ++----- test/regression/api/v3/admin/settings_spec.js | 120 ++----- .../scheduling/post-scheduling/index_spec.js | 4 +- test/unit/api/shared/http_spec.js | 10 +- test/unit/api/shared/pipeline_spec.js | 2 +- test/unit/apps/amp/amp_content_spec.js | 10 +- test/unit/apps/amp/router_spec.js | 6 +- test/unit/data/meta/paginated_url_spec.js | 3 +- test/unit/helpers/foreach_spec.js | 12 +- test/unit/helpers/has_spec.js | 4 +- test/unit/helpers/url_spec.js | 2 - test/unit/models/base/index_spec.js | 12 +- test/unit/models/member_spec.js | 2 +- test/unit/services/mail/GhostMailer_spec.js | 2 - test/unit/services/permissions/index_spec.js | 28 +- test/unit/services/permissions/public_spec.js | 4 +- .../routing/controllers/entry_spec.js | 8 +- .../services/routing/controllers/rss_spec.js | 2 +- .../routing/helpers/entry-lookup_spec.js | 1 - test/unit/services/themes/middleware_spec.js | 4 +- test/utils/configUtils.js | 4 +- test/utils/index.js | 43 +-- 28 files changed, 326 insertions(+), 557 deletions(-) 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 = ''; const expected = ''; - shouldCompileToExpected(templateString, tagObjectHash, expected); - shouldCompileToExpected(templateString, tagArrayHash, expected); + shouldCompileToExpected(templateString, internalTagObjectHash, expected); + shouldCompileToExpected(templateString, internalTagArrayHash, expected); }); }); }); diff --git a/test/unit/helpers/has_spec.js b/test/unit/helpers/has_spec.js index 752f296e4c..5e7767f1a9 100644 --- a/test/unit/helpers/has_spec.js +++ b/test/unit/helpers/has_spec.js @@ -29,10 +29,10 @@ describe('{{#has}} helper', function () { }; }); - function callHasHelper(thisCtx, hash) { + function callHasHelper(context, hash) { // Hash is the options passed in handlebarsOptions.hash = hash; - return helpers.has.call(thisCtx, handlebarsOptions); + return helpers.has.call(context, handlebarsOptions); } describe('tag match', function () { diff --git a/test/unit/helpers/url_spec.js b/test/unit/helpers/url_spec.js index 436e36204c..66fd4a7491 100644 --- a/test/unit/helpers/url_spec.js +++ b/test/unit/helpers/url_spec.js @@ -271,8 +271,6 @@ describe('{{url}} helper', function () { }); describe('with subdir', function () { - let sandbox; - before(function () { sandbox = sinon.createSandbox(); urlUtils.stubUrlUtils({url: 'http://localhost:65535/blog'}, sandbox); diff --git a/test/unit/models/base/index_spec.js b/test/unit/models/base/index_spec.js index 34beb1942e..9cef240630 100644 --- a/test/unit/models/base/index_spec.js +++ b/test/unit/models/base/index_spec.js @@ -67,8 +67,8 @@ describe('Models: base', function () { security.string.safe.withArgs(slug).returns(slug); return models.Base.Model.generateSlug(Model, slug, options) - .then((slug) => { - slug.should.eql(new Array(186).join('a')); + .then((generatedSlug) => { + generatedSlug.should.eql(new Array(186).join('a')); }); }); @@ -79,8 +79,8 @@ describe('Models: base', function () { security.string.safe.withArgs(slug).returns(slug); return models.Base.Model.generateSlug(Model, slug, options) - .then((slug) => { - slug.should.eql('upsi-tableName'); + .then((generatedSlug) => { + generatedSlug.should.eql('upsi-tableName'); }); }); @@ -95,8 +95,8 @@ describe('Models: base', function () { security.string.safe.withArgs(slug).returns(slug); return models.Base.Model.generateSlug(Model, slug, options) - .then((slug) => { - slug.should.eql('hash-#lul'); + .then((generatedSlug) => { + generatedSlug.should.eql('hash-#lul'); }); }); diff --git a/test/unit/models/member_spec.js b/test/unit/models/member_spec.js index 6904330fa3..d100033d27 100644 --- a/test/unit/models/member_spec.js +++ b/test/unit/models/member_spec.js @@ -22,7 +22,7 @@ describe('Unit: models/member', function () { let toJSON; beforeEach(function () { - toJSON = function toJSON(model, options) { + toJSON = function (model, options) { return new models.Member(model).toJSON(options); }; }); diff --git a/test/unit/services/mail/GhostMailer_spec.js b/test/unit/services/mail/GhostMailer_spec.js index bb4a0a4ed3..d1926e9e96 100644 --- a/test/unit/services/mail/GhostMailer_spec.js +++ b/test/unit/services/mail/GhostMailer_spec.js @@ -191,8 +191,6 @@ describe('Mail: Ghostmailer', function () { }); describe('should fall back to [blog.title] ', function () { - let mailer; - beforeEach(async function () { mailer = new mail.GhostMailer(); sandbox.stub(mailer, 'sendMail').resolves(); diff --git a/test/unit/services/permissions/index_spec.js b/test/unit/services/permissions/index_spec.js index 0c003565b9..eabc421526 100644 --- a/test/unit/services/permissions/index_spec.js +++ b/test/unit/services/permissions/index_spec.js @@ -78,17 +78,17 @@ describe('Permissions', function () { it('can load an actions map from existing permissions', function (done) { fakePermissions = loadFakePermissions(); - permissions.init().then(function (actionsMap) { - should.exist(actionsMap); + permissions.init().then(function (actions) { + should.exist(actions); permissions.canThis.should.not.throwError(); - _.keys(actionsMap).should.eql(['browse', 'edit', 'add', 'destroy']); + _.keys(actions).should.eql(['browse', 'edit', 'add', 'destroy']); - actionsMap.browse.should.eql(['post']); - actionsMap.edit.should.eql(['post', 'tag', 'user', 'page']); - actionsMap.add.should.eql(['post', 'user', 'page']); - actionsMap.destroy.should.eql(['post', 'user']); + actions.browse.should.eql(['post']); + actions.edit.should.eql(['post', 'tag', 'user', 'page']); + actions.add.should.eql(['post', 'user', 'page']); + actions.destroy.should.eql(['post', 'user']); done(); }).catch(done); @@ -97,17 +97,17 @@ describe('Permissions', function () { it('can load an actions map from existing permissions, and deduplicate', function (done) { fakePermissions = loadFakePermissions({extra: true}); - permissions.init().then(function (actionsMap) { - should.exist(actionsMap); + permissions.init().then(function (actions) { + should.exist(actions); permissions.canThis.should.not.throwError(); - _.keys(actionsMap).should.eql(['browse', 'edit', 'add', 'destroy']); + _.keys(actions).should.eql(['browse', 'edit', 'add', 'destroy']); - actionsMap.browse.should.eql(['post']); - actionsMap.edit.should.eql(['post', 'tag', 'user', 'page']); - actionsMap.add.should.eql(['post', 'user', 'page']); - actionsMap.destroy.should.eql(['post', 'user']); + actions.browse.should.eql(['post']); + actions.edit.should.eql(['post', 'tag', 'user', 'page']); + actions.add.should.eql(['post', 'user', 'page']); + actions.destroy.should.eql(['post', 'user']); done(); }).catch(done); diff --git a/test/unit/services/permissions/public_spec.js b/test/unit/services/permissions/public_spec.js index cc2d9183b0..ce882b6502 100644 --- a/test/unit/services/permissions/public_spec.js +++ b/test/unit/services/permissions/public_spec.js @@ -122,8 +122,8 @@ describe('Permissions', function () { return applyPublicRules('posts', 'read', _.cloneDeep(draft)).then(function () { done('Did not throw an error for draft'); - }).catch(function (err) { - (err instanceof errors.NoPermissionError).should.eql(true); + }).catch(function (error) { + (error instanceof errors.NoPermissionError).should.eql(true); done(); }); }); diff --git a/test/unit/services/routing/controllers/entry_spec.js b/test/unit/services/routing/controllers/entry_spec.js index b335133a4d..980c217076 100644 --- a/test/unit/services/routing/controllers/entry_spec.js +++ b/test/unit/services/routing/controllers/entry_spec.js @@ -123,7 +123,7 @@ describe('Unit - services/routing/controllers/entry', function () { entry: post }); - urlUtils.redirectToAdmin.callsFake(function (statusCode, res, editorUrl) { + urlUtils.redirectToAdmin.callsFake(function (statusCode, _res, editorUrl) { statusCode.should.eql(302); editorUrl.should.eql(EDITOR_URL + post.id); done(); @@ -145,7 +145,7 @@ describe('Unit - services/routing/controllers/entry', function () { entry: post }); - urlUtils.redirectToAdmin.callsFake(function (statusCode, res, editorUrl) { + urlUtils.redirectToAdmin.callsFake(function (statusCode, _res, editorUrl) { configUtils.restore(); done(new Error('redirectToAdmin was called')); }); @@ -197,7 +197,7 @@ describe('Unit - services/routing/controllers/entry', function () { entry: post }); - urlUtils.redirect301.callsFake(function (res, postUrl) { + urlUtils.redirect301.callsFake(function (_res, postUrl) { postUrl.should.eql(post.url); done(); }); @@ -226,7 +226,7 @@ describe('Unit - services/routing/controllers/entry', function () { entry: post }); - urlUtils.redirect301.callsFake(function (res, postUrl) { + urlUtils.redirect301.callsFake(function (_res, postUrl) { postUrl.should.eql(post.url + '?query=true'); done(); }); diff --git a/test/unit/services/routing/controllers/rss_spec.js b/test/unit/services/routing/controllers/rss_spec.js index 5bc31b8750..42735eb7da 100644 --- a/test/unit/services/routing/controllers/rss_spec.js +++ b/test/unit/services/routing/controllers/rss_spec.js @@ -65,7 +65,7 @@ describe('Unit - services/routing/controllers/rss', function () { posts: posts }); - rssService.render.callsFake(function (res, baseUrl, data) { + rssService.render.callsFake(function (_res, baseUrl, data) { baseUrl.should.eql('/rss/'); data.posts.should.eql(posts); data.title.should.eql('Ghost'); diff --git a/test/unit/services/routing/helpers/entry-lookup_spec.js b/test/unit/services/routing/helpers/entry-lookup_spec.js index 9dcd511d65..5828791665 100644 --- a/test/unit/services/routing/helpers/entry-lookup_spec.js +++ b/test/unit/services/routing/helpers/entry-lookup_spec.js @@ -6,7 +6,6 @@ const api = require('../../../../../core/server/api'); const helpers = require('../../../../../core/frontend/services/routing/helpers'); describe('Unit - services/routing/helpers/entry-lookup', function () { - let posts; let locals; afterEach(function () { diff --git a/test/unit/services/themes/middleware_spec.js b/test/unit/services/themes/middleware_spec.js index bc9c18af3b..e278f4827f 100644 --- a/test/unit/services/themes/middleware_spec.js +++ b/test/unit/services/themes/middleware_spec.js @@ -9,8 +9,8 @@ const middleware = themes.middleware; const sandbox = sinon.createSandbox(); -function executeMiddleware(middleware, req, res, next) { - const [current, ...rest] = middleware; +function executeMiddleware(toExecute, req, res, next) { + const [current, ...rest] = toExecute; current(req, res, function (err) { if (err) { diff --git a/test/utils/configUtils.js b/test/utils/configUtils.js index bfa0093e38..a39ab69885 100644 --- a/test/utils/configUtils.js +++ b/test/utils/configUtils.js @@ -14,8 +14,8 @@ configUtils.set = function () { const value = arguments[1]; if (_.isObject(key)) { - _.each(key, function (value, key) { - config.set(key, value); + _.each(key, function (settingValue, settingKey) { + config.set(settingKey, settingValue); }); } else { config.set(key, value); diff --git a/test/utils/index.js b/test/utils/index.js index 09b905564f..714e02ecfa 100644 --- a/test/utils/index.js +++ b/test/utils/index.js @@ -34,20 +34,9 @@ const APIUtils = require('./api'); const config = require('../../core/shared/config'); const knexMigrator = new KnexMigrator(); let fixtures; -let getFixtureOps; let toDoList; let originalRequireFn; let postsInserted = 0; -let teardownDb; -let setup; -let truncate; -let createUser; -let createPost; -let startGhost; -let initFixtures; -let initData; -let clearData; -let clearBruteData; // Require additional assertions which help us keep our tests small and clear require('./assertions'); @@ -512,7 +501,7 @@ fixtures = { }; /** Test Utility Functions **/ -initData = function initData() { +const initData = function initData() { return knexMigrator.init() .then(function () { events.emit('db.ready'); @@ -533,11 +522,11 @@ initData = function initData() { }); }; -clearBruteData = function clearBruteData() { +const clearBruteData = function clearBruteData() { return db.knex('brute').truncate(); }; -truncate = function truncate(tableName) { +const truncate = function truncate(tableName) { if (config.get('database:client') === 'sqlite3') { return db.knex(tableName).truncate(); } @@ -552,7 +541,7 @@ truncate = function truncate(tableName) { }; // we must always try to delete all tables -clearData = function clearData() { +const clearData = function clearData() { debug('Database reset'); return knexMigrator.reset({force: true}) .then(function () { @@ -660,7 +649,7 @@ toDoList = { * * `users:roles` - create a full suite of users, one per role * @param {Object} toDos */ -getFixtureOps = function getFixtureOps(toDos) { +const getFixtureOps = function getFixtureOps(toDos) { // default = default fixtures, if it isn't present, init with tables only const tablesOnly = !toDos.default; @@ -705,7 +694,7 @@ getFixtureOps = function getFixtureOps(toDos) { // ## Test Setup and Teardown -initFixtures = function initFixtures() { +const initFixtures = function initFixtures() { const options = _.merge({init: true}, _.transform(arguments, function (result, val) { result[val] = true; })); @@ -721,19 +710,19 @@ initFixtures = function initFixtures() { * Setup does 'init' (DB) by default * @returns {Function} */ -setup = function setup() { +const setup = function setup() { /*eslint no-invalid-this: "off"*/ const self = this; const args = arguments; - return function setup() { + return function innerSetup() { models.init(); return initFixtures.apply(self, args); }; }; -createUser = function createUser(options) { +const createUser = function createUser(options) { const user = options.user; const role = options.role; @@ -749,7 +738,7 @@ createUser = function createUser(options) { }); }; -createPost = function createPost(options) { +const createPost = function createPost(options) { const post = DataGenerator.forKnex.createPost(options.post); if (options.author) { @@ -764,7 +753,7 @@ createPost = function createPost(options) { * Has to run in a transaction for MySQL, otherwise the foreign key check does not work. * Sqlite3 has no truncate command. */ -teardownDb = function teardownDb() { +const teardownDb = function teardownDb() { debug('Database teardown'); urlService.softReset(); @@ -815,7 +804,7 @@ let ghostServer; * * @TODO: tidy up the tmp folders */ -startGhost = function startGhost(options) { +const startGhost = function startGhost(options) { console.time('Start Ghost'); // eslint-disable-line no-console options = _.merge({ redirectsFile: true, @@ -948,7 +937,7 @@ startGhost = function startGhost(options) { return ghost(); }) - .then(function startGhost(_ghostServer) { + .then(function startGhostServer(_ghostServer) { ghostServer = _ghostServer; if (options.subdir) { @@ -1020,9 +1009,9 @@ module.exports = { }, integrationTesting: { - overrideGhostConfig: function overrideGhostConfig(configUtils) { - configUtils.set('paths:contentPath', path.join(__dirname, 'fixtures')); - configUtils.set('times:getImageSizeTimeoutInMS', 1); + overrideGhostConfig: function overrideGhostConfig(utils) { + utils.set('paths:contentPath', path.join(__dirname, 'fixtures')); + utils.set('times:getImageSizeTimeoutInMS', 1); }, defaultMocks: function defaultMocks(sandbox, options) {