mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-09 14:33:44 +08:00
Implement a participant cap for multi-send, add multi-send unit tests
Summary: Prevent hitting SMTP rate limit with multi-send Some users were hitting the SMTP rate limit when sending messages with multi-send to too many recipients. There is a backend patch to help with this, but we decided it would be useful to limit it on the client side as well. Test Plan: Added unit tests Reviewers: jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3109
This commit is contained in:
parent
d55616ca14
commit
7ca9f7667c
2 changed files with 98 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
APIError,
|
||||
Actions,
|
||||
AccountStore,
|
||||
DatabaseStore,
|
||||
DatabaseTransaction,
|
||||
Message,
|
||||
|
@ -537,4 +538,95 @@ describe('SendDraftTask', function sendDraftTask() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("usingMultiSend", () => {
|
||||
beforeEach(() => {
|
||||
this.task = new SendDraftTask('client-id');
|
||||
this.task.allowMultiSend = true;
|
||||
this.task.draft = new Message({
|
||||
version: 1,
|
||||
clientId: 'client-id',
|
||||
serverId: 'server-123',
|
||||
accountId: TEST_ACCOUNT_ID,
|
||||
from: [new Contact({email: TEST_ACCOUNT_EMAIL})],
|
||||
subject: 'New Draft',
|
||||
draft: true,
|
||||
body: 'hello world',
|
||||
to: {
|
||||
name: 'Dummy',
|
||||
email: 'dummythis.nylas.com',
|
||||
},
|
||||
uploads: [],
|
||||
});
|
||||
this.task.draft.applyPluginMetadata('open-tracking', true);
|
||||
this.task.draft.applyPluginMetadata('link-tracking', true);
|
||||
|
||||
this.applySpies = (customValues = {}) => {
|
||||
let value = {provider: customValues["AccountStore.accountForId"] || "gmail"}
|
||||
spyOn(AccountStore, "accountForId").andReturn(value)
|
||||
|
||||
value = customValues["NylasEnv.packages.pluginIdFor"] || (name => name)
|
||||
spyOn(NylasEnv.packages, "pluginIdFor").andCallFake(value);
|
||||
|
||||
value = {length: customValues["draft.participants"] || 5}
|
||||
spyOn(this.task.draft, "participants").andReturn(value);
|
||||
}
|
||||
});
|
||||
|
||||
it("should return false if the provider is eas", () => {
|
||||
this.applySpies({"AccountStore.accountForId": "eas"})
|
||||
expect(this.task.usingMultiSend()).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if allowMultiSend is false", () => {
|
||||
this.applySpies();
|
||||
this.task.allowMultiSend = false;
|
||||
expect(this.task.usingMultiSend()).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if the open-tracking id is null", () => {
|
||||
const fake = (name) => {
|
||||
return name === "open-tracking" ? null : name;
|
||||
};
|
||||
this.applySpies({"NylasEnv.packages.pluginIdFor": fake});
|
||||
expect(this.task.usingMultiSend()).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if the link-tracking id is null", () => {
|
||||
const fake = (name) => {
|
||||
return name === "link-tracking" ? null : name;
|
||||
};
|
||||
this.applySpies({"NylasEnv.packages.pluginIdFor": fake});
|
||||
expect(this.task.usingMultiSend()).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false if neither open-tracking nor link-tracking is on", () => {
|
||||
this.applySpies();
|
||||
this.task.draft.applyPluginMetadata('open-tracking', false);
|
||||
this.task.draft.applyPluginMetadata('link-tracking', false);
|
||||
expect(this.task.usingMultiSend()).toBe(false);
|
||||
});
|
||||
|
||||
it("should return true if only open-tracking is on", () => {
|
||||
this.applySpies();
|
||||
this.task.draft.applyPluginMetadata('link-tracking', false);
|
||||
expect(this.task.usingMultiSend()).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true if only link-tracking is on", () => {
|
||||
this.applySpies();
|
||||
this.task.draft.applyPluginMetadata('open-tracking', false);
|
||||
expect(this.task.usingMultiSend()).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if there are too many participants", () => {
|
||||
this.applySpies({"draft.participants": 15});
|
||||
expect(this.task.usingMultiSend()).toBe(false);
|
||||
});
|
||||
|
||||
it("should return true otherwise", () => {
|
||||
this.applySpies();
|
||||
expect(this.task.usingMultiSend()).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -64,6 +64,12 @@ export default class SendDraftTask extends BaseDraftTask {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Sending individual bodies for too many participants can cause us
|
||||
// to hit the smtp rate limit.
|
||||
if (this.draft.participants({includeFrom: false}).length > 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const openTrackingId = NylasEnv.packages.pluginIdFor('open-tracking')
|
||||
const linkTrackingId = NylasEnv.packages.pluginIdFor('link-tracking')
|
||||
|
||||
|
|
Loading…
Reference in a new issue