Change BSA job status notifications (#2385)

Add error notifications for BsaDownload.

Stop sending success notifications.
This commit is contained in:
Weimin Yu
2024-03-22 19:27:25 +00:00
committed by GitHub
parent 59f4129ee0
commit 0df8372407
7 changed files with 23 additions and 18 deletions
@@ -66,6 +66,8 @@ class BsaDownloadFunctionalTest {
@Mock BlockListFetcher blockListFetcher;
@Mock BsaReportSender bsaReportSender;
@Mock BsaEmailSender bsaEmailSender;
private final FakeClock fakeClock = new FakeClock(TEST_START_TIME);
@RegisterExtension
@@ -95,6 +97,7 @@ class BsaDownloadFunctionalTest {
bsaReportSender,
gcsClient,
() -> new IdnChecker(fakeClock),
bsaEmailSender,
new BsaLock(
new FakeLockHandler(/* lockSucceeds= */ true), Duration.standardSeconds(30)),
fakeClock,
@@ -16,6 +16,7 @@ package google.registry.bsa;
import static com.google.common.base.Throwables.getStackTraceAsString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -96,14 +97,13 @@ public class BsaRefreshActionTest {
}
@Test
void notificationSent_success() {
void notification_notSent_whenNoError() {
when(bsaLock.executeWithLock(any()))
.thenAnswer(
args -> {
return true;
});
action.run();
verify(gmailClient, times(1))
.sendEmail(EmailMessage.create("BSA refreshed successfully", "", emailRecipient));
verify(gmailClient, never()).sendEmail(any());
}
}
@@ -149,7 +149,7 @@ class BsaRefreshFunctionalTest {
verify(bsaReportSender, times(1))
.addUnblockableDomainsUpdates("{\n \"reserved\": [\n \"blocked1.app\"\n ]\n}");
verify(emailSender, times(1)).sendNotification("BSA refreshed successfully", "");
verify(emailSender, never()).sendNotification(anyString(), anyString());
}
@Test
@@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -345,7 +346,7 @@ public class BsaValidateActionTest {
}
@Test
void notificationSent_noError() {
void notification_notSent_WhenNoError() {
when(bsaLock.executeWithLock(any()))
.thenAnswer(
args -> {
@@ -356,9 +357,6 @@ public class BsaValidateActionTest {
action = spy(action);
doReturn(ImmutableList.of()).when(action).checkBsaLabels(anyString());
action.run();
verify(gmailClient, times(1)).sendEmail(emailCaptor.capture());
EmailMessage message = emailCaptor.getValue();
assertThat(message.subject()).isEqualTo("BSA validation completed: no errors found");
assertThat(message.body()).isEqualTo("Most recent download is 2023-11-09t020857.880z.\n\n");
verify(gmailClient, never()).sendEmail(any());
}
}