mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
Use @tryghost/logging package instead of injected argument
refs: https://github.com/TryGhost/Toolbox/issues/146
This commit is contained in:
parent
9c9d6c2340
commit
a96cf1a39a
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user