Skip to content

Commit

Permalink
Add remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benzuzu committed Aug 9, 2023
1 parent 3fc6d65 commit 49159e6
Show file tree
Hide file tree
Showing 6 changed files with 487 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mskcc.cbio.oncokb.domain.enumeration;

import org.mskcc.cbio.oncokb.web.rest.slack.DropdownEmailOption;

import java.util.Optional;

/**
Expand Down Expand Up @@ -86,7 +88,8 @@ public enum MailType {
, ACTIVATE_FREE_TRIAL(new MailTypeBuilder()
.templateName("activateFreeTrial")
.description("OncoKB Trial Activation Link")
.titleKey("email.active.free.trial.title"))
.titleKey("email.active.free.trial.title")
.stringTemplateName("activateFreeTrialString.txt"))
, TRIAL_ACCOUNT_IS_ABOUT_TO_EXPIRE(new MailTypeBuilder()
.templateName("trialAccountIsAboutToExpire")
.description("Trail account is about to expire"))
Expand Down Expand Up @@ -181,4 +184,15 @@ public Optional<String> getStringTemplateName() {
public Optional<String> getAttachmentFileNames() {
return attachmentFileNames;
}

public static boolean isDropdownEmail(MailType mailType) {
if (mailType == null) {
return false;
}
for (DropdownEmailOption mailOption : DropdownEmailOption.values()) {
if (mailType.equals(mailOption.getMailType()))
return true;
}
return false;
}
}
13 changes: 8 additions & 5 deletions src/main/java/org/mskcc/cbio/oncokb/service/SlackService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public class SlackService {

private final Logger log = LoggerFactory.getLogger(SlackService.class);

private final String VALUE_SEPARATOR = "-";
public final static String VALUE_SEPARATOR = "-";
public final static String APPROVE_USER_EXPANDED_NOTE = "The user has been approved and notified.";
public final static String CONVERT_TO_REGULAR_ACCOUNT_EXPANDED_NOTE = "The trial account has been converted to a regular account.";

private final ApplicationProperties applicationProperties;
private final MailService mailService;
private final EmailService emailService;
Expand Down Expand Up @@ -380,7 +383,7 @@ private LayoutBlock buildAccountStatusBlock(UserDTO userDTO, boolean isTrialAcco
return SectionBlock.builder().fields(userInfo).blockId(ACCOUNT_STATUS.getId()).build();
}

private String getOptionValue(String argument, String login) {
public String getOptionValue(String argument, String login) {
return String.join(VALUE_SEPARATOR, argument, login);
}

Expand Down Expand Up @@ -520,9 +523,9 @@ private List<LayoutBlock> buildAdditionalInfoBlocks(UserDTO userDTO, boolean tri
}
if (userDTO.isActivated() && !trialAccountActivated) {
if (!withNote(DropdownEmailOption.GIVE_TRIAL_ACCESS, userDTO, actionId)) {
layoutBlocks.add(buildPlainTextBlock("The user has been approved and notified.", APPROVED_NOTE));
layoutBlocks.add(buildPlainTextBlock(APPROVE_USER_EXPANDED_NOTE, APPROVED_NOTE));
} else {
layoutBlocks.add(buildPlainTextBlock("The trial account has been converted to a regular account.", CONVERT_TO_REGULAR_ACCOUNT_NOTE));
layoutBlocks.add(buildPlainTextBlock(CONVERT_TO_REGULAR_ACCOUNT_EXPANDED_NOTE, CONVERT_TO_REGULAR_ACCOUNT_NOTE));
}
} else if (withNote(DropdownEmailOption.GIVE_TRIAL_ACCESS, userDTO, actionId)) {
layoutBlocks.add(buildPlainTextBlock(DropdownEmailOption.GIVE_TRIAL_ACCESS.getExpandedNote(), TRIAL_ACCOUNT_NOTE));
Expand Down Expand Up @@ -738,7 +741,7 @@ private LayoutBlock buildPlainTextBlock(String text, BlockId blockId) {
return null;
}

private String getStringFromResourceTemplateMailTextFile(String fileName) {
public String getStringFromResourceTemplateMailTextFile(String fileName) {
StringBuilder sb = new StringBuilder();

URL targetFileUrl = getClass().getClassLoader().getResource("templates/mail/" + fileName);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/mskcc/cbio/oncokb/web/rest/slack/ActionId.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ public static boolean isModalEmailAction(ActionId actionId) {
return false;
}

public static boolean isConfirmEmailAction(ActionId actionId) {
if (actionId == null) {
return false;
}
for (DropdownEmailOption mailOption : DropdownEmailOption.values()) {
if (actionId.equals(mailOption.getConfirmActionId().orElse(null)))
return true;
}
return false;
}

public static boolean isDropdownAction(ActionId actionId) {
if (actionId == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* options in the Slack dropdown menu that the team can select.
* Approval is not included as the logic is complex and unique.
*
* To add a new email option, add the following fields:
* To add a new email option, add the following fields (you will
* need to create some of these in their respective classes as
* well, namely ActionId, BlockId, and MailType):
*
* REQUIRED:
* - Block blockId (the corresponding BlockId enum constant
Expand Down
Loading

0 comments on commit 49159e6

Please sign in to comment.