diff --git a/ghost/core/core/server/adapters/scheduling/post-scheduling/index.js b/ghost/core/core/server/adapters/scheduling/post-scheduling/index.js index 5eeb59023f7..3054ca6766f 100644 --- a/ghost/core/core/server/adapters/scheduling/post-scheduling/index.js +++ b/ghost/core/core/server/adapters/scheduling/post-scheduling/index.js @@ -1,7 +1,7 @@ const events = require('../../../lib/common/events'); const localUtils = require('../utils'); const PostScheduler = require('./PostScheduler'); -const getSchedulerIntegration = require('./scheduler-intergation'); +const getSchedulerIntegration = require('./scheduler-integration'); const {sequence} = require('@tryghost/promise'); /** @@ -32,7 +32,7 @@ const loadScheduledResources = async function () { const init = async (options) => { const integration = await getSchedulerIntegration(); - const adapter = await localUtils.createAdapter(); + const adapter = localUtils.createAdapter(); let scheduledResources; diff --git a/ghost/core/core/server/adapters/scheduling/post-scheduling/scheduler-intergation.js b/ghost/core/core/server/adapters/scheduling/post-scheduling/scheduler-integration.js similarity index 100% rename from ghost/core/core/server/adapters/scheduling/post-scheduling/scheduler-intergation.js rename to ghost/core/core/server/adapters/scheduling/post-scheduling/scheduler-integration.js diff --git a/ghost/core/core/server/adapters/scheduling/post-scheduling/scheduling-auth-token.js b/ghost/core/core/server/adapters/scheduling/post-scheduling/scheduling-auth-token.js index 18894b6a8bf..fdce896f59b 100644 --- a/ghost/core/core/server/adapters/scheduling/post-scheduling/scheduling-auth-token.js +++ b/ghost/core/core/server/adapters/scheduling/post-scheduling/scheduling-auth-token.js @@ -7,19 +7,19 @@ const jwt = require('jsonwebtoken'); * @param {Object} options * @param {string} options.publishedAt - ISO date * @param {string} options.apiUrl - url of the JWT's audience - * @param {string} options.key - integration key + * @param {object} options.key - integration key * @param {string} options.key.id - key ID * @param {string} options.key.secret - key secret * * @return {string} the JSON Web Token */ const getSignedAdminToken = function ({publishedAt, apiUrl, key}) { - const JWT_OPTIONS = { + const JWT_OPTIONS = /** @type {const} */ ({ keyid: key.id, algorithm: 'HS256', audience: apiUrl, noTimestamp: true - }; + }); // Default token expiry is till 6 hours after scheduled time // or if published_at is in past then till 6 hours after blog start diff --git a/ghost/core/core/server/adapters/scheduling/utils.js b/ghost/core/core/server/adapters/scheduling/utils.js index dbbcfc5173a..e416bf61cce 100644 --- a/ghost/core/core/server/adapters/scheduling/utils.js +++ b/ghost/core/core/server/adapters/scheduling/utils.js @@ -1,6 +1,6 @@ const adapterManager = require('../../services/adapter-manager'); -async function createAdapter() { +function createAdapter() { return adapterManager.getAdapter('scheduling'); } diff --git a/ghost/core/test/unit/server/adapters/scheduling/utils.test.js b/ghost/core/test/unit/server/adapters/scheduling/utils.test.js index 83307801596..d07b5d8d370 100644 --- a/ghost/core/test/unit/server/adapters/scheduling/utils.test.js +++ b/ghost/core/test/unit/server/adapters/scheduling/utils.test.js @@ -24,14 +24,12 @@ describe('Scheduling: utils', function () { }); describe('success', function () { - it('create good adapter', function (done) { - schedulingUtils.createAdapter().then(function (adapter) { - assertExists(adapter); - done(); - }).catch(done); + it('create good adapter', function () { + const adapter = schedulingUtils.createAdapter(); + assertExists(adapter); }); - it('create good adapter from custom file', function (done) { + it('create good adapter from custom file', function () { scope.adapter = schedulingPath + 'another-scheduler.js'; configUtils.set({ @@ -53,15 +51,13 @@ describe('Scheduling: utils', function () { fs.writeFileSync(scope.adapter, jsFile); - schedulingUtils.createAdapter().then(function (adapter) { - assertExists(adapter); - done(); - }).catch(done); + const adapter = schedulingUtils.createAdapter(); + assertExists(adapter); }); }); describe('error', function () { - it('create with adapter, but missing fn\'s', function (done) { + it('create with adapter, but missing fn\'s', function () { scope.adapter = schedulingPath + 'bad-adapter.js'; const jsFile = '' + 'var util = require(\'util\');' + @@ -78,11 +74,15 @@ describe('Scheduling: utils', function () { active: 'bad-adapter' } }); - schedulingUtils.createAdapter().catch(function (err) { - assertExists(err); - assert.equal(err.errorType, 'IncorrectUsageError'); - done(); - }); + + assert.throws( + () => schedulingUtils.createAdapter(), + (err) => { + assertExists(err); + assert.equal(err.errorType, 'IncorrectUsageError'); + return true; + } + ); }); }); });