mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +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 mailgunJs = require('mailgun-js');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const {EventProcessingResult} = require('@tryghost/email-analytics-service');
|
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 EVENT_FILTER = 'delivered OR opened OR failed OR unsubscribed OR complained';
|
||||||
const PAGE_LIMIT = 300;
|
const PAGE_LIMIT = 300;
|
||||||
@ -9,10 +10,9 @@ const TRUST_THRESHOLD_S = 30 * 60; // 30 minutes
|
|||||||
const DEFAULT_TAGS = ['bulk-email'];
|
const DEFAULT_TAGS = ['bulk-email'];
|
||||||
|
|
||||||
class EmailAnalyticsProviderMailgun {
|
class EmailAnalyticsProviderMailgun {
|
||||||
constructor({config, settings, mailgun, logging = console} = {}) {
|
constructor({config, settings, mailgun} = {}) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.logging = logging;
|
|
||||||
this.tags = [...DEFAULT_TAGS];
|
this.tags = [...DEFAULT_TAGS];
|
||||||
this._mailgun = mailgun;
|
this._mailgun = mailgun;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class EmailAnalyticsProviderMailgun {
|
|||||||
const hasMailgunSetting = !!(bulkEmailSetting && bulkEmailSetting.apiKey && bulkEmailSetting.baseUrl && bulkEmailSetting.domain);
|
const hasMailgunSetting = !!(bulkEmailSetting && bulkEmailSetting.apiKey && bulkEmailSetting.baseUrl && bulkEmailSetting.domain);
|
||||||
|
|
||||||
if (!hasMailgunConfig && !hasMailgunSetting) {
|
if (!hasMailgunConfig && !hasMailgunSetting) {
|
||||||
this.logging.warn(`Bulk email service is not configured`);
|
logging.warn(`Bulk email service is not configured`);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class EmailAnalyticsProviderMailgun {
|
|||||||
const {mailgun} = this;
|
const {mailgun} = this;
|
||||||
|
|
||||||
if (!mailgun) {
|
if (!mailgun) {
|
||||||
this.logging.warn(`Bulk email service is not configured`);
|
logging.warn(`Bulk email service is not configured`);
|
||||||
return new EventProcessingResult();
|
return new EventProcessingResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tryghost/email-analytics-service": "^1.0.4",
|
"@tryghost/email-analytics-service": "^1.0.4",
|
||||||
|
"@tryghost/logging": "^1.0.2",
|
||||||
"mailgun-js": "^0.22.0",
|
"mailgun-js": "^0.22.0",
|
||||||
"moment": "^2.29.1"
|
"moment": "^2.29.1"
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,12 @@ const sinon = require('sinon');
|
|||||||
const EmailAnalyticsProviderMailgun = require('../');
|
const EmailAnalyticsProviderMailgun = require('../');
|
||||||
|
|
||||||
describe('EmailAnalyticsProviderMailgun', function () {
|
describe('EmailAnalyticsProviderMailgun', function () {
|
||||||
let config, settings, logging;
|
let config, settings;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// options objects that can be stubbed or spied
|
// options objects that can be stubbed or spied
|
||||||
config = {get() {}};
|
config = {get() {}};
|
||||||
settings = {get() {}};
|
settings = {get() {}};
|
||||||
logging = {warn() {}};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@ -43,7 +42,7 @@ describe('EmailAnalyticsProviderMailgun', function () {
|
|||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging});
|
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings});
|
||||||
await mailgunProvider.fetchAll(() => {});
|
await mailgunProvider.fetchAll(() => {});
|
||||||
|
|
||||||
eventsMock.isDone().should.be.true();
|
eventsMock.isDone().should.be.true();
|
||||||
@ -66,7 +65,7 @@ describe('EmailAnalyticsProviderMailgun', function () {
|
|||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging});
|
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings});
|
||||||
await mailgunProvider.fetchAll(() => {});
|
await mailgunProvider.fetchAll(() => {});
|
||||||
|
|
||||||
eventsMock.isDone().should.be.true();
|
eventsMock.isDone().should.be.true();
|
||||||
@ -89,7 +88,7 @@ describe('EmailAnalyticsProviderMailgun', function () {
|
|||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging});
|
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings});
|
||||||
await mailgunProvider.fetchAll(() => {});
|
await mailgunProvider.fetchAll(() => {});
|
||||||
|
|
||||||
settingsStub.withArgs('mailgun_api_key').returns('settingsApiKey2');
|
settingsStub.withArgs('mailgun_api_key').returns('settingsApiKey2');
|
||||||
@ -148,7 +147,7 @@ describe('EmailAnalyticsProviderMailgun', function () {
|
|||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging});
|
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings});
|
||||||
|
|
||||||
const batchHandler = sinon.spy();
|
const batchHandler = sinon.spy();
|
||||||
|
|
||||||
@ -194,7 +193,7 @@ describe('EmailAnalyticsProviderMailgun', function () {
|
|||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging});
|
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings});
|
||||||
|
|
||||||
const batchHandler = sinon.spy();
|
const batchHandler = sinon.spy();
|
||||||
|
|
||||||
@ -242,7 +241,7 @@ describe('EmailAnalyticsProviderMailgun', function () {
|
|||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging});
|
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings});
|
||||||
|
|
||||||
const batchHandler = sinon.spy();
|
const batchHandler = sinon.spy();
|
||||||
|
|
||||||
@ -291,7 +290,7 @@ describe('EmailAnalyticsProviderMailgun', function () {
|
|||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings, logging});
|
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings});
|
||||||
|
|
||||||
const batchHandler = sinon.spy();
|
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);
|
const result = mailgunProvider.normalizeEvent(event);
|
||||||
|
|
||||||
result.should.deepEqual({
|
result.should.deepEqual({
|
||||||
|
Loading…
Reference in New Issue
Block a user