forked from oncokb/oncokb-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slack reports error and limits justification section
- Loading branch information
Showing
4 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
import com.slack.api.model.block.SectionBlock; | ||
import com.slack.api.model.block.composition.TextObject; | ||
import com.slack.api.webhook.Payload; | ||
import com.slack.api.webhook.WebhookResponse; | ||
|
||
import io.sentry.SentryLevel; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
@@ -23,6 +27,7 @@ | |
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
|
@@ -42,9 +47,6 @@ class SlackServiceIT { | |
@Autowired | ||
private MailService mailService; | ||
|
||
@Autowired | ||
private EmailService emailService; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
|
@@ -57,6 +59,9 @@ class SlackServiceIT { | |
@Spy | ||
private Slack slack; | ||
|
||
@Spy | ||
private SentryService sentryService; | ||
|
||
@Captor | ||
private ArgumentCaptor<String> urlCaptor; | ||
|
||
|
@@ -75,13 +80,21 @@ public void setup() throws IOException { | |
applicationProperties.setSlack(new SlackProperties()); | ||
applicationProperties.getSlack().setUserRegistrationWebhook(USER_REGISTRATION_WEBHOOK); | ||
|
||
slackService = new SlackService(applicationProperties, mailService, emailService, userService, userMailsService, userMapper, slack); | ||
slackService = new SlackService(applicationProperties, mailService, userService, userMailsService, userMapper, slack, sentryService); | ||
} | ||
|
||
private void setMockResponse(Integer code) throws IOException { | ||
WebhookResponse response = WebhookResponse.builder() | ||
.code(code) | ||
.build(); | ||
doReturn(response).when(slack).send(any(String.class), any(Payload.class)); | ||
} | ||
|
||
@Test | ||
void testSendUserRegistrationToChannel() throws IOException { | ||
// Create mock user | ||
UserDTO user = new UserDTO(); | ||
setMockResponse(200); | ||
user.setId(0L); | ||
user.setEmail("[email protected]"); | ||
user.setFirstName("john"); | ||
|
@@ -131,4 +144,28 @@ void testSendUserRegistrationToChannel() throws IOException { | |
} | ||
assertThat(expectedValues).isEmpty(); | ||
} | ||
|
||
@Test | ||
void testSend400Response() throws IOException { | ||
// Create mock user | ||
UserDTO user = new UserDTO(); | ||
setMockResponse(400); | ||
user.setId(0L); | ||
user.setEmail("[email protected]"); | ||
user.setFirstName("john"); | ||
user.setLastName("doe"); | ||
user.setJobTitle("job title"); | ||
user.setCompanyName("company name"); | ||
user.setCity("city"); | ||
user.setCountry("country"); | ||
user.setLicenseType(LicenseType.COMMERCIAL); | ||
Company company = new Company(); | ||
company.setName("company name"); | ||
company.setLicenseType(LicenseType.COMMERCIAL); | ||
company.setLicenseStatus(LicenseStatus.UNKNOWN); | ||
|
||
slackService.sendUserRegistrationToChannel(user, false, company); | ||
verify(slack).send(urlCaptor.capture(), payloadCaptor.capture()); | ||
verify(sentryService).throwMessage(eq(SentryLevel.ERROR), anyString(), isNull()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters