Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FcmSender) : sendMatchedNotification의 알림 전송 방식을 multi -> single 로 변경 #187

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading