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.
- Loading branch information
Showing
8 changed files
with
440 additions
and
26 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/org/mskcc/cbio/oncokb/config/SlackConfiguration.java
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.mskcc.cbio.oncokb.config; | ||
|
||
import com.slack.api.Slack; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SlackConfiguration { | ||
|
||
@Bean | ||
public Slack slack() { | ||
return Slack.getInstance(); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -39,7 +39,7 @@ spring: | |
type: com.zaxxer.hikari.HikariDataSource | ||
url: jdbc:mysql://localhost:3306/oncokb_public?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true | ||
username: root | ||
password: root | ||
password: annaben123 | ||
hikari: | ||
poolName: Hikari | ||
auto-commit: false | ||
|
@@ -52,11 +52,11 @@ spring: | |
show-sql: true | ||
liquibase: | ||
# Remove 'faker' if you do not want the sample data to be loaded automatically | ||
contexts: dev, faker | ||
contexts: dev | ||
mail: | ||
host: smtp.gmail.com | ||
username: | ||
password: | ||
username: [email protected] | ||
password: wambrlgrknmtaowj | ||
port: 587 | ||
protocol: smtp | ||
tls: true | ||
|
@@ -142,8 +142,8 @@ application: | |
slack: # Add the following if you wish to integrate user registration to Slack and send the weekly unapproved users email | ||
# You will need to expose your app using a public-facing URL to achieve interactivity with components (use ngrok) | ||
# specific to the app you install to your Slack workspace | ||
user-registration-webhook: # for sending user requests to Slack | ||
slack-bot-oauth-token: # for permission to read conversation history (generation of unapproved users list) | ||
user-registration-webhook: https://hooks.slack.com/services/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 # for sending user requests to Slack | ||
slack-bot-oauth-token: xoxp-4676495597-2180980600950-3967749158372-dc12ff23e1b33aaf82a9f8fb8f27a239 # for permission to read conversation history (generation of unapproved users list) | ||
# for Slack link in weekly unapproved users email | ||
slack-base-url: | ||
user-registration-channel-id: | ||
|
@@ -154,10 +154,10 @@ application: | |
password: 'oncokb-public-redis-password' | ||
address: 'redis://localhost:6379' | ||
email-addresses: | ||
license-address: | ||
registration-address: | ||
contact-address: | ||
tech-dev-address: | ||
license-address: [email protected] | ||
registration-address: [email protected] | ||
contact-address: [email protected] | ||
tech-dev-address: [email protected] | ||
public-website-api-threshold: 10 | ||
academic-email-clarify-domain: | ||
frontend: | ||
|
@@ -168,9 +168,9 @@ application: | |
recaptcha-site-key: | ||
recaptcha-threshold: 0.1 | ||
aws: | ||
s3-access-key: | ||
s3-secret-key: | ||
s3-region: | ||
s3-access-key: AKIARAXHP3JMLUTOQ4EJ | ||
s3-secret-key: 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 | ||
s3-region: us-east-1 | ||
github-token: | ||
db-read-only: false # Certain endpoints will be disabled when readonly is set to true | ||
recaptcha: | ||
|
130 changes: 130 additions & 0 deletions
130
src/test/java/org/mskcc/cbio/oncokb/service/SlackServiceIT.java
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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package org.mskcc.cbio.oncokb.service; | ||
|
||
import com.slack.api.Slack; | ||
import com.slack.api.model.block.LayoutBlock; | ||
import com.slack.api.model.block.SectionBlock; | ||
import com.slack.api.model.block.composition.TextObject; | ||
import com.slack.api.webhook.Payload; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Captor; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.Spy; | ||
import org.mskcc.cbio.oncokb.OncokbPublicApp; | ||
import org.mskcc.cbio.oncokb.config.application.ApplicationProperties; | ||
import org.mskcc.cbio.oncokb.config.application.SlackProperties; | ||
import org.mskcc.cbio.oncokb.domain.Company; | ||
import org.mskcc.cbio.oncokb.domain.enumeration.LicenseStatus; | ||
import org.mskcc.cbio.oncokb.domain.enumeration.LicenseType; | ||
import org.mskcc.cbio.oncokb.service.dto.UserDTO; | ||
import org.mskcc.cbio.oncokb.service.mapper.UserMapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@SpringBootTest(classes = OncokbPublicApp.class) | ||
class SlackServiceIT { | ||
|
||
// Testing Slack url for applicationProperties | ||
private static final String USER_REGISTRATION_WEBHOOK = "https://hooks.slack.com/example"; | ||
|
||
@Autowired | ||
private ApplicationProperties applicationProperties; | ||
|
||
@Autowired | ||
private MailService mailService; | ||
|
||
@Autowired | ||
private EmailService emailService; | ||
|
||
@Autowired | ||
private UserMailsService userMailsService; | ||
|
||
@Autowired | ||
private UserMapper userMapper; | ||
|
||
@Spy | ||
private Slack slack; | ||
|
||
@Captor | ||
private ArgumentCaptor<String> urlCaptor; | ||
|
||
@Captor | ||
private ArgumentCaptor<Payload> payloadCaptor; | ||
|
||
private SlackService slackService; | ||
|
||
@BeforeEach | ||
public void setup() throws IOException { | ||
MockitoAnnotations.initMocks(this); | ||
doReturn(null).when(slack).send(any(String.class), any(Payload.class)); | ||
|
||
// Specify webhook address for testing | ||
applicationProperties.setSlack(new SlackProperties()); | ||
applicationProperties.getSlack().setUserRegistrationWebhook(USER_REGISTRATION_WEBHOOK); | ||
|
||
slackService = new SlackService(applicationProperties, mailService, emailService, userMailsService, userMapper, slack); | ||
} | ||
|
||
@Test | ||
void testSendUserRegistrationToChannel() throws IOException { | ||
// Create mock user | ||
UserDTO user = new UserDTO(); | ||
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); | ||
|
||
// Mock send Slack blocks | ||
slackService.sendUserRegistrationToChannel(user, false, company); | ||
verify(slack).send(urlCaptor.capture(), payloadCaptor.capture()); | ||
String url = urlCaptor.getValue(); | ||
Payload payload = payloadCaptor.getValue(); | ||
|
||
// Ensure url is correct | ||
assertThat(url).isEqualTo(USER_REGISTRATION_WEBHOOK); | ||
|
||
// Ensure all crucial information is in payload | ||
Set<String> expectedValues = new HashSet<>(); | ||
expectedValues.add(LicenseType.COMMERCIAL.getName()); | ||
expectedValues.add("Not Activated"); | ||
expectedValues.add("REGULAR"); | ||
expectedValues.add("[email protected]"); | ||
expectedValues.add("john doe"); | ||
expectedValues.add("job title"); | ||
expectedValues.add("company name"); | ||
expectedValues.add("city"); | ||
expectedValues.add("country"); | ||
for (LayoutBlock block : payload.getBlocks()) { | ||
if (block instanceof SectionBlock) { | ||
SectionBlock sectionBlock = (SectionBlock) block; | ||
if (sectionBlock.getText() != null) { | ||
expectedValues.removeIf(sectionBlock.getText().getText()::contains); | ||
} | ||
if (sectionBlock.getFields() != null) { | ||
for (TextObject textObject : sectionBlock.getFields()) { | ||
expectedValues.removeIf(textObject.getText()::contains); | ||
} | ||
} | ||
} | ||
} | ||
assertThat(expectedValues).isEmpty(); | ||
} | ||
} |
Oops, something went wrong.