Added additional tests for email analytics (#20805)

ref 4267ff9
- unit tests didn't cover what events were passed along to be fetched,
important now that it's split out
This commit is contained in:
Steve Larson 2024-08-20 18:30:54 -05:00 committed by GitHub
parent 3c9b8d682d
commit 54b0b87633
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 2 deletions

View File

@ -99,7 +99,7 @@ module.exports = class EmailAnalyticsService {
};
}
return await this.#fetchEvents(this.#fetchLatestOpenedData, {begin, end, maxEvents, events: ['opened']});
return await this.#fetchEvents(this.#fetchLatestOpenedData, {begin, end, maxEvents, eventTypes: ['opened']});
}
async fetchLatestNonOpenedEvents({maxEvents = Infinity} = {}) {
@ -120,7 +120,7 @@ module.exports = class EmailAnalyticsService {
};
}
return await this.#fetchEvents(this.#fetchLatestNonOpenedData, {begin, end, maxEvents, events: ['delivered', 'failed', 'unsubscribed', 'complained']});
return await this.#fetchEvents(this.#fetchLatestNonOpenedData, {begin, end, maxEvents, eventTypes: ['delivered', 'failed', 'unsubscribed', 'complained']});
}
/**

View File

@ -75,6 +75,44 @@ describe('EmailAnalyticsService', function () {
});
});
describe('Fetching events', function () {
afterEach(function () {
sinon.restore();
});
describe('fetchLatestOpenedEvents', function () {
it('fetches only opened events', async function () {
const fetchLatestSpy = sinon.spy();
const service = new EmailAnalyticsService({
queries: {
getLastEventTimestamp: sinon.stub().resolves()
},
providers: [{
fetchLatest: fetchLatestSpy
}]
});
await service.fetchLatestOpenedEvents();
fetchLatestSpy.calledOnce.should.be.true();
fetchLatestSpy.getCall(0).args[1].should.have.property('events', ['opened']);
});
});
describe('fetchLatestNonOpenedEvents', function () {
it('fetches only non-opened events', async function () {
const fetchLatestSpy = sinon.spy();
const service = new EmailAnalyticsService({
queries: {
getLastEventTimestamp: sinon.stub().resolves()
},
providers: [{
fetchLatest: fetchLatestSpy
}]
});
await service.fetchLatestNonOpenedEvents();
fetchLatestSpy.calledOnce.should.be.true();
fetchLatestSpy.getCall(0).args[1].should.have.property('events', ['delivered', 'failed', 'unsubscribed', 'complained']);
});
});
});
describe('processEventBatch', function () {
let eventProcessor;
beforeEach(function () {