Allow skip of emailing/uploading for activity reports (#2538)

This will help us if/when we need to run the report generation multiple
times, or for past dates and we don't want to send extra emails or
upload any extra reports to ICANN.
This commit is contained in:
gbrodman
2024-08-26 20:25:31 +00:00
committed by GitHub
parent e88c6e1550
commit 1765f4f0b4
3 changed files with 74 additions and 18 deletions
@@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.cloud.tasks.v2.HttpMethod;
@@ -60,6 +61,8 @@ class IcannReportingStagingActionTest {
action.yearMonth = yearMonth;
action.overrideSubdir = Optional.of(subdir);
action.reportTypes = ImmutableSet.of(ReportType.ACTIVITY, ReportType.TRANSACTIONS);
action.sendEmail = true;
action.shouldUpload = true;
action.response = response;
action.stager = stager;
action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
@@ -154,6 +157,33 @@ class IcannReportingStagingActionTest {
cloudTasksHelper.assertNoTasksEnqueued("retryable-cron-tasks");
}
@Test
void testSkipsEmail() throws Exception {
action.sendEmail = false;
action.run();
verify(stager).stageReports(yearMonth, subdir, ReportType.ACTIVITY);
verify(stager).stageReports(yearMonth, subdir, ReportType.TRANSACTIONS);
verify(stager).createAndUploadManifest(subdir, ImmutableList.of("a", "b", "c", "d"));
verifyNoInteractions(action.gmailClient);
assertUploadTaskEnqueued();
}
@Test
void testSkipsUpload() throws Exception {
action.shouldUpload = false;
action.run();
verify(stager).stageReports(yearMonth, subdir, ReportType.ACTIVITY);
verify(stager).stageReports(yearMonth, subdir, ReportType.TRANSACTIONS);
verify(stager).createAndUploadManifest(subdir, ImmutableList.of("a", "b", "c", "d"));
verify(action.gmailClient)
.sendEmail(
EmailMessage.create(
"ICANN Monthly report staging summary [SUCCESS]",
"Completed staging the following 4 ICANN reports:\na\nb\nc\nd",
new InternetAddress("recipient@example.com")));
cloudTasksHelper.assertNoTasksEnqueued("retryable-cron-tasks");
}
@Test
void testEmptySubDir_returnsDefaultSubdir() {
action.overrideSubdir = Optional.empty();