Skip to content

Commit 8d2607d

Browse files
committed
Fixed test errors.
1 parent 173f552 commit 8d2607d

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

server/src/main/java/com/objectcomputing/checkins/services/slack/SlackSubmissionHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
import com.fasterxml.jackson.core.type.TypeReference;
2020
import com.fasterxml.jackson.core.JsonProcessingException;
2121

22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
2225
import java.util.Map;
2326
import java.nio.charset.StandardCharsets;
2427

2528
@Singleton
2629
public class SlackSubmissionHandler {
27-
private final String typeKey = "type";
30+
private static final Logger LOG = LoggerFactory.getLogger(SlackSubmissionHandler.class);
31+
private static final String typeKey = "type";
2832

2933
private final PulseResponseService pulseResponseServices;
3034
private final SlackSignatureVerifier slackSignatureVerifier;
@@ -96,6 +100,7 @@ public HttpResponse externalResponse(String signature,
96100
}
97101
} catch(JsonProcessingException ex) {
98102
// Fall through to the bottom...
103+
LOG.error("externalResponse: " + ex.toString());
99104
}
100105
}
101106
} else {

server/src/test/java/com/objectcomputing/checkins/services/SlackSearchReplacement.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ public SlackSearchReplacement(CheckInsConfiguration checkInsConfiguration) {
2525
super(checkInsConfiguration);
2626
}
2727

28+
@Override
29+
public String findChannelName(String channelId) {
30+
return channels.containsKey(channelId) ?
31+
channels.get(channelId) : null;
32+
}
33+
2834
@Override
2935
public String findChannelId(String channelName) {
30-
return channels.containsKey(channelName) ?
31-
channels.get(channelName) : null;
36+
for (Map.Entry<String, String> entry : channels.entrySet()) {
37+
if (entry.getValue().equals(channelName)) {
38+
return entry.getKey();
39+
}
40+
}
41+
return null;
3242
}
3343

3444
@Override

server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.nio.charset.StandardCharsets;
3838
import java.util.Base64;
3939
import java.time.Instant;
40+
import java.net.URLEncoder;
4041

4142
import static com.objectcomputing.checkins.services.role.RoleType.Constants.ADMIN_ROLE;
4243
import static com.objectcomputing.checkins.services.role.RoleType.Constants.MEMBER_ROLE;
@@ -536,9 +537,10 @@ void testUpdateInvalidDatePulseResponse() {
536537
@Test
537538
void testCreateAPulseResponseFromSlack() {
538539
MemberProfile memberProfile = createADefaultMemberProfile();
539-
slackSearch.users.put("SLACK_ID_HI", memberProfile.getWorkEmail());
540+
String slackId = "SLACK_ID_HI";
541+
slackSearch.users.put(slackId, memberProfile.getWorkEmail());
540542

541-
final String rawBody = "payload=%7B%22type%22%3A+%22view_submission%22%2C+%22user%22%3A+%7B%22id%22%3A+%22SLACK_ID_HI%22%7D%2C+%22view%22%3A+%7B%22id%22%3A+%22VNHU13V36%22%2C+%22type%22%3A+%22modal%22%2C+%22state%22%3A+%7B%22values%22%3A+%7B%22internalNumber%22%3A+%7B%22internalScore%22%3A+%7B%22selected_option%22%3A+%7B%22type%22%3A+%22radio_buttons%22%2C+%22value%22%3A+%224%22%7D%7D%7D%2C+%22internalText%22%3A+%7B%22internalFeelings%22%3A+%7B%22type%22%3A+%22plain_text_input%22%2C+%22value%22%3A+%22I+am+a+robot.%22%7D%7D%2C+%22externalNumber%22%3A+%7B%22externalScore%22%3A+%7B%22selected_option%22%3A+%7B%22type%22%3A+%22radio_buttons%22%2C+%22value%22%3A+%225%22%7D%7D%7D%2C+%22externalText%22%3A+%7B%22externalFeelings%22%3A+%7B%22type%22%3A+%22plain_text_input%22%2C+%22value%22%3A+%22You+are+a+robot.%22%7D%7D%7D%7D%7D%7D";
543+
final String rawBody = getSlackPulsePayload(slackId);
542544

543545
long currentTime = Instant.now().getEpochSecond();
544546
String timestamp = String.valueOf(currentTime);
@@ -603,4 +605,53 @@ private MemberProfile profile(String key) {
603605
private UUID id(String key) {
604606
return profile(key).getId();
605607
}
608+
609+
private String getSlackPulsePayload(String slackId) {
610+
return "payload=" +
611+
URLEncoder.encode(String.format("""
612+
{
613+
"type": "view_submission",
614+
"user": {
615+
"id": "%s"
616+
},
617+
"view": {
618+
"id": "VNHU13V36",
619+
"type": "modal",
620+
"callback_id": "pulseSubmission",
621+
"state": {
622+
"values": {
623+
"internalNumber": {
624+
"internalScore": {
625+
"selected_option": {
626+
"type": "radio_buttons",
627+
"value": "4"
628+
}
629+
}
630+
},
631+
"internalText": {
632+
"internalFeelings": {
633+
"type": "plain_text_input",
634+
"value": "I am a robot."
635+
}
636+
},
637+
"externalNumber": {
638+
"externalScore": {
639+
"selected_option": {
640+
"type": "radio_buttons",
641+
"value": "5"
642+
}
643+
}
644+
},
645+
"externalText": {
646+
"externalFeelings": {
647+
"type": "plain_text_input",
648+
"value": "You are a robot."
649+
}
650+
}
651+
}
652+
}
653+
}
654+
}
655+
""", slackId));
656+
}
606657
}

server/src/test/resources/application-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ check-ins:
4545
webhook-url: https://bogus.objectcomputing.com/slack
4646
bot-token: BOGUS_TOKEN
4747
signing-secret: BOGUS_SIGNING_SECRET
48+
kudos-channel: SLACK_KUDOS_CHANNEL_ID
4849
---
4950
aes:
5051
key: BOGUS_TEST_KEY

0 commit comments

Comments
 (0)