mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Moved Mailgun settings test to mailgun-client
- this test checks that the mailgun client respects the changes in settings, which is something that we used to ask `email-analytics-provider-mailgun` to do when the mailgun client was made in that package - since then, we've pulled it out, so we should move the test to the `mailgun-client` library
This commit is contained in:
parent
98bd5423fa
commit
9401d835ce
@ -21,47 +21,6 @@ describe('EmailAnalyticsProviderMailgun', function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('respects changes in settings', async function () {
|
||||
const settingsStub = sinon.stub(settings, 'get');
|
||||
settingsStub.withArgs('mailgun_api_key').returns('settingsApiKey');
|
||||
settingsStub.withArgs('mailgun_domain').returns('settingsdomain.com');
|
||||
settingsStub.withArgs('mailgun_base_url').returns('https://example.com/v3');
|
||||
|
||||
const eventsMock1 = nock('https://example.com')
|
||||
.get('/v3/settingsdomain.com/events')
|
||||
.query({
|
||||
event: 'delivered OR opened OR failed OR unsubscribed OR complained',
|
||||
limit: 300,
|
||||
tags: 'bulk-email'
|
||||
})
|
||||
.reply(200, {'Content-Type': 'application/json'}, {
|
||||
items: []
|
||||
});
|
||||
|
||||
const mailgunProvider = new EmailAnalyticsProviderMailgun({config, settings});
|
||||
await mailgunProvider.fetchAll(() => {});
|
||||
|
||||
settingsStub.withArgs('mailgun_api_key').returns('settingsApiKey2');
|
||||
settingsStub.withArgs('mailgun_domain').returns('settingsdomain2.com');
|
||||
settingsStub.withArgs('mailgun_base_url').returns('https://example2.com/v3');
|
||||
|
||||
const eventsMock2 = nock('https://example2.com')
|
||||
.get('/v3/settingsdomain2.com/events')
|
||||
.query({
|
||||
event: 'delivered OR opened OR failed OR unsubscribed OR complained',
|
||||
limit: 300,
|
||||
tags: 'bulk-email'
|
||||
})
|
||||
.reply(200, {'Content-Type': 'application/json'}, {
|
||||
items: []
|
||||
});
|
||||
|
||||
await mailgunProvider.fetchAll(() => {});
|
||||
|
||||
eventsMock1.isDone().should.be.true();
|
||||
eventsMock2.isDone().should.be.true();
|
||||
});
|
||||
|
||||
describe('fetchAll()', function () {
|
||||
it('fetches from now and works backwards', async function () {
|
||||
const configStub = sinon.stub(config, 'get');
|
||||
|
@ -1,4 +1,5 @@
|
||||
const assert = require('assert');
|
||||
const nock = require('nock');
|
||||
const sinon = require('sinon');
|
||||
|
||||
// module under test
|
||||
@ -46,6 +47,45 @@ describe('MailgunClient', function () {
|
||||
assert.equal(mailgunClient.isConfigured(), false);
|
||||
});
|
||||
|
||||
it('respects changes in settings', async function () {
|
||||
const settingsStub = sinon.stub(settings, 'get');
|
||||
settingsStub.withArgs('mailgun_api_key').returns('settingsApiKey');
|
||||
settingsStub.withArgs('mailgun_domain').returns('settingsdomain.com');
|
||||
settingsStub.withArgs('mailgun_base_url').returns('https://example.com/v3');
|
||||
|
||||
const mailgunOptions = {
|
||||
event: 'delivered OR opened OR failed OR unsubscribed OR complained',
|
||||
limit: 300,
|
||||
tags: 'bulk-email'
|
||||
};
|
||||
|
||||
const eventsMock1 = nock('https://example.com')
|
||||
.get('/v3/settingsdomain.com/events')
|
||||
.query(mailgunOptions)
|
||||
.reply(200, {'Content-Type': 'application/json'}, {
|
||||
items: []
|
||||
});
|
||||
|
||||
const mailgunClient = new MailgunClient({config, settings});
|
||||
await mailgunClient.fetchEvents(mailgunOptions, () => {});
|
||||
|
||||
settingsStub.withArgs('mailgun_api_key').returns('settingsApiKey2');
|
||||
settingsStub.withArgs('mailgun_domain').returns('settingsdomain2.com');
|
||||
settingsStub.withArgs('mailgun_base_url').returns('https://example2.com/v3');
|
||||
|
||||
const eventsMock2 = nock('https://example2.com')
|
||||
.get('/v3/settingsdomain2.com/events')
|
||||
.query(mailgunOptions)
|
||||
.reply(200, {'Content-Type': 'application/json'}, {
|
||||
items: []
|
||||
});
|
||||
|
||||
await mailgunClient.fetchEvents(mailgunOptions, () => {});
|
||||
|
||||
assert.equal(eventsMock1.isDone(), true);
|
||||
assert.equal(eventsMock2.isDone(), true);
|
||||
});
|
||||
|
||||
describe('normalizeEvent()', function () {
|
||||
it('works', function () {
|
||||
const event = {
|
||||
|
Loading…
Reference in New Issue
Block a user