From a96cf1a39a56b202e9f3b8921deb9ef172ba94e5 Mon Sep 17 00:00:00 2001 From: Sam Lord Date: Thu, 2 Dec 2021 12:26:23 +0000 Subject: [PATCH] Use @tryghost/logging package instead of injected argument refs: https://github.com/TryGhost/Toolbox/issues/146 --- .../lib/provider-mailgun.js | 10 +++++----- .../package.json | 1 + .../test/provider-mailgun.test.js | 19 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ghost/email-analytics-provider-mailgun/lib/provider-mailgun.js b/ghost/email-analytics-provider-mailgun/lib/provider-mailgun.js index 998f172720..286466a036 100644 --- a/ghost/email-analytics-provider-mailgun/lib/provider-mailgun.js +++ b/ghost/email-analytics-provider-mailgun/lib/provider-mailgun.js @@ -1,7 +1,8 @@ const mailgunJs = require('mailgun-js'); const moment = require('moment'); const {EventProcessingResult} = require('@tryghost/email-analytics-service'); -const debug = require('ghost-ignition').debug('email-analytics-provider-mailgun'); +const debug = require('@tryghost/debug')('email-analytics-provider-mailgun'); +const logging = require('@tryghost/logging'); const EVENT_FILTER = 'delivered OR opened OR failed OR unsubscribed OR complained'; const PAGE_LIMIT = 300; @@ -9,10 +10,9 @@ const TRUST_THRESHOLD_S = 30 * 60; // 30 minutes const DEFAULT_TAGS = ['bulk-email']; class EmailAnalyticsProviderMailgun { - constructor({config, settings, mailgun, logging = console} = {}) { + constructor({config, settings, mailgun} = {}) { this.config = config; this.settings = settings; - this.logging = logging; this.tags = [...DEFAULT_TAGS]; this._mailgun = mailgun; @@ -38,7 +38,7 @@ class EmailAnalyticsProviderMailgun { const hasMailgunSetting = !!(bulkEmailSetting && bulkEmailSetting.apiKey && bulkEmailSetting.baseUrl && bulkEmailSetting.domain); if (!hasMailgunConfig && !hasMailgunSetting) { - this.logging.warn(`Bulk email service is not configured`); + logging.warn(`Bulk email service is not configured`); return undefined; } @@ -89,7 +89,7 @@ class EmailAnalyticsProviderMailgun { const {mailgun} = this; if (!mailgun) { - this.logging.warn(`Bulk email service is not configured`); + logging.warn(`Bulk email service is not configured`); return new EventProcessingResult(); } diff --git a/ghost/email-analytics-provider-mailgun/package.json b/ghost/email-analytics-provider-mailgun/package.json index a275664f12..aee8ed27ab 100644 --- a/ghost/email-analytics-provider-mailgun/package.json +++ b/ghost/email-analytics-provider-mailgun/package.json @@ -26,6 +26,7 @@ }, "dependencies": { "@tryghost/email-analytics-service": "^1.0.4", + "@tryghost/logging": "^1.0.2", "mailgun-js": "^0.22.0", "moment": "^2.29.1" } diff --git a/ghost/email-analytics-provider-mailgun/test/provider-mailgun.test.js b/ghost/email-analytics-provider-mailgun/test/provider-mailgun.test.js index 5b16f9d50e..2fe51fe54f 100644 --- a/ghost/email-analytics-provider-mailgun/test/provider-mailgun.test.js +++ b/ghost/email-analytics-provider-mailgun/test/provider-mailgun.test.js @@ -9,13 +9,12 @@ const sinon = require('sinon'); const EmailAnalyticsProviderMailgun = require('../'); describe('EmailAnalyticsProviderMailgun', function () { - let config, settings, logging; + let config, settings; beforeEach(function () { // options objects that can be stubbed or spied config = {get() {}}; settings = {get() {}}; - logging = {warn() {}}; }); afterEach(function () { @@ -43,7 +42,7 @@ describe('EmailAnalyticsProviderMailgun', function () { items: [] }); - const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging}); + const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings}); await mailgunProvider.fetchAll(() => {}); eventsMock.isDone().should.be.true(); @@ -66,7 +65,7 @@ describe('EmailAnalyticsProviderMailgun', function () { items: [] }); - const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging}); + const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings}); await mailgunProvider.fetchAll(() => {}); eventsMock.isDone().should.be.true(); @@ -89,7 +88,7 @@ describe('EmailAnalyticsProviderMailgun', function () { items: [] }); - const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging}); + const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings}); await mailgunProvider.fetchAll(() => {}); settingsStub.withArgs('mailgun_api_key').returns('settingsApiKey2'); @@ -148,7 +147,7 @@ describe('EmailAnalyticsProviderMailgun', function () { items: [] }); - const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging}); + const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings}); const batchHandler = sinon.spy(); @@ -194,7 +193,7 @@ describe('EmailAnalyticsProviderMailgun', function () { items: [] }); - const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging}); + const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings}); const batchHandler = sinon.spy(); @@ -242,7 +241,7 @@ describe('EmailAnalyticsProviderMailgun', function () { items: [] }); - const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging}); + const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings}); const batchHandler = sinon.spy(); @@ -291,7 +290,7 @@ describe('EmailAnalyticsProviderMailgun', function () { items: [] }); - const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging}); + const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings}); const batchHandler = sinon.spy(); @@ -320,7 +319,7 @@ describe('EmailAnalyticsProviderMailgun', function () { } }; - const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging}); + const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings}); const result = mailgunProvider.normalizeEvent(event); result.should.deepEqual({