Skip to content

Commit

Permalink
test: 알림 기능 테스트 메서드 추가 (#487)
Browse files Browse the repository at this point in the history
* test: 알림 기능 테스트 메서드 추가

* test: 알림 기능 테스트 의존성 추가
  • Loading branch information
Kim0914 authored Jan 5, 2024
1 parent a904a66 commit fc240b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.official.pium.admin.ui;

import com.official.pium.admin.domain.Admin;
import com.official.pium.admin.domain.Registration;
import com.official.pium.admin.service.dto.AdminSendNotificationRequest;
import com.official.pium.admin.repository.RegistrationRepository;
import com.official.pium.admin.service.AdminService;
import com.official.pium.admin.domain.Admin;
import com.official.pium.admin.service.dto.AdminLoginRequest;
import com.official.pium.admin.service.dto.AdminSendNotificationRequest;
import com.official.pium.dictionaryPlant.domain.DictionaryPlant;
import com.official.pium.member.domain.Member;
import com.official.pium.notification.application.NotificationService;
import com.official.pium.dictionaryPlant.repository.DictionaryPlantRepository;
import com.official.pium.member.domain.Member;
import com.official.pium.member.repository.MemberRepository;
import com.official.pium.admin.service.dto.AdminLoginRequest;
import com.official.pium.notification.application.NotificationService;
import com.official.pium.petPlant.application.ReminderService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class AdminPageController {
private final MemberRepository memberRepository;
private final AdminService adminService;
private final NotificationService notificationService;
private final ReminderService reminderService;

@GetMapping("/**")
public String adminPage(@AdminAuth Admin admin, Model model) {
Expand Down Expand Up @@ -162,4 +164,10 @@ public ResponseEntity<Void> logout(HttpServletRequest request) {

return ResponseEntity.ok().build();
}

@GetMapping("/notifications")
public ResponseEntity<String> notificationTest() {
reminderService.sendWaterNotificationTest();
return ResponseEntity.ok("알림 기능 테스트 성공");
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.official.pium.petPlant.application;

import com.official.pium.common.dto.DataResponse;
import com.official.pium.history.domain.HistoryType;
import com.official.pium.member.domain.Member;
import com.official.pium.petPlant.application.dto.ReminderCreateRequest;
import com.official.pium.petPlant.application.dto.ReminderResponse;
import com.official.pium.petPlant.application.dto.ReminderUpdateRequest;
import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.petPlant.event.history.HistoryEvent;
import com.official.pium.petPlant.event.notification.NotificationEvent;
import com.official.pium.petPlant.repository.PetPlantRepository;
import com.official.pium.common.dto.DataResponse;
import com.official.pium.petPlant.application.dto.ReminderCreateRequest;
import com.official.pium.petPlant.application.dto.ReminderResponse;
import com.official.pium.petPlant.application.dto.ReminderUpdateRequest;
import java.time.LocalDate;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -90,4 +90,17 @@ public void sendWaterNotification() {

publisher.publishEvent(events);
}

public void sendWaterNotificationTest() {
List<PetPlant> petPlants = petPlantRepository.findAll();
List<NotificationEvent> events = petPlants.stream()
.map(plant -> NotificationEvent.builder()
.title(plant.getNickname())
.body("(테스트 중) 물을 줄 시간이에요!")
.deviceToken(plant.getMember().getDeviceToken())
.build()
).toList();

publisher.publishEvent(events);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.official.pium.fixture.MemberFixture;
import com.official.pium.fixture.NotificationFixture;
import com.official.pium.notification.application.NotificationService;
import com.official.pium.petPlant.application.ReminderService;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.DisplayNameGeneration;
Expand Down Expand Up @@ -64,6 +65,9 @@ class AdminPageControllerTest extends UITest {
@MockBean
private NotificationService notificationService;

@MockBean
private ReminderService reminderService;

@Nested
class 페이지_정상_호출_ {

Expand Down

0 comments on commit fc240b9

Please sign in to comment.