Skip to content

Commit

Permalink
fix: don't call post send hook in test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Gum-Joe committed Aug 13, 2024
1 parent 4e7b514 commit bf97bf1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion email/mailmerge/src/pipelines/send.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe("sendEmails", () => {
expect(mockMailer.sendMail).toHaveBeenCalledTimes(1);
});

it("should send to test email if given and not cc or bcc anyone in", async () => {
it("should send to test email if given, not cc or bcc anyone in and not call post send hooks", async () => {
const mergeResults: MergeResultWithMetadata<unknown>[] = [
{
record: { field1: "value1" },
Expand Down Expand Up @@ -168,6 +168,7 @@ describe("sendEmails", () => {
bcc: [],
},
);
expect(mockStorageBackend.postSendAction).not.toHaveBeenCalled();
});

it("should refuse test send if onlySend is not set", async () => {
Expand Down
3 changes: 2 additions & 1 deletion email/mailmerge/src/pipelines/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export async function sendEmails(
}
logger.warn("");
logger.warn(`Will send ${options.onlySend} emails to ${options.testSendTo} as a test.`);
logger.warn("Note that post send hooks will not be called in test mode.");
logger.warn("");
}

Expand Down Expand Up @@ -167,7 +168,7 @@ You are about to send ${emailsNumberDisplay} emails. The esitmated time for this
},
);

if (storageBackend.postSendAction) {
if (storageBackend.postSendAction && !options.testSendTo) {
logger.debug("Calling post-send hook...");
await storageBackend.postSendAction(originalResult, PostSendActionMode.SMTP_SEND);
}
Expand Down
2 changes: 1 addition & 1 deletion email/workspace/quick-run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docsoc-mailmerge generate nunjucks ./data/names.csv -o ./output -n test -b -c
docsoc-mailmerge regenerate ./output/test
# docsoc-mailmerge upload-drafts ./output/test -y -s 2 -n 1
docsoc-mailmerge send ./output/test -s 5 -n 2 -t "kss22@ic.ac.uk"
docsoc-mailmerge send ./output/test -s 5 -n 1 -t "kss22@ic.ac.uk"

0 comments on commit bf97bf1

Please sign in to comment.