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:
Daniel Lockyer 2022-08-10 18:23:15 +02:00
parent 98bd5423fa
commit 9401d835ce
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD
2 changed files with 40 additions and 41 deletions

View File

@ -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');

View File

@ -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 = {