Skip to content

Commit

Permalink
Merge pull request #187 from Re-4aliens/fix/#186_change-matched-notif…
Browse files Browse the repository at this point in the history
…ication

fix(FcmSender) : sendMatchedNotification의 알림 전송 방식을 multi -> single 로 변경
  • Loading branch information
suhyun0918 authored Oct 17, 2024
2 parents 1258691 + 5170822 commit 4486c8d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void sendMatchedNotification() {
MatchingResultGroup matchingResultGroup = MatchingResultGroup.of(previousMatchingResults);
Set<Member> matchedMemberSet = matchingResultGroup.getMatchedMemberSet();
if (!matchedMemberSet.isEmpty()) {
fcmSender.sentMatchingNotification(matchedMemberSet);
fcmSender.sendMatchedNotification(matchedMemberSet);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FcmSender {

public FcmSender(MemberRepository memberRepository,
FcmTokenRepository fcmTokenRepository,
ObjectMapper objectMapper) {
ObjectMapper objectMapper) {
this.memberRepository = memberRepository;
this.fcmTokenRepository = fcmTokenRepository;
this.objectMapper = objectMapper;
Expand Down Expand Up @@ -111,18 +111,19 @@ private void sendSingleFcm(Message message) {
}
}

public void sentMatchingNotification(Set<Member> members) {
public void sendMatchedNotification(Set<Member> members) {
List<String> tokens = members.stream().map(this::findFcmTokenByMember).toList();
Notification notification = Notification.builder()
.setTitle(MATCHING_SUCCESS_MESSAGE_TITLE)
.setBody(MATCHING_SUCCESS_MESSAGE_BODY)
.build();

MulticastMessage multicastMessage = MulticastMessage.builder()
.addAllTokens(tokens)
.setNotification(notification)
.build();

sendMultiFcm(multicastMessage);
tokens.forEach(token -> {
Message message = Message.builder()
.setToken(token)
.setNotification(notification)
.build();
sendSingleFcm(message);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void setUpSpy() {

//FCM
doNothing().when(fcmSender).sendChatMessage(any());
doNothing().when(fcmSender).sentMatchingNotification(any());
doNothing().when(fcmSender).sendMatchedNotification(any());
doNothing().when(fcmSender).sendBoardNotification(any(),any());

//AWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import com.aliens.backend.mathcing.service.MatchingRoundService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.DayOfWeek;
Expand All @@ -28,7 +26,6 @@
class MatchingRoundServiceTest extends BaseIntegrationTest {
@Autowired MatchingRoundRepository matchingRoundRepository;
@Autowired MatchingTimeProperties matchingTimeProperties;
// @Autowired MatchingResultRepository matchingResultRepository;
@Autowired MatchingRoundService matchingRoundService;
@Autowired DummyGenerator dummyGenerator;
@Autowired MockClock mockClock;
Expand Down Expand Up @@ -71,7 +68,6 @@ private MatchingRound getCurrentRound() {
@Test
@DisplayName("매칭 회차가 업데이트 된 00시에 매칭된 회원들에게 알림이 발송됨")
void sendMatchedNotification() {
Logger log = LoggerFactory.getLogger("테스트 로그");
// given
List<Member> members = dummyGenerator.generateMultiMember(5);
dummyGenerator.generateMatchingRound(MockTime.VALID_RECEPTION_TIME_ON_TUESDAY);
Expand All @@ -83,6 +79,6 @@ void sendMatchedNotification() {
matchingRoundService.saveMatchRound();

// then
verify(fcmSender, times(1)).sentMatchingNotification(any());
verify(fcmSender, times(1)).sendMatchedNotification(any());
}
}

0 comments on commit 4486c8d

Please sign in to comment.