From f4abaf10d0c21e22c15c178da0e31024c18d5e41 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 17 Aug 2024 23:12:39 +0900 Subject: [PATCH 01/55] =?UTF-8?q?chore:=20Admin=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EC=97=90=20Getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/JGS/CasperEvent/domain/event/entity/admin/Admin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/admin/Admin.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/admin/Admin.java index bea80329..4e4d1c12 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/admin/Admin.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/admin/Admin.java @@ -4,8 +4,10 @@ import JGS.CasperEvent.global.entity.BaseUser; import JGS.CasperEvent.global.enums.Role; import jakarta.persistence.Entity; +import lombok.Getter; @Entity +@Getter public class Admin extends BaseUser { private String password; From 976115027a0185263e95d0ad893184fbddc43e07 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 17 Aug 2024 23:12:55 +0900 Subject: [PATCH 02/55] =?UTF-8?q?test:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 47800f8f..59199ac3 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -62,6 +62,7 @@ public class AdminService { private final LotteryWinnerRepository lotteryWinnerRepository; private final RedisTemplate casperBotRedisTemplate; + // 어드민 인증 public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findByIdAndPassword(adminRequestDto.getAdminId(), adminRequestDto.getPassword()).orElseThrow(NoSuchElementException::new); } diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java new file mode 100644 index 00000000..4f28db15 --- /dev/null +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -0,0 +1,82 @@ +package JGS.CasperEvent.domain.event.service.adminService; + +import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.entity.admin.Admin; +import JGS.CasperEvent.domain.event.repository.AdminRepository; +import JGS.CasperEvent.domain.event.repository.CasperBotRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushOptionRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryWinnerRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; +import JGS.CasperEvent.global.enums.Role; +import JGS.CasperEvent.global.service.S3Service; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.Optional; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; + +@ExtendWith(MockitoExtension.class) +class AdminServiceTest { + + @Mock + private AdminRepository adminRepository; + @Mock + private LotteryEventRepository lotteryEventRepository; + @Mock + private RushEventRepository rushEventRepository; + @Mock + private LotteryParticipantsRepository lotteryParticipantsRepository; + @Mock + private RushParticipantsRepository rushParticipantsRepository; + @Mock + private RushOptionRepository rushOptionRepository; + @Mock + private S3Service s3Service; + @Mock + private CasperBotRepository casperBotRepository; + @Mock + private LotteryWinnerRepository lotteryWinnerRepository; + + @InjectMocks + AdminService adminService; + + private Admin admin; + + @BeforeEach + void setUp() { + // 어드민 객체 + admin = new Admin("adminId", "password", Role.ADMIN); + + // 어드민 인증 + given(adminRepository.findByIdAndPassword("adminId", "password")).willReturn(Optional.ofNullable(admin)); + } + + @Test + @DisplayName("어드민 인증 테스트 - 성공") + void verifyAdminTest_Success() { + //given + AdminRequestDto adminRequestDto = AdminRequestDto.builder() + .adminId("adminId") + .password("password") + .build(); + + //when + Admin admin = adminService.verifyAdmin(adminRequestDto); + + //then + assertThat(admin.getRole()).isEqualTo(Role.ADMIN); + assertThat(admin.getId()).isEqualTo("adminId"); + assertThat(admin.getPassword()).isEqualTo("password"); + } +} \ No newline at end of file From c9047bf0a0b836991d6422c0edd37fed28ac38df Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 17 Aug 2024 23:15:08 +0900 Subject: [PATCH 03/55] =?UTF-8?q?test:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 59199ac3..c081882a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -67,6 +67,7 @@ public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findByIdAndPassword(adminRequestDto.getAdminId(), adminRequestDto.getPassword()).orElseThrow(NoSuchElementException::new); } + // 어드민 생성 public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { String adminId = adminRequestDto.getAdminId(); //Todo: 비밀번호 암호화 필요 diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 4f28db15..b8c46e65 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -11,6 +11,7 @@ import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryWinnerRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; import JGS.CasperEvent.global.enums.Role; +import JGS.CasperEvent.global.response.ResponseDto; import JGS.CasperEvent.global.service.S3Service; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -23,7 +24,6 @@ import java.util.Optional; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @ExtendWith(MockitoExtension.class) @@ -57,9 +57,6 @@ class AdminServiceTest { void setUp() { // 어드민 객체 admin = new Admin("adminId", "password", Role.ADMIN); - - // 어드민 인증 - given(adminRepository.findByIdAndPassword("adminId", "password")).willReturn(Optional.ofNullable(admin)); } @Test @@ -71,6 +68,8 @@ void verifyAdminTest_Success() { .password("password") .build(); + given(adminRepository.findByIdAndPassword("adminId", "password")).willReturn(Optional.ofNullable(admin)); + //when Admin admin = adminService.verifyAdmin(adminRequestDto); @@ -79,4 +78,20 @@ void verifyAdminTest_Success() { assertThat(admin.getId()).isEqualTo("adminId"); assertThat(admin.getPassword()).isEqualTo("password"); } + + @Test + @DisplayName("어드민 생성 테스트 - 성공") + void testName() { + //given + AdminRequestDto adminRequestDto = AdminRequestDto.builder() + .adminId("adminId") + .password("password") + .build(); + + //when + ResponseDto responseDto = adminService.postAdmin(adminRequestDto); + + //then + assertThat(responseDto.message()).isEqualTo("관리자 생성 성공"); + } } \ No newline at end of file From 421ad316232ea5d50e9eafb867df305c4af3a023 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 17 Aug 2024 23:18:20 +0900 Subject: [PATCH 04/55] =?UTF-8?q?test:=20=EC=96=B4=EB=93=9C=EB=AF=BC=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index b8c46e65..4a24f421 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -10,7 +10,9 @@ import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryWinnerRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; +import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; +import JGS.CasperEvent.global.error.exception.CustomException; import JGS.CasperEvent.global.response.ResponseDto; import JGS.CasperEvent.global.service.S3Service; import org.junit.jupiter.api.BeforeEach; @@ -24,6 +26,8 @@ import java.util.Optional; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.BDDMockito.given; @ExtendWith(MockitoExtension.class) @@ -94,4 +98,26 @@ void testName() { //then assertThat(responseDto.message()).isEqualTo("관리자 생성 성공"); } + + @Test + @DisplayName("어드민 생성 테스트 - 실패 (중복 아이디 존재)") + void postAdminTest_Failure_DuplicatedId() { + //given + AdminRequestDto adminRequestDto = AdminRequestDto.builder() + .adminId("adminId") + .password("password") + .build(); + + given(adminRepository.findById("adminId")).willReturn(Optional.ofNullable(admin)); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.postAdmin(adminRequestDto) + ); + + //then + assertEquals(CustomErrorCode.CONFLICT, customException.getErrorCode()); + assertEquals("이미 등록된 ID입니다.", customException.getMessage()); + + } } \ No newline at end of file From ebdd4e7bf857e5596473b813df98430f58c23c0d Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sat, 17 Aug 2024 23:21:32 +0900 Subject: [PATCH 05/55] =?UTF-8?q?test:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminServiceTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 4a24f421..8b4d8e2e 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1,6 +1,7 @@ package JGS.CasperEvent.domain.event.service.adminService; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; @@ -22,6 +23,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.mock.web.MockMultipartFile; import java.util.Optional; @@ -118,6 +120,19 @@ void postAdminTest_Failure_DuplicatedId() { //then assertEquals(CustomErrorCode.CONFLICT, customException.getErrorCode()); assertEquals("이미 등록된 ID입니다.", customException.getMessage()); + } + + @Test + @DisplayName("이미지 업로드 성공 테스트") + void postImageTest_Success() { + //given + MockMultipartFile image = new MockMultipartFile("image", "image.png", "png", "<>".getBytes()); + given(s3Service.upload(image)).willReturn("www.image.com"); + //when + ImageUrlResponseDto imageUrlResponseDto = adminService.postImage(image); + + //then + assertThat(imageUrlResponseDto.imageUrl()).isEqualTo("www.image.com"); } } \ No newline at end of file From f3bdc0b0592462f24d9f8e6acda6fea7e7ac9778 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 13:37:41 +0900 Subject: [PATCH 06/55] =?UTF-8?q?chore:=20LotteryEvent=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20EqualsAndHashCode=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java index cf4825c1..4eac2dc0 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java @@ -1,12 +1,14 @@ package JGS.CasperEvent.domain.event.entity.event; import jakarta.persistence.*; +import lombok.EqualsAndHashCode; import lombok.Getter; import java.time.LocalDateTime; @Entity @Getter +@EqualsAndHashCode public class LotteryEvent extends BaseEvent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From 4381ebb93c4adb2425829becffbb7592fab7c444 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 13:37:58 +0900 Subject: [PATCH 07/55] =?UTF-8?q?test:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 2 + .../adminService/AdminServiceTest.java | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index c081882a..c2e13329 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -81,10 +81,12 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { return ResponseDto.of("관리자 생성 성공"); } + // 이미지 업로드 public ImageUrlResponseDto postImage(MultipartFile image) { return new ImageUrlResponseDto(s3Service.upload(image)); } + // 추첨 이벤트 생성 public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { if (lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 8b4d8e2e..0eae698f 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1,8 +1,11 @@ package JGS.CasperEvent.domain.event.service.adminService; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; @@ -25,6 +28,9 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.mock.web.MockMultipartFile; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.Optional; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -58,11 +64,29 @@ class AdminServiceTest { AdminService adminService; private Admin admin; + private LotteryEvent lotteryEvent; + private LotteryEventRequestDto lotteryEventRequestDto; @BeforeEach void setUp() { // 어드민 객체 admin = new Admin("adminId", "password", Role.ADMIN); + + // 추첨 이벤트 생성 요청 DTO + lotteryEventRequestDto = LotteryEventRequestDto.builder() + .startDate(LocalDate.of(2000, 9, 27)) + .startTime(LocalTime.of(0, 0)) + .endDate(LocalDate.of(2100, 9, 27)) + .endTime(LocalTime.of(0, 0)) + .winnerCount(315) + .build(); + + // 추첨 이벤트 엔티티 + lotteryEvent = new LotteryEvent( + LocalDateTime.of(lotteryEventRequestDto.getStartDate(), lotteryEventRequestDto.getStartTime()), + LocalDateTime.of(lotteryEventRequestDto.getEndDate(), lotteryEventRequestDto.getEndTime()), + lotteryEventRequestDto.getWinnerCount() + ); } @Test @@ -135,4 +159,21 @@ void postImageTest_Success() { //then assertThat(imageUrlResponseDto.imageUrl()).isEqualTo("www.image.com"); } + + @Test + @DisplayName("추첨 이벤트 생성 테스트 - 성공") + void createLotteryEventTest_Success() { + //given + given(lotteryEventRepository.count()).willReturn(0L); + given(lotteryEventRepository.save(lotteryEvent)).willReturn(lotteryEvent); + + //when + LotteryEventResponseDto lotteryEventResponseDto = adminService.createLotteryEvent(lotteryEventRequestDto); + + //then + assertThat(lotteryEventResponseDto.serverDateTime()).isEqualTo("2024-08-18T13:36:18.155541"); + assertThat(lotteryEventResponseDto.eventStartDate()).isEqualTo("2000-09-27T00:00"); + assertThat(lotteryEventResponseDto.eventEndDate()).isEqualTo("2100-09-27T00:00"); + assertThat(lotteryEventResponseDto.activePeriod()).isEqualTo(36524); + } } \ No newline at end of file From dfb86962b3fbca046417ed5334f972ebe476de87 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 13:40:48 +0900 Subject: [PATCH 08/55] =?UTF-8?q?test:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=EA=B0=80=20=EC=9D=B4=EB=AF=B8=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=ED=95=A0=20=EB=95=8C=20=EC=B6=94=EC=B2=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 2 +- .../service/adminService/AdminServiceTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index c2e13329..68955202 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -88,7 +88,7 @@ public ImageUrlResponseDto postImage(MultipartFile image) { // 추첨 이벤트 생성 public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { - if (lotteryEventRepository.count() >= 1) throw new TooManyLotteryEventException(); + if (lotteryEventRepository.count() >= 1) throw new CustomException(CustomErrorCode.TOO_MANY_LOTTERY_EVENT); LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( LocalDateTime.of(lotteryEventRequestDto.getStartDate(), lotteryEventRequestDto.getStartTime()), diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 0eae698f..96647f73 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -176,4 +176,20 @@ void createLotteryEventTest_Success() { assertThat(lotteryEventResponseDto.eventEndDate()).isEqualTo("2100-09-27T00:00"); assertThat(lotteryEventResponseDto.activePeriod()).isEqualTo(36524); } + + @Test + @DisplayName("추첨 이벤트 생성 테스트 - 실패 (데이터베이스에 추첨 이벤트가 존재할 때)") + void createLotteryEventTest_Failure_TooManyLotteryEvent() { + //given + given(lotteryEventRepository.count()).willReturn(1L); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.createLotteryEvent(lotteryEventRequestDto) + ); + + //then + assertEquals(CustomErrorCode.TOO_MANY_LOTTERY_EVENT, customException.getErrorCode()); + assertEquals("현재 진행중인 추첨 이벤트가 2개 이상입니다.", customException.getMessage()); + } } \ No newline at end of file From a8cfcd4d695137bc393d21b74119d03cd3c59648 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 13:43:59 +0900 Subject: [PATCH 09/55] =?UTF-8?q?test:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 68955202..8adf117c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -99,6 +99,7 @@ public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lottery return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); } + // 추첨 이벤트 조회 public LotteryEventDetailResponseDto getLotteryEvent() { return LotteryEventDetailResponseDto.of( getCurrentLotteryEvent() diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 96647f73..5036d607 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -3,6 +3,7 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; @@ -15,6 +16,7 @@ import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryWinnerRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; +import JGS.CasperEvent.global.enums.EventStatus; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; import JGS.CasperEvent.global.response.ResponseDto; @@ -31,6 +33,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -192,4 +196,25 @@ void createLotteryEventTest_Failure_TooManyLotteryEvent() { assertEquals(CustomErrorCode.TOO_MANY_LOTTERY_EVENT, customException.getErrorCode()); assertEquals("현재 진행중인 추첨 이벤트가 2개 이상입니다.", customException.getMessage()); } + + @Test + @DisplayName("추첨 이벤트 조회 성공 테스트") + void getLotteryEventTest_Success() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + + //when + LotteryEventDetailResponseDto lotteryEventDetailResponseDto = adminService.getLotteryEvent(); + + //then + assertThat(lotteryEventDetailResponseDto.startDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(lotteryEventDetailResponseDto.startTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(lotteryEventDetailResponseDto.endDate()).isEqualTo(LocalDate.of(2100, 9, 27)); + assertThat(lotteryEventDetailResponseDto.endTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(lotteryEventDetailResponseDto.appliedCount()).isEqualTo(0); + assertThat(lotteryEventDetailResponseDto.winnerCount()).isEqualTo(315); + assertThat(lotteryEventDetailResponseDto.status()).isEqualTo(EventStatus.DURING); + } } \ No newline at end of file From de2dd1b73f0788d4cc62302705698f4f4859199d Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 14:16:56 +0900 Subject: [PATCH 10/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=88=20=EB=95=8C=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 5036d607..911e7f90 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -4,9 +4,12 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; @@ -15,6 +18,7 @@ import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryWinnerRepository; import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository; +import JGS.CasperEvent.global.entity.BaseUser; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.EventStatus; import JGS.CasperEvent.global.enums.Role; @@ -28,6 +32,10 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.mock.web.MockMultipartFile; import java.time.LocalDate; @@ -40,7 +48,9 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class AdminServiceTest { @@ -68,14 +78,21 @@ class AdminServiceTest { AdminService adminService; private Admin admin; + + private BaseUser user; private LotteryEvent lotteryEvent; private LotteryEventRequestDto lotteryEventRequestDto; + private LotteryParticipants lotteryParticipants; @BeforeEach void setUp() { // 어드민 객체 admin = new Admin("adminId", "password", Role.ADMIN); + // 유저 객체 + user = new BaseUser("010-0000-0000", Role.USER); + user.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + user.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); // 추첨 이벤트 생성 요청 DTO lotteryEventRequestDto = LotteryEventRequestDto.builder() .startDate(LocalDate.of(2000, 9, 27)) @@ -91,6 +108,9 @@ void setUp() { LocalDateTime.of(lotteryEventRequestDto.getEndDate(), lotteryEventRequestDto.getEndTime()), lotteryEventRequestDto.getWinnerCount() ); + + // 추첨 이벤트 참여자 엔티티 + lotteryParticipants = new LotteryParticipants(user); } @Test @@ -175,7 +195,7 @@ void createLotteryEventTest_Success() { LotteryEventResponseDto lotteryEventResponseDto = adminService.createLotteryEvent(lotteryEventRequestDto); //then - assertThat(lotteryEventResponseDto.serverDateTime()).isEqualTo("2024-08-18T13:36:18.155541"); + assertThat(lotteryEventResponseDto.serverDateTime()).isNotNull(); assertThat(lotteryEventResponseDto.eventStartDate()).isEqualTo("2000-09-27T00:00"); assertThat(lotteryEventResponseDto.eventEndDate()).isEqualTo("2100-09-27T00:00"); assertThat(lotteryEventResponseDto.activePeriod()).isEqualTo(36524); @@ -217,4 +237,32 @@ void getLotteryEventTest_Success() { assertThat(lotteryEventDetailResponseDto.winnerCount()).isEqualTo(315); assertThat(lotteryEventDetailResponseDto.status()).isEqualTo(EventStatus.DURING); } -} \ No newline at end of file + + @Test + @DisplayName("추첨 이벤트 참여자 조회 성공 테스트 (전화번호가 없을 때)") + void getLotteryEventParticipantsTest_Success_withoutPhoneNumber() { + //given + List lotteryParticipantsList = new ArrayList<>(); + lotteryParticipantsList.add(lotteryParticipants); + Page lotteryParticipantsPage = new PageImpl<>(lotteryParticipantsList); + + + given(lotteryParticipantsRepository.findAll(any(Pageable.class))).willReturn(lotteryParticipantsPage); + given(lotteryParticipantsRepository.count()).willReturn(1L); + + //when + LotteryEventParticipantsListResponseDto lotteryEventParticipantsListResponseDto = adminService.getLotteryEventParticipants(10, 0, ""); + LotteryEventParticipantsResponseDto retrievedParticipant = lotteryEventParticipantsListResponseDto.participantsList().get(0); + + //then + assertThat(lotteryEventParticipantsListResponseDto.isLastPage()).isTrue(); + assertThat(lotteryEventParticipantsListResponseDto.totalParticipants()).isEqualTo(1); + + assertThat(retrievedParticipant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(retrievedParticipant.linkClickedCounts()).isEqualTo(0); + assertThat(retrievedParticipant.expectation()).isEqualTo(0); + assertThat(retrievedParticipant.appliedCount()).isEqualTo(1); + assertThat(retrievedParticipant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(retrievedParticipant.createdTime()).isEqualTo(LocalTime.of(0, 0, 0)); + } +} From 35f5a26248c5b2ae81a5df3d67dfb3f323d4e909 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 14:18:43 +0900 Subject: [PATCH 11/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=9D=84=20=EB=95=8C=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 911e7f90..7eef376d 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -34,7 +34,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.mock.web.MockMultipartFile; @@ -49,8 +48,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class AdminServiceTest { @@ -265,4 +264,32 @@ void getLotteryEventParticipantsTest_Success_withoutPhoneNumber() { assertThat(retrievedParticipant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); assertThat(retrievedParticipant.createdTime()).isEqualTo(LocalTime.of(0, 0, 0)); } + + @Test + @DisplayName("추첨 이벤트 참여자 조회 성공 테스트 (전화번호가 있을 때)") + void getLotteryEventParticipantsTest_Success_withPhoneNumber() { + //given + List lotteryParticipantsList = new ArrayList<>(); + lotteryParticipantsList.add(lotteryParticipants); + Page lotteryParticipantsPage = new PageImpl<>(lotteryParticipantsList); + + + given(lotteryParticipantsRepository.findByBaseUser_Id(eq("010-0000-0000"), any(Pageable.class))).willReturn(lotteryParticipantsPage); + given(lotteryParticipantsRepository.countByBaseUser_Id("010-0000-0000")).willReturn(1L); + + //when + LotteryEventParticipantsListResponseDto lotteryEventParticipantsListResponseDto = adminService.getLotteryEventParticipants(10, 0, "010-0000-0000"); + LotteryEventParticipantsResponseDto retrievedParticipant = lotteryEventParticipantsListResponseDto.participantsList().get(0); + + //then + assertThat(lotteryEventParticipantsListResponseDto.isLastPage()).isTrue(); + assertThat(lotteryEventParticipantsListResponseDto.totalParticipants()).isEqualTo(1); + + assertThat(retrievedParticipant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(retrievedParticipant.linkClickedCounts()).isEqualTo(0); + assertThat(retrievedParticipant.expectation()).isEqualTo(0); + assertThat(retrievedParticipant.appliedCount()).isEqualTo(1); + assertThat(retrievedParticipant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(retrievedParticipant.createdTime()).isEqualTo(LocalTime.of(0, 0, 0)); + } } From fa49ee04b7ed66de31191a8435447769bfc78216 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 20:21:37 +0900 Subject: [PATCH 12/55] =?UTF-8?q?test:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RushEventOptionResponseDto.java | 2 +- .../domain/event/entity/event/RushEvent.java | 2 + .../domain/event/entity/event/RushOption.java | 7 +- .../service/adminService/AdminService.java | 7 +- .../adminService/AdminServiceTest.java | 150 +++++++++++++++++- 5 files changed, 152 insertions(+), 16 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java index 5d09bf73..5ca72249 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/rushEventResponseDto/RushEventOptionResponseDto.java @@ -9,7 +9,7 @@ import java.time.LocalDateTime; -public record RushEventOptionResponseDto(long optionId, String mainText, +public record RushEventOptionResponseDto(Long optionId, String mainText, String subText, String resultMainText, String resultSubText, String imageUrl, Position position, diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index 0da7678c..30720d35 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -7,6 +7,7 @@ import JGS.CasperEvent.global.error.exception.CustomException; import com.fasterxml.jackson.annotation.JsonManagedReference; import jakarta.persistence.*; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -17,6 +18,7 @@ @Entity @Getter @ToString +@EqualsAndHashCode public class RushEvent extends BaseEvent { private String prizeImageUrl; private String prizeDescription; diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java index b47c79cb..a90b5d4a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushOption.java @@ -5,16 +5,15 @@ import JGS.CasperEvent.global.enums.Position; import com.fasterxml.jackson.annotation.JsonBackReference; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Entity @Getter @NoArgsConstructor @AllArgsConstructor @Builder +@EqualsAndHashCode(exclude = {"rushEvent"}) +@ToString(exclude = {"rushEvent"}) public class RushOption extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 8adf117c..ef8127bc 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -132,12 +132,10 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s public AdminRushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequestDto, MultipartFile prizeImg, MultipartFile leftOptionImg, MultipartFile rightOptionImg) { if (rushEventRepository.count() >= 6) throw new TooManyRushEventException(); - String prizeImgSrc = s3Service.upload(prizeImg); String leftOptionImgSrc = s3Service.upload(leftOptionImg); String rightOptionImgSrc = s3Service.upload(rightOptionImg); - // Img s3 저장 RushEvent rushEvent = rushEventRepository.save( new RushEvent( LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getStartTime()), @@ -171,7 +169,6 @@ public AdminRushEventResponseDto createRushEvent(RushEventRequestDto rushEventRe )); rushEvent.addOption(leftRushOption, rightRushOption); - return AdminRushEventResponseDto.of(rushEvent); } @@ -352,7 +349,7 @@ public ResponseDto pickLotteryEventWinners() { int cumulativeSum = 0; for (LotteryParticipants lotteryParticipant : lotteryParticipants) { cumulativeSum += lotteryParticipant.getAppliedCount(); - if(randomValue <= cumulativeSum){ + if (randomValue <= cumulativeSum) { lotteryEventWinners.add(lotteryParticipant); lotteryParticipants.remove(lotteryParticipant); break; @@ -367,7 +364,7 @@ public ResponseDto pickLotteryEventWinners() { return new ResponseDto("추첨이 완료되었습니다."); } - public ResponseDto deleteLotteryEventWinners(){ + public ResponseDto deleteLotteryEventWinners() { lotteryWinnerRepository.deleteAll(); return new ResponseDto("당첨자 명단을 삭제했습니다."); } diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 7eef376d..cfb90bb1 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -2,13 +2,19 @@ import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventOptionResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +import JGS.CasperEvent.domain.event.entity.event.RushEvent; +import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; @@ -21,6 +27,7 @@ import JGS.CasperEvent.global.entity.BaseUser; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.EventStatus; +import JGS.CasperEvent.global.enums.Position; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; import JGS.CasperEvent.global.response.ResponseDto; @@ -40,9 +47,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -50,6 +55,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class AdminServiceTest { @@ -73,16 +80,24 @@ class AdminServiceTest { @Mock private LotteryWinnerRepository lotteryWinnerRepository; - @InjectMocks - AdminService adminService; + private RushEvent rushEvent; + private RushOption leftOption; + @Mock + private RushOption rightOption; private Admin admin; - private BaseUser user; private LotteryEvent lotteryEvent; private LotteryEventRequestDto lotteryEventRequestDto; private LotteryParticipants lotteryParticipants; + private RushEventRequestDto rushEventRequestDto; + private RushEventOptionRequestDto leftOptionRequestDto; + private RushEventOptionRequestDto rightOptionRequestDto; + + @InjectMocks + AdminService adminService; + @BeforeEach void setUp() { // 어드민 객체 @@ -110,6 +125,72 @@ void setUp() { // 추첨 이벤트 참여자 엔티티 lotteryParticipants = new LotteryParticipants(user); + + + // 선착순 이벤트 옵션 요청 DTO + leftOptionRequestDto = RushEventOptionRequestDto.builder() + .rushOptionId(1L) + .position(Position.LEFT) + .mainText("Main Text 1") + .subText("Sub Text 1") + .resultMainText("Result Main Text 1") + .resultSubText("Result Sub Text 1") + .imageUrl("http://example.com/leftImage.jpg").build(); + + rightOptionRequestDto = RushEventOptionRequestDto.builder() + .rushOptionId(1L) + .position(Position.RIGHT) + .mainText("Main Text 2") + .subText("Sub Text 2") + .resultMainText("Result Main Text 2") + .resultSubText("Result Sub Text 2") + .imageUrl("http://example.com/rightImage.jpg").build(); + + Set options = new HashSet<>(); + options.add(leftOptionRequestDto); + options.add(rightOptionRequestDto); + + // 선착순 이벤트 요청 DTO + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.of(2024, 8, 15)) + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.of(23, 59)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + // 선착순 이벤트 객체 + rushEvent = new RushEvent( + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getStartTime()), + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getEndTime()), + rushEventRequestDto.getWinnerCount(), + "http://example.com/image.jpg", + rushEventRequestDto.getPrizeDescription() + ); + + // 선착순 이벤트 선택지 객체 + leftOption = new RushOption( + rushEvent, + leftOptionRequestDto.getMainText(), + leftOptionRequestDto.getSubText(), + leftOptionRequestDto.getResultMainText(), + leftOptionRequestDto.getResultSubText(), + "http://example.com/image.jpg", + Position.LEFT + ); + + rightOption = new RushOption( + rushEvent, + rightOptionRequestDto.getMainText(), + rightOptionRequestDto.getSubText(), + rightOptionRequestDto.getResultMainText(), + rightOptionRequestDto.getResultSubText(), + "http://example.com/image.jpg", + Position.RIGHT + ); } @Test @@ -292,4 +373,61 @@ void getLotteryEventParticipantsTest_Success_withPhoneNumber() { assertThat(retrievedParticipant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); assertThat(retrievedParticipant.createdTime()).isEqualTo(LocalTime.of(0, 0, 0)); } + + @Test + @DisplayName("선착순 이벤트 생성 테스트 - 성공") + void createRushEventTest_Success() { + //given + MockMultipartFile prizeImg = new MockMultipartFile("prizeImg", "prizeImage.png", "png", "<>".getBytes()); + MockMultipartFile leftOptionImg = new MockMultipartFile("leftOptionImg", "leftOptionImage.png", "png", "<>".getBytes()); + MockMultipartFile rightOptionImg = new MockMultipartFile("rightOptionImg", "rightOptionImage.png", "png", "<>".getBytes()); + + + given(rushEventRepository.count()).willReturn(1L); + given(rushEventRepository.save(rushEvent)).willReturn(rushEvent); + given(rushOptionRepository.save(leftOption)).willReturn(leftOption); + given(rushOptionRepository.save(rightOption)).willReturn(rightOption); + + given(s3Service.upload(any())).willReturn("http://example.com/image.jpg"); + + + //when + AdminRushEventResponseDto adminRushEventResponseDto = adminService.createRushEvent(rushEventRequestDto, prizeImg, leftOptionImg, rightOptionImg); + + //then + assertThat(adminRushEventResponseDto.eventDate()).isEqualTo(LocalDate.of(2024, 8, 15)); + assertThat(adminRushEventResponseDto.startTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(adminRushEventResponseDto.endTime()).isEqualTo(LocalTime.of(23, 59)); + assertThat(adminRushEventResponseDto.winnerCount()).isEqualTo(100); + assertThat(adminRushEventResponseDto.prizeImageUrl()).isEqualTo("http://example.com/image.jpg"); + assertThat(adminRushEventResponseDto.prizeDescription()).isEqualTo("This is a detailed description of the prize."); + assertThat(adminRushEventResponseDto.status()).isEqualTo(EventStatus.AFTER); + + Set options = adminRushEventResponseDto.options(); + + boolean firstOptionFound = false; + boolean secondOptionFound = false; + + for (RushEventOptionResponseDto option : options) { + if (option.mainText().equals("Main Text 2") && + option.subText().equals("Sub Text 2") && + option.resultMainText().equals("Result Main Text 2") && + option.resultSubText().equals("Result Sub Text 2") && + option.imageUrl().equals("http://example.com/image.jpg") && + option.position().equals(Position.RIGHT)) { + firstOptionFound = true; + } else if (option.mainText().equals("Main Text 1") && + option.subText().equals("Sub Text 1") && + option.resultMainText().equals("Result Main Text 1") && + option.resultSubText().equals("Result Sub Text 1") && + option.imageUrl().equals("http://example.com/image.jpg") && + option.position().equals(Position.LEFT)) { + secondOptionFound = true; + } + } + + assertThat(firstOptionFound).isTrue(); + assertThat(secondOptionFound).isTrue(); + } + } From 038494162954a9f1301e921247082f69b131927c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 20:28:25 +0900 Subject: [PATCH 13/55] =?UTF-8?q?test:=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=20=EC=84=A0=EC=B0=A9?= =?UTF-8?q?=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EA=B0=80=206=EA=B0=9C?= =?UTF-8?q?=20=EC=9D=B4=EC=83=81=20=EC=A1=B4=EC=9E=AC=ED=95=A0=20=EB=95=8C?= =?UTF-8?q?=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 2 +- .../global/enums/CustomErrorCode.java | 1 + .../adminService/AdminServiceTest.java | 21 ++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index ef8127bc..2d1958ef 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -131,7 +131,7 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s } public AdminRushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequestDto, MultipartFile prizeImg, MultipartFile leftOptionImg, MultipartFile rightOptionImg) { - if (rushEventRepository.count() >= 6) throw new TooManyRushEventException(); + if (rushEventRepository.count() >= 6) throw new CustomException(CustomErrorCode.TOO_MANY_RUSH_EVENT); String prizeImgSrc = s3Service.upload(prizeImg); String leftOptionImgSrc = s3Service.upload(leftOptionImg); String rightOptionImgSrc = s3Service.upload(rightOptionImg); diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 7ca81da5..8f49dcd3 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -24,6 +24,7 @@ public enum CustomErrorCode { INVALID_RUSH_EVENT_OPTION_ID("옵션 ID는 1 또는 2여야 합니다.", 400), EMPTY_FILE("유효하지 않은 파일입니다.", 422), TOO_MANY_LOTTERY_EVENT("현재 진행중인 추첨 이벤트가 2개 이상입니다.", 409), + TOO_MANY_RUSH_EVENT("현재 진행중인 선착순 이벤트가 6개 이상입니다.", 409), EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME("현재 진행 중인 이벤트의 시작 시간을 변경할 수 없습니다.", 400), EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW("현재 진행 중인 이벤트의 종료 시간을 현재 시간보다 이전으로 설정할 수 없습니다.", 400), EVENT_BEFORE_START_TIME("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", 400), diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index cfb90bb1..0afd2e25 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -215,7 +215,7 @@ void verifyAdminTest_Success() { @Test @DisplayName("어드민 생성 테스트 - 성공") - void testName() { + void postAdminTest_Success() { //given AdminRequestDto adminRequestDto = AdminRequestDto.builder() .adminId("adminId") @@ -430,4 +430,23 @@ void createRushEventTest_Success() { assertThat(secondOptionFound).isTrue(); } + @Test + @DisplayName("선착순 이벤트 생성 테스트 - 실패 (데이터베이스에 이미 6개의 선착순 이벤트가 존재할 때)") + void createRushEventTest_Failure_TooManyRushEvent() { + //given + given(rushEventRepository.count()).willReturn(6L); + MockMultipartFile prizeImg = new MockMultipartFile("prizeImg", "prizeImage.png", "png", "<>".getBytes()); + MockMultipartFile leftOptionImg = new MockMultipartFile("leftOptionImg", "leftOptionImage.png", "png", "<>".getBytes()); + MockMultipartFile rightOptionImg = new MockMultipartFile("rightOptionImg", "rightOptionImage.png", "png", "<>".getBytes()); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.createRushEvent(rushEventRequestDto, prizeImg, leftOptionImg, rightOptionImg) + ); + + //then + assertEquals(CustomErrorCode.TOO_MANY_RUSH_EVENT, customException.getErrorCode()); + assertEquals("현재 진행중인 선착순 이벤트가 6개 이상입니다.", customException.getMessage()); + } + } From cf07fc2f8219237bc426db3cbb62c5699ffe08ed Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 20:37:07 +0900 Subject: [PATCH 14/55] =?UTF-8?q?test:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 3 ++ .../adminService/AdminServiceTest.java | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 2d1958ef..e5fbef0b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -106,6 +106,7 @@ public LotteryEventDetailResponseDto getLotteryEvent() { ); } + // 추첨 이벤트 참여자 조회 public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int size, int page, String phoneNumber) { Pageable pageable = PageRequest.of(page, size); @@ -130,6 +131,7 @@ public LotteryEventParticipantsListResponseDto getLotteryEventParticipants(int s return new LotteryEventParticipantsListResponseDto(lotteryEventParticipantsResponseDtoList, isLastPage, count); } + // 선착순 이벤트 생성 public AdminRushEventResponseDto createRushEvent(RushEventRequestDto rushEventRequestDto, MultipartFile prizeImg, MultipartFile leftOptionImg, MultipartFile rightOptionImg) { if (rushEventRepository.count() >= 6) throw new CustomException(CustomErrorCode.TOO_MANY_RUSH_EVENT); String prizeImgSrc = s3Service.upload(prizeImg); @@ -172,6 +174,7 @@ public AdminRushEventResponseDto createRushEvent(RushEventRequestDto rushEventRe return AdminRushEventResponseDto.of(rushEvent); } + // 선착순 이벤트 조회 public List getRushEvents() { List rushEvents = rushEventRepository.findAll(); List rushEventResponseDtoList = new ArrayList<>(); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 0afd2e25..b703bb93 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -191,6 +191,8 @@ void setUp() { "http://example.com/image.jpg", Position.RIGHT ); + + rushEvent.addOption(leftOption, rightOption); } @Test @@ -449,4 +451,51 @@ void createRushEventTest_Failure_TooManyRushEvent() { assertEquals("현재 진행중인 선착순 이벤트가 6개 이상입니다.", customException.getMessage()); } + @Test + @DisplayName("선착순 이벤트 조회 테스트 - 성공") + void getRushEventsTest_Success() { + //given + List rushEventList = new ArrayList<>(); + rushEventList.add(rushEvent); + given(rushEventRepository.findAll()).willReturn(rushEventList); + + //when + List rushEvents = adminService.getRushEvents(); + + //then + AdminRushEventResponseDto firstEvent = rushEvents.get(0); + assertThat(firstEvent.eventDate()).isEqualTo(LocalDate.of(2024, 8, 15)); + assertThat(firstEvent.startTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(firstEvent.endTime()).isEqualTo(LocalTime.of(23, 59)); + assertThat(firstEvent.winnerCount()).isEqualTo(100); + assertThat(firstEvent.prizeImageUrl()).isEqualTo("http://example.com/image.jpg"); + assertThat(firstEvent.prizeDescription()).isEqualTo("This is a detailed description of the prize."); + assertThat(firstEvent.status()).isEqualTo(EventStatus.AFTER); + + Set options = firstEvent.options(); + + boolean firstOptionFound = false; + boolean secondOptionFound = false; + for (RushEventOptionResponseDto option : options) { + if (option.mainText().equals("Main Text 1") && + option.subText().equals("Sub Text 1") && + option.resultMainText().equals("Result Main Text 1") && + option.resultSubText().equals("Result Sub Text 1") && + option.imageUrl().equals("http://example.com/image.jpg") && + option.position().equals(Position.LEFT)) { + firstOptionFound = true; + } else if (option.mainText().equals("Main Text 2") && + option.subText().equals("Sub Text 2") && + option.resultMainText().equals("Result Main Text 2") && + option.resultSubText().equals("Result Sub Text 2") && + option.imageUrl().equals("http://example.com/image.jpg") && + option.position().equals(Position.RIGHT)) { + secondOptionFound = true; + } + } + + assertThat(firstOptionFound).isTrue(); + assertThat(secondOptionFound).isTrue(); + } + } From 0bbbb5b172b920a7fe22dd618c5f73bb01856af0 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 20:49:12 +0900 Subject: [PATCH 15/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EA=B3=A0,=20?= =?UTF-8?q?=EB=8F=99=EC=A0=90=EC=9D=B4=20=EC=95=84=EB=8B=8C=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 63 ++++++++++++++++--- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index e5fbef0b..854b6186 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -184,6 +184,7 @@ public List getRushEvents() { return rushEventResponseDtoList; } + // 선착순 이벤트 참여자 조회 public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEventId, int size, int page, int optionId, String phoneNumber) { Pageable pageable = PageRequest.of(page, size); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index b703bb93..92ea3964 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -11,11 +11,14 @@ import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventOptionResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; @@ -55,8 +58,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class AdminServiceTest { @@ -86,7 +87,8 @@ class AdminServiceTest { private RushOption rightOption; private Admin admin; - private BaseUser user; + private BaseUser user1; + private BaseUser user2; private LotteryEvent lotteryEvent; private LotteryEventRequestDto lotteryEventRequestDto; private LotteryParticipants lotteryParticipants; @@ -94,6 +96,8 @@ class AdminServiceTest { private RushEventRequestDto rushEventRequestDto; private RushEventOptionRequestDto leftOptionRequestDto; private RushEventOptionRequestDto rightOptionRequestDto; + private RushParticipants rushParticipant1; + private RushParticipants rushParticipant2; @InjectMocks AdminService adminService; @@ -104,9 +108,14 @@ void setUp() { admin = new Admin("adminId", "password", Role.ADMIN); // 유저 객체 - user = new BaseUser("010-0000-0000", Role.USER); - user.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - user.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + user1 = new BaseUser("010-0000-0000", Role.USER); + user1.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + user1.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + + user2 = new BaseUser("010-9999-9999", Role.USER); + user2.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + user2.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + // 추첨 이벤트 생성 요청 DTO lotteryEventRequestDto = LotteryEventRequestDto.builder() .startDate(LocalDate.of(2000, 9, 27)) @@ -124,7 +133,7 @@ void setUp() { ); // 추첨 이벤트 참여자 엔티티 - lotteryParticipants = new LotteryParticipants(user); + lotteryParticipants = new LotteryParticipants(user1); // 선착순 이벤트 옵션 요청 DTO @@ -193,6 +202,15 @@ void setUp() { ); rushEvent.addOption(leftOption, rightOption); + + // 선착순 이벤트 참여자 + rushParticipant1 = new RushParticipants(user1, rushEvent, 1); + rushParticipant1.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + rushParticipant1.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + + rushParticipant2 = new RushParticipants(user1, rushEvent, 2); + rushParticipant2.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + rushParticipant2.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); } @Test @@ -498,4 +516,35 @@ void getRushEventsTest_Success() { assertThat(secondOptionFound).isTrue(); } + @Test + @DisplayName("선착순 이벤트 참여자 조회 테스트 - 성공 (전화번호가 존재하고 결과가 동점이 아닌 경우") + void testName() { + //given + List rushParticipantsList = new ArrayList<>(); + rushParticipantsList.add(rushParticipant1); + Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); + + given(rushParticipantsRepository.findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(eq(1L), eq(1), eq("010-0000-0000"), any(Pageable.class))) + .willReturn(rushParticipantsPage); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(1L, 1, "010-0000-0000")) + .willReturn(1L); + + //when + RushEventParticipantsListResponseDto rushEventParticipants = adminService.getRushEventParticipants(1, 1, 0, 1, "010-0000-0000"); + + //then + assertThat(rushEventParticipants.isLastPage()).isTrue(); + assertThat(rushEventParticipants.totalParticipants()).isEqualTo(1); + + List participantsList = rushEventParticipants.participantsList(); + + RushEventParticipantResponseDto participant = participantsList.get(0); + + assertThat(participant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(participant.balanceGameChoice()).isEqualTo(1); + assertThat(participant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(participant.rank()).isEqualTo(0); + + } } From 1d1ebfd1ebbbdd20f3546327b8ede7193c8fe609 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 20:52:52 +0900 Subject: [PATCH 16/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B3=A0,=20=EB=8F=99=EC=A0=90=EC=9D=B8=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 92ea3964..6ec52b62 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -518,7 +518,7 @@ void getRushEventsTest_Success() { @Test @DisplayName("선착순 이벤트 참여자 조회 테스트 - 성공 (전화번호가 존재하고 결과가 동점이 아닌 경우") - void testName() { + void getRushEventParticipantsTest_Success_withPhoneNumberAndOptionId() { //given List rushParticipantsList = new ArrayList<>(); rushParticipantsList.add(rushParticipant1); @@ -547,4 +547,35 @@ void testName() { assertThat(participant.rank()).isEqualTo(0); } + + @Test + @DisplayName("선착순 이벤트 참여자 조회 테스트 - 성공 (전화번호가 존재하지 않고 결과가 동점인 경우") + void getRushEventParticipantsTest_Success_withoutPhoneNumberAndOptionId() { + //given + List rushParticipantsList = new ArrayList<>(); + rushParticipantsList.add(rushParticipant1); + Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); + + given(rushParticipantsRepository.findByRushEvent_RushEventId(eq(1L), any(Pageable.class))) + .willReturn(rushParticipantsPage); + given(rushParticipantsRepository.countByRushEvent_RushEventId(1L)) + .willReturn(1L); + + //when + RushEventParticipantsListResponseDto rushEventParticipants = adminService.getRushEventParticipants(1, 1, 0, 0, ""); + + //then + assertThat(rushEventParticipants.isLastPage()).isTrue(); + assertThat(rushEventParticipants.totalParticipants()).isEqualTo(1); + + List participantsList = rushEventParticipants.participantsList(); + + RushEventParticipantResponseDto participant = participantsList.get(0); + + assertThat(participant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(participant.balanceGameChoice()).isEqualTo(1); + assertThat(participant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(participant.rank()).isEqualTo(0); + } } From 434405787d7d7728c3e75a92c926f8da33924ce3 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 20:55:51 +0900 Subject: [PATCH 17/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B3=A0,=20=EB=8F=99=EC=A0=90=EC=9D=B4=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20=EA=B2=BD=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 6ec52b62..a2b25139 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -578,4 +578,35 @@ void getRushEventParticipantsTest_Success_withoutPhoneNumberAndOptionId() { assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); assertThat(participant.rank()).isEqualTo(0); } + + @Test + @DisplayName("선착순 이벤트 참여자 조회 테스트 - 성공 (전화번호가 존재하지 않고 결과가 동점이 아닌 경우") + void getRushEventParticipantsTest_Success_withoutPhoneNumberWithOptionId() { + //given + List rushParticipantsList = new ArrayList<>(); + rushParticipantsList.add(rushParticipant1); + Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); + + given(rushParticipantsRepository.findByRushEvent_RushEventIdAndOptionId(eq(1L), eq(1), any(Pageable.class))) + .willReturn(rushParticipantsPage); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)) + .willReturn(1L); + + //when + RushEventParticipantsListResponseDto rushEventParticipants = adminService.getRushEventParticipants(1, 1, 0, 1, ""); + + //then + assertThat(rushEventParticipants.isLastPage()).isTrue(); + assertThat(rushEventParticipants.totalParticipants()).isEqualTo(1); + + List participantsList = rushEventParticipants.participantsList(); + + RushEventParticipantResponseDto participant = participantsList.get(0); + + assertThat(participant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(participant.balanceGameChoice()).isEqualTo(1); + assertThat(participant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(participant.rank()).isEqualTo(0); + } } From be81055efbb6a571672442e68a2ae95e46608bc3 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 20:58:22 +0900 Subject: [PATCH 18/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EA=B3=A0,=20?= =?UTF-8?q?=EB=8F=99=EC=A0=90=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=84=A0?= =?UTF-8?q?=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index a2b25139..af53c2db 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -609,4 +609,35 @@ void getRushEventParticipantsTest_Success_withoutPhoneNumberWithOptionId() { assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); assertThat(participant.rank()).isEqualTo(0); } + + @Test + @DisplayName("선착순 이벤트 참여자 조회 테스트 - 성공 (전화번호가 존재하고 결과가 동점인 경우") + void getRushEventParticipantsTest_Success_witPhoneNumberAndWithoutOptionId() { + //given + List rushParticipantsList = new ArrayList<>(); + rushParticipantsList.add(rushParticipant1); + Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); + + given(rushParticipantsRepository.findByRushEvent_RushEventIdAndBaseUser_Id(eq(1L), eq("010-0000-0000"), any(Pageable.class))) + .willReturn(rushParticipantsPage); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndBaseUser_Id(1L, "010-0000-0000")) + .willReturn(1L); + + //when + RushEventParticipantsListResponseDto rushEventParticipants = adminService.getRushEventParticipants(1, 1, 0, 0, "010-0000-0000"); + + //then + assertThat(rushEventParticipants.isLastPage()).isTrue(); + assertThat(rushEventParticipants.totalParticipants()).isEqualTo(1); + + List participantsList = rushEventParticipants.participantsList(); + + RushEventParticipantResponseDto participant = participantsList.get(0); + + assertThat(participant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(participant.balanceGameChoice()).isEqualTo(1); + assertThat(participant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(participant.rank()).isEqualTo(0); + } } From e9549825b45e3542f9829c1182f9a1a501cdf11f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:09:21 +0900 Subject: [PATCH 19/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EA=B3=A0,=20?= =?UTF-8?q?=EB=8F=99=EC=A0=90=EC=9D=B4=20=EC=95=84=EB=8B=8C=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index af53c2db..51378db4 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -52,6 +52,7 @@ import java.time.LocalTime; import java.util.*; +import static JGS.CasperEvent.global.util.RepositoryErrorHandler.findByIdOrElseThrow; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -201,8 +202,6 @@ void setUp() { Position.RIGHT ); - rushEvent.addOption(leftOption, rightOption); - // 선착순 이벤트 참여자 rushParticipant1 = new RushParticipants(user1, rushEvent, 1); rushParticipant1.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); @@ -473,6 +472,7 @@ void createRushEventTest_Failure_TooManyRushEvent() { @DisplayName("선착순 이벤트 조회 테스트 - 성공") void getRushEventsTest_Success() { //given + rushEvent.addOption(leftOption, rightOption); List rushEventList = new ArrayList<>(); rushEventList.add(rushEvent); given(rushEventRepository.findAll()).willReturn(rushEventList); @@ -640,4 +640,39 @@ void getRushEventParticipantsTest_Success_witPhoneNumberAndWithoutOptionId() { assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); assertThat(participant.rank()).isEqualTo(0); } + + @Test + @DisplayName("선착순 이벤트 당첨자 조회 테스트 - 성공 (전화번호가 존재하고 결과가 동점이 아닌 경우") + void getRushEventWinnersTest_Success_withPhoneNumberAndOptionId() { + //given + List rushParticipantsList = new ArrayList<>(); + rushParticipantsList.add(rushParticipant1); + Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); + + given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)) + .willReturn(2L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)) + .willReturn(1L); + given(rushParticipantsRepository.findWinnerByEventIdAndOptionIdAndPhoneNumber(eq(1L), eq(1), eq("010-0000-0000"), any(Pageable.class))) + .willReturn(rushParticipantsPage); + + //when + RushEventParticipantsListResponseDto rushEventWinners + = adminService.getRushEventWinners(1L, 1, 0, "010-0000-0000"); + + //then + assertThat(rushEventWinners.isLastPage()).isTrue(); + assertThat(rushEventWinners.totalParticipants()).isEqualTo(1); + + List participantsList = rushEventWinners.participantsList(); + + RushEventParticipantResponseDto participant = participantsList.get(0); + + assertThat(participant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(participant.balanceGameChoice()).isEqualTo(1); + assertThat(participant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(participant.rank()).isEqualTo(0); + } } From a940639d02d830343d4b3437a4bd55496a8640d5 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:12:06 +0900 Subject: [PATCH 20/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B3=A0,=20=EB=8F=99=EC=A0=90=EC=9D=B8=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 51378db4..75f21142 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -652,7 +652,7 @@ void getRushEventWinnersTest_Success_withPhoneNumberAndOptionId() { given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)) .willReturn(2L); - given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)) + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)) .willReturn(1L); given(rushParticipantsRepository.findWinnerByEventIdAndOptionIdAndPhoneNumber(eq(1L), eq(1), eq("010-0000-0000"), any(Pageable.class))) .willReturn(rushParticipantsPage); @@ -675,4 +675,39 @@ void getRushEventWinnersTest_Success_withPhoneNumberAndOptionId() { assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); assertThat(participant.rank()).isEqualTo(0); } + + @Test + @DisplayName("선착순 이벤트 당첨자 조회 테스트 - 성공 (전화번호가 존재하지 않고 결과가 동점인 경우") + void getRushEventWinnersTest_Success_withoutPhoneNumberAndOptionId() { + //given + List rushParticipantsList = new ArrayList<>(); + rushParticipantsList.add(rushParticipant1); + Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); + + given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)) + .willReturn(1L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)) + .willReturn(1L); + given(rushParticipantsRepository.findWinnerByEventId(eq(1L), any(Pageable.class))) + .willReturn(rushParticipantsPage); + + //when + RushEventParticipantsListResponseDto rushEventWinners + = adminService.getRushEventWinners(1L, 1, 0, ""); + + //then + assertThat(rushEventWinners.isLastPage()).isTrue(); + assertThat(rushEventWinners.totalParticipants()).isEqualTo(1); + + List participantsList = rushEventWinners.participantsList(); + + RushEventParticipantResponseDto participant = participantsList.get(0); + + assertThat(participant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(participant.balanceGameChoice()).isEqualTo(1); + assertThat(participant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(participant.rank()).isEqualTo(0); + } } From 8820e8d1fca0d1c7c5ce2727c6e4ccb2043c34a1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:13:21 +0900 Subject: [PATCH 21/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B3=A0,=20=EB=8F=99=EC=A0=90=EC=9D=B4=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20=EA=B2=BD=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 75f21142..edbf15f8 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -710,4 +710,39 @@ void getRushEventWinnersTest_Success_withoutPhoneNumberAndOptionId() { assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); assertThat(participant.rank()).isEqualTo(0); } + + @Test + @DisplayName("선착순 이벤트 당첨자 조회 테스트 - 성공 (전화번호가 존재하지 않고 결과가 동점이 아닌 경우") + void getRushEventWinnersTest_Success_withoutPhoneNumberAndWithOptionId() { + //given + List rushParticipantsList = new ArrayList<>(); + rushParticipantsList.add(rushParticipant1); + Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); + + given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)) + .willReturn(2L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)) + .willReturn(1L); + given(rushParticipantsRepository.findWinnerByEventIdAndOptionId(eq(1L), eq(1), any(Pageable.class))) + .willReturn(rushParticipantsPage); + + //when + RushEventParticipantsListResponseDto rushEventWinners + = adminService.getRushEventWinners(1L, 1, 0, ""); + + //then + assertThat(rushEventWinners.isLastPage()).isTrue(); + assertThat(rushEventWinners.totalParticipants()).isEqualTo(1); + + List participantsList = rushEventWinners.participantsList(); + + RushEventParticipantResponseDto participant = participantsList.get(0); + + assertThat(participant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(participant.balanceGameChoice()).isEqualTo(1); + assertThat(participant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(participant.rank()).isEqualTo(0); + } } From ef2b2e6f6c58e446edaa5425ae0fcc769f4888dd Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:14:48 +0900 Subject: [PATCH 22/55] =?UTF-8?q?test:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A7=80=EA=B3=A0,=20?= =?UTF-8?q?=EB=8F=99=EC=A0=90=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=84=A0?= =?UTF-8?q?=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index edbf15f8..136164b3 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -745,4 +745,39 @@ void getRushEventWinnersTest_Success_withoutPhoneNumberAndWithOptionId() { assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); assertThat(participant.rank()).isEqualTo(0); } + + @Test + @DisplayName("선착순 이벤트 당첨자 조회 테스트 - 성공 (전화번호가 존재하고 결과가 동점인 경우") + void getRushEventWinnersTest_Success_withPhoneNumberAndWithoutOptionId() { + //given + List rushParticipantsList = new ArrayList<>(); + rushParticipantsList.add(rushParticipant1); + Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); + + given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 1)) + .willReturn(1L); + given(rushParticipantsRepository.countByRushEvent_RushEventIdAndOptionId(1L, 2)) + .willReturn(1L); + given(rushParticipantsRepository.findByWinnerByEventIdAndPhoneNumber(eq(1L), eq("010-0000-0000"), any(Pageable.class))) + .willReturn(rushParticipantsPage); + + //when + RushEventParticipantsListResponseDto rushEventWinners + = adminService.getRushEventWinners(1L, 1, 0, "010-0000-0000"); + + //then + assertThat(rushEventWinners.isLastPage()).isTrue(); + assertThat(rushEventWinners.totalParticipants()).isEqualTo(1); + + List participantsList = rushEventWinners.participantsList(); + + RushEventParticipantResponseDto participant = participantsList.get(0); + + assertThat(participant.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(participant.balanceGameChoice()).isEqualTo(1); + assertThat(participant.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(participant.rank()).isEqualTo(0); + } } From b92eaffdaad0c7c7a30641d4836447e1931439af Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:19:45 +0900 Subject: [PATCH 23/55] =?UTF-8?q?test:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 8 ++++---- .../service/adminService/AdminServiceTest.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 854b6186..bd70bf03 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -227,6 +227,7 @@ public RushEventParticipantsListResponseDto getRushEventParticipants(long rushEv return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, count); } + // 선착순 이벤트 당첨자 조회 public RushEventParticipantsListResponseDto getRushEventWinners(long rushEventId, int size, int page, String phoneNumber) { Page rushParticipantsPage = null; @@ -239,10 +240,8 @@ public RushEventParticipantsListResponseDto getRushEventWinners(long rushEventId boolean isPhoneNumberEmpty = phoneNumber.isEmpty(); - int winnerOptionId; - if (leftSelect > rightSelect) winnerOptionId = 1; - else if (leftSelect < rightSelect) winnerOptionId = 2; - else winnerOptionId = 0; + int winnerOptionId = (leftSelect > rightSelect) ? 1 : (leftSelect < rightSelect) ? 2 : 0; + if (!isPhoneNumberEmpty && winnerOptionId != 0) { // 전화번호와 유효한 옵션 ID가 있는 경우 @@ -276,6 +275,7 @@ public RushEventParticipantsListResponseDto getRushEventWinners(long rushEventId return new RushEventParticipantsListResponseDto(rushEventParticipantResponseDtoList, isLastPage, totalParticipants); } + // 선착순 이벤트 삭제 @Transactional public void deleteLotteryEvent() { LotteryEvent currentLotteryEvent = getCurrentLotteryEvent(); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 136164b3..6c7e978c 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -780,4 +780,19 @@ void getRushEventWinnersTest_Success_withPhoneNumberAndWithoutOptionId() { assertThat(participant.createdTime()).isEqualTo(LocalTime.of(0, 0)); assertThat(participant.rank()).isEqualTo(0); } + + @Test + @DisplayName("선착순 이벤트 삭제 - 성공") + void deleteLotteryEvent_Success() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + + //when + adminService.deleteLotteryEvent(); + + //then + + } } From 50ae1e5f9d0c58bf2e59a860c84c39fb77114c5f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:23:23 +0900 Subject: [PATCH 24/55] =?UTF-8?q?test:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index bd70bf03..9341deac 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -282,6 +282,7 @@ public void deleteLotteryEvent() { lotteryEventRepository.deleteById(currentLotteryEvent.getLotteryEventId()); } + // 선착순 이벤트 업데이트 @Transactional public LotteryEventDetailResponseDto updateLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { LotteryEvent currentLotteryEvent = getCurrentLotteryEvent(); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 6c7e978c..d18b0076 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -791,8 +791,28 @@ void deleteLotteryEvent_Success() { //when adminService.deleteLotteryEvent(); + } - //then + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 성공") + void testName() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + //when + LotteryEventDetailResponseDto lotteryEventDetailResponseDto = adminService.updateLotteryEvent(lotteryEventRequestDto); + + //then + assertThat(lotteryEventDetailResponseDto.startDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(lotteryEventDetailResponseDto.startTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(lotteryEventDetailResponseDto.endDate()).isEqualTo(LocalDate.of(2100, 9, 27)); + assertThat(lotteryEventDetailResponseDto.endTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(lotteryEventDetailResponseDto.appliedCount()).isEqualTo(0); + assertThat(lotteryEventDetailResponseDto.winnerCount()).isEqualTo(315); + assertThat(lotteryEventDetailResponseDto.status()).isEqualTo(EventStatus.DURING); } + + } From e932a39065f53f0dae4e10b3920bdec78a4cb630 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:26:12 +0900 Subject: [PATCH 25/55] =?UTF-8?q?test:=20=EC=A2=85=EB=A3=8C=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=EA=B0=80=20=EC=8B=9C=EC=9E=91=20=EB=82=A0=EC=A7=9C?= =?UTF-8?q?=EB=B3=B4=EB=8B=A4=20=EC=95=9E=EC=84=9C=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index d18b0076..c5a81d06 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -52,7 +52,6 @@ import java.time.LocalTime; import java.util.*; -import static JGS.CasperEvent.global.util.RepositoryErrorHandler.findByIdOrElseThrow; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -794,8 +793,8 @@ void deleteLotteryEvent_Success() { } @Test - @DisplayName("선착순 이벤트 업데이트 테스트 - 성공") - void testName() { + @DisplayName("추첨 이벤트 업데이트 테스트 - 성공") + void updateLotteryEventTest_Success() { //given List lotteryEventList = new ArrayList<>(); lotteryEventList.add(lotteryEvent); @@ -814,5 +813,28 @@ void testName() { assertThat(lotteryEventDetailResponseDto.status()).isEqualTo(EventStatus.DURING); } + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (종료 날짜가 시작 날짜보다 앞서는 경우)") + void updateLotteryEventTest_Failure_EndBeforeStart() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + + lotteryEventRequestDto = LotteryEventRequestDto.builder() + .startDate(LocalDate.of(2100, 9, 27)) + .startTime(LocalTime.of(0, 0)) + .endDate(LocalDate.of(2000, 9, 27)) + .endTime(LocalTime.of(0, 0)) + .winnerCount(315) + .build(); + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.updateLotteryEvent(lotteryEventRequestDto) + ); + //then + assertEquals(CustomErrorCode.EVENT_END_TIME_BEFORE_START_TIME, customException.getErrorCode()); + assertEquals("종료 시간은 시작 시간 이후로 설정해야 합니다.", customException.getMessage()); + } } From 511213e277eb09699dbf234f8a76736f27baa9f6 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:28:19 +0900 Subject: [PATCH 26/55] =?UTF-8?q?test:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=EA=B0=80=20=EC=A7=84=ED=96=89=EC=A4=91=EC=9D=BC=20=EB=95=8C,?= =?UTF-8?q?=20=EC=8B=9C=EC=9E=91=20=EB=82=A0=EC=A7=9C=EB=A5=BC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=ED=95=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index c5a81d06..bc651451 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -837,4 +837,29 @@ void updateLotteryEventTest_Failure_EndBeforeStart() { assertEquals(CustomErrorCode.EVENT_END_TIME_BEFORE_START_TIME, customException.getErrorCode()); assertEquals("종료 시간은 시작 시간 이후로 설정해야 합니다.", customException.getMessage()); } + + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (이벤트가 진행중일 때, 시작 날짜를 수정하는 경우)") + void updateLotteryEventTest_Failure_Modifying_Ongoing_Event() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + + lotteryEventRequestDto = LotteryEventRequestDto.builder() + .startDate(LocalDate.of(2050, 9, 27)) + .startTime(LocalTime.of(0, 0)) + .endDate(LocalDate.of(2100, 9, 27)) + .endTime(LocalTime.of(0, 0)) + .winnerCount(315) + .build(); + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.updateLotteryEvent(lotteryEventRequestDto) + ); + + //then + assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME, customException.getErrorCode()); + assertEquals("현재 진행 중인 이벤트의 시작 시간을 변경할 수 없습니다.", customException.getMessage()); + } } From 5b83eca103ea038709c585bdaf74efa2433b6fb8 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:30:05 +0900 Subject: [PATCH 27/55] =?UTF-8?q?test:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=EA=B0=80=20=EC=A7=84=ED=96=89=EC=A4=91=EC=9D=BC=20=EB=95=8C,?= =?UTF-8?q?=20=EC=A2=85=EB=A3=8C=20=EB=82=A0=EC=A7=9C=EA=B0=80=20=ED=98=84?= =?UTF-8?q?=EC=9E=AC=20=EC=8B=9C=EA=B0=84=EB=B3=B4=EB=8B=A4=20=EC=95=9E?= =?UTF-8?q?=EC=84=9C=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=B6=94=EC=B2=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index bc651451..c3a421b7 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -862,4 +862,29 @@ void updateLotteryEventTest_Failure_Modifying_Ongoing_Event() { assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME, customException.getErrorCode()); assertEquals("현재 진행 중인 이벤트의 시작 시간을 변경할 수 없습니다.", customException.getMessage()); } + + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (이벤트가 진행중일 때, 종료 날짜가 현재 시간보다 앞서는 경우)") + void updateLotteryEventTest_Failure_EndBeforeNow() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + + lotteryEventRequestDto = LotteryEventRequestDto.builder() + .startDate(LocalDate.of(2000, 9, 27)) + .startTime(LocalTime.of(0, 0)) + .endDate(LocalDate.of(2001, 9, 27)) + .endTime(LocalTime.of(0, 0)) + .winnerCount(315) + .build(); + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.updateLotteryEvent(lotteryEventRequestDto) + ); + + //then + assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW, customException.getErrorCode()); + assertEquals("현재 진행 중인 이벤트의 종료 시간을 현재 시간보다 이전으로 설정할 수 없습니다.", customException.getMessage()); + } } From cf89f74d9dbbd98410d80b94c5fa6750f9231f83 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:32:43 +0900 Subject: [PATCH 28/55] =?UTF-8?q?test:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=EA=B0=80=20=EC=8B=9C=EC=9E=91=20=EC=A0=84=EC=9D=BC=20=EB=95=8C?= =?UTF-8?q?,=20=EC=8B=9C=EC=9E=91=20=EB=82=A0=EC=A7=9C=EA=B0=80=20?= =?UTF-8?q?=ED=98=84=EC=9E=AC=20=EC=8B=9C=EA=B0=84=EB=B3=B4=EB=8B=A4=20?= =?UTF-8?q?=EC=95=9E=EC=84=9C=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index c3a421b7..4fbff00a 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -887,4 +887,43 @@ void updateLotteryEventTest_Failure_EndBeforeNow() { assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW, customException.getErrorCode()); assertEquals("현재 진행 중인 이벤트의 종료 시간을 현재 시간보다 이전으로 설정할 수 없습니다.", customException.getMessage()); } + + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (이벤트가 시작 전일 때, 시작 날짜가 현재 시간보다 앞서는 경우)") + void updateLotteryEventTest_Failure_StartBeforeNow() { + //given + lotteryEventRequestDto = LotteryEventRequestDto.builder() + .startDate(LocalDate.of(2100, 9, 27)) + .startTime(LocalTime.of(0, 0)) + .endDate(LocalDate.of(2200, 9, 27)) + .endTime(LocalTime.of(0, 0)) + .winnerCount(315) + .build(); + + lotteryEvent = new LotteryEvent( + LocalDateTime.of(lotteryEventRequestDto.getStartDate(), lotteryEventRequestDto.getStartTime()), + LocalDateTime.of(lotteryEventRequestDto.getEndDate(), lotteryEventRequestDto.getEndTime()), + lotteryEventRequestDto.getWinnerCount() + ); + + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + + lotteryEventRequestDto = LotteryEventRequestDto.builder() + .startDate(LocalDate.of(2000, 9, 27)) + .startTime(LocalTime.of(0, 0)) + .endDate(LocalDate.of(2200, 9, 27)) + .endTime(LocalTime.of(0, 0)) + .winnerCount(315) + .build(); + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.updateLotteryEvent(lotteryEventRequestDto) + ); + + //then + assertEquals(CustomErrorCode.EVENT_BEFORE_START_TIME, customException.getErrorCode()); + assertEquals("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", customException.getMessage()); + } } From 95a6ebe19c32f1cda3925cbafff0c6cd00f8841c Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:37:12 +0900 Subject: [PATCH 29/55] =?UTF-8?q?test:=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=20=EC=B6=94=EC=B2=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=EA=B0=80=202=EA=B0=9C=20=EC=9D=B4?= =?UTF-8?q?=EC=83=81=20=EC=A1=B4=EC=9E=AC=ED=95=A0=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 9341deac..a6ff5c66 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -317,6 +317,7 @@ else if (newStartDateTime.isBefore(now)) { return LotteryEventDetailResponseDto.of(currentLotteryEvent); } + // 추첨 이벤트 조회 private LotteryEvent getCurrentLotteryEvent() { List lotteryEventList = lotteryEventRepository.findAll(); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 4fbff00a..3418491b 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -336,6 +336,26 @@ void getLotteryEventTest_Success() { assertThat(lotteryEventDetailResponseDto.status()).isEqualTo(EventStatus.DURING); } + @Test + @DisplayName("추첨 이벤트 조회 테스트 - 실패 (데이터베이스에 추첨 이벤트가 2개 이상 존재)") + void getCurrentLotteryEvent_Success() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + lotteryEventList.add(lotteryEvent); + given(lotteryEventRepository.findAll()) + .willReturn(lotteryEventList); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.getLotteryEvent() + ); + + //then + assertEquals(CustomErrorCode.TOO_MANY_LOTTERY_EVENT, customException.getErrorCode()); + assertEquals("현재 진행중인 lotteryEvent가 2개 이상입니다.", customException.getMessage()); + } + @Test @DisplayName("추첨 이벤트 참여자 조회 성공 테스트 (전화번호가 없을 때)") void getLotteryEventParticipantsTest_Success_withoutPhoneNumber() { @@ -926,4 +946,5 @@ void updateLotteryEventTest_Failure_StartBeforeNow() { assertEquals(CustomErrorCode.EVENT_BEFORE_START_TIME, customException.getErrorCode()); assertEquals("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", customException.getMessage()); } + } From 2c51e55142cd7b84377f36be31838033058ad92a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:38:43 +0900 Subject: [PATCH 30/55] =?UTF-8?q?test:=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=EC=97=90=20=EC=B6=94=EC=B2=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=EA=B0=80=20=EC=97=86=EB=8A=94=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 3418491b..8374fc34 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -336,9 +336,27 @@ void getLotteryEventTest_Success() { assertThat(lotteryEventDetailResponseDto.status()).isEqualTo(EventStatus.DURING); } + @Test + @DisplayName("추첨 이벤트 조회 테스트 - 실패 (데이터베이스에 추첨 이벤트가 없을 때)") + void getLotteryEvent_Failure_NoLotteryEvent() { + //given + List lotteryEventList = new ArrayList<>(); + given(lotteryEventRepository.findAll()) + .willReturn(lotteryEventList); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.getLotteryEvent() + ); + + //then + assertEquals(CustomErrorCode.NO_LOTTERY_EVENT, customException.getErrorCode()); + assertEquals("현재 진행중인 lotteryEvent가 존재하지 않습니다.", customException.getMessage()); + } + @Test @DisplayName("추첨 이벤트 조회 테스트 - 실패 (데이터베이스에 추첨 이벤트가 2개 이상 존재)") - void getCurrentLotteryEvent_Success() { + void getLotteryEvent_Failure_TooManyLotteryEvent() { //given List lotteryEventList = new ArrayList<>(); lotteryEventList.add(lotteryEvent); From 4ae3339bd763a72cee5242a4649c1967f93998f1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:50:09 +0900 Subject: [PATCH 31/55] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EC=98=88?= =?UTF-8?q?=EC=A0=95=20=EC=9D=B8=EC=9B=90=EB=B3=B4=EB=8B=A4=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=EC=9D=B8=EC=9B=90=EC=9D=B4=20=EB=8D=94=20=EC=A0=81?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EB=8B=B9=EC=B2=A8=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/adminService/AdminService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index a6ff5c66..5e9a10bb 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -332,6 +332,7 @@ private LotteryEvent getCurrentLotteryEvent() { return lotteryEventList.get(0); } + // 추첨 이벤트 당첨자 추첨 @Transactional public ResponseDto pickLotteryEventWinners() { if (lotteryWinnerRepository.count() > 1) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_ALREADY_DRAWN); @@ -340,6 +341,13 @@ public ResponseDto pickLotteryEventWinners() { int winnerCount = lotteryEvent.getWinnerCount(); List lotteryParticipants = lotteryParticipantsRepository.findAll(); + + if(winnerCount >= lotteryParticipants.size()){ + for (LotteryParticipants lotteryParticipant : lotteryParticipants) { + lotteryWinnerRepository.save(new LotteryWinners(lotteryParticipant)); + } + return new ResponseDto("추첨이 완료되었습니다."); + } Set lotteryEventWinners = new HashSet<>(); int totalWeight; From 9872ec0994b5aa7de276dd7b95b70c6a125f7fe7 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:50:19 +0900 Subject: [PATCH 32/55] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EC=98=88?= =?UTF-8?q?=EC=A0=95=20=EC=9D=B8=EC=9B=90=EB=B3=B4=EB=8B=A4=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=EC=9D=B8=EC=9B=90=EC=9D=B4=20=EB=8D=94=20=EC=A0=81?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/participants/LotteryWinners.java | 2 +- .../adminService/AdminServiceTest.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java index 1a3f98cc..c5c091fe 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryWinners.java @@ -11,7 +11,7 @@ @Entity @Getter public class LotteryWinners { - private long id; + private Long id; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 8374fc34..7de03027 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -965,4 +965,25 @@ void updateLotteryEventTest_Failure_StartBeforeNow() { assertEquals("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", customException.getMessage()); } + @Test + @DisplayName("추첨 이벤트 당첨자 추첨 테스트 - 성공 (당첨인원보다 신청인원이 적을 경우)") + void pickLotteryEventWinners_Success_ParticipantsIsLessThanWinners() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + List lotteryParticipantsList = new ArrayList<>(); + lotteryParticipantsList.add(lotteryParticipants); + + + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + given(lotteryWinnerRepository.count()).willReturn(0L); + given(lotteryParticipantsRepository.findAll()).willReturn(lotteryParticipantsList); + + //when + ResponseDto responseDto = adminService.pickLotteryEventWinners(); + + //then + assertThat(responseDto.message()).isEqualTo("추첨이 완료되었습니다."); + } + } From 921db48a0db6dc89ebfb17e61e0f795e9b4a4a54 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 21:58:16 +0900 Subject: [PATCH 33/55] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 7de03027..5cc48bea 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -965,6 +965,31 @@ void updateLotteryEventTest_Failure_StartBeforeNow() { assertEquals("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", customException.getMessage()); } + @Test + @DisplayName("추첨 이벤트 당첨자 추첨 테스트 - 성공") + void pickLotteryEventWinners_Success() { + //given + List lotteryEventList = new ArrayList<>(); + lotteryEventList.add(lotteryEvent); + List lotteryParticipantsList = new ArrayList<>(); + + for (int i = 0; i < 400; i++) { + BaseUser user = new BaseUser(String.format("010-0000-%04d", i), Role.USER); + LotteryParticipants lotteryParticipants = new LotteryParticipants(user); + lotteryParticipantsList.add(lotteryParticipants); + } + + given(lotteryEventRepository.findAll()).willReturn(lotteryEventList); + given(lotteryWinnerRepository.count()).willReturn(0L); + given(lotteryParticipantsRepository.findAll()).willReturn(lotteryParticipantsList); + + //when + ResponseDto responseDto = adminService.pickLotteryEventWinners(); + + //then + assertThat(responseDto.message()).isEqualTo("추첨이 완료되었습니다."); + } + @Test @DisplayName("추첨 이벤트 당첨자 추첨 테스트 - 성공 (당첨인원보다 신청인원이 적을 경우)") void pickLotteryEventWinners_Success_ParticipantsIsLessThanWinners() { From ab41da54ed556e19ea8b916f39ea5e5f1ed0560e Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:00:13 +0900 Subject: [PATCH 34/55] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=EC=9D=98=20=EB=8B=B9=EC=B2=A8=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=EC=9D=B4=EB=AF=B8=20=EC=B6=94=EC=B2=A8=EB=90=98?= =?UTF-8?q?=EC=97=88=EC=9D=84=20=EB=95=8C,=20=EB=8B=B9=EC=B2=A8=EC=9E=90?= =?UTF-8?q?=20=EC=B6=94=EC=B2=A8=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminServiceTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 5cc48bea..b71e83b3 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1011,4 +1011,19 @@ void pickLotteryEventWinners_Success_ParticipantsIsLessThanWinners() { assertThat(responseDto.message()).isEqualTo("추첨이 완료되었습니다."); } + @Test + @DisplayName("추첨 이벤트 당첨자 추첨 테스트 - 실패 (이미 추첨이 완료된 경우)") + void pickLotteryEventWinnersTest_Failure_AlreadyDrown() { + //given + given(lotteryWinnerRepository.count()).willReturn(315L); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.pickLotteryEventWinners() + ); + + //then + assertEquals(CustomErrorCode.LOTTERY_EVENT_ALREADY_DRAWN, customException.getErrorCode()); + assertEquals("추첨 이벤트의 당첨자가 이미 추첨되었습니다.", customException.getMessage()); + } } From a4147bef14746c468dc187100aa7029d80c1705e Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:01:41 +0900 Subject: [PATCH 35/55] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EB=AA=85?= =?UTF-8?q?=EB=8B=A8=20=EC=82=AD=EC=A0=9C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 1 + .../service/adminService/AdminServiceTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 5e9a10bb..0b88407a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -378,6 +378,7 @@ public ResponseDto pickLotteryEventWinners() { return new ResponseDto("추첨이 완료되었습니다."); } + // 당첨자 명단 삭제 public ResponseDto deleteLotteryEventWinners() { lotteryWinnerRepository.deleteAll(); return new ResponseDto("당첨자 명단을 삭제했습니다."); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index b71e83b3..4f0f5ba2 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1026,4 +1026,17 @@ void pickLotteryEventWinnersTest_Failure_AlreadyDrown() { assertEquals(CustomErrorCode.LOTTERY_EVENT_ALREADY_DRAWN, customException.getErrorCode()); assertEquals("추첨 이벤트의 당첨자가 이미 추첨되었습니다.", customException.getMessage()); } + + @Test + @DisplayName("당첨자 명단 삭제 테스트 - 성공") + void deleteLotteryEventWinnersTest_Success() { + //given + + //when + ResponseDto responseDto = adminService.deleteLotteryEventWinners(); + + //then + assertThat(responseDto.message()).isEqualTo("당첨자 명단을 삭제했습니다."); + + } } From 506b2f2d7a74bae004ca7c129555871e9390af36 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:08:48 +0900 Subject: [PATCH 36/55] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EB=AA=85?= =?UTF-8?q?=EB=8B=A8=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 38 ++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 0b88407a..a26e9de8 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -384,6 +384,7 @@ public ResponseDto deleteLotteryEventWinners() { return new ResponseDto("당첨자 명단을 삭제했습니다."); } + // 추첨 이벤트 당첨자 명단 조회 public LotteryEventWinnerListResponseDto getLotteryEventWinners(int size, int page, String phoneNumber) { Pageable pageable = PageRequest.of(page, size); if (lotteryWinnerRepository.count() == 0) throw new CustomException(CustomErrorCode.LOTTERY_EVENT_NOT_DRAWN); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 4f0f5ba2..82dd5e5f 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -9,15 +9,13 @@ import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsResponseDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.AdminRushEventResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventOptionResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.RushEventParticipantsListResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.*; import JGS.CasperEvent.domain.event.entity.admin.Admin; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import JGS.CasperEvent.domain.event.entity.participants.LotteryWinners; import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import JGS.CasperEvent.domain.event.repository.AdminRepository; import JGS.CasperEvent.domain.event.repository.CasperBotRepository; @@ -134,7 +132,8 @@ void setUp() { // 추첨 이벤트 참여자 엔티티 lotteryParticipants = new LotteryParticipants(user1); - + lotteryParticipants.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lotteryParticipants.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); // 선착순 이벤트 옵션 요청 DTO leftOptionRequestDto = RushEventOptionRequestDto.builder() @@ -1037,6 +1036,35 @@ void deleteLotteryEventWinnersTest_Success() { //then assertThat(responseDto.message()).isEqualTo("당첨자 명단을 삭제했습니다."); + } + + @Test + @DisplayName("당첨자 명단 조회 테스트 - 성공") + void testName() { + //given + List lotteryWinnersList = new ArrayList<>(); + lotteryWinnersList.add(new LotteryWinners(lotteryParticipants)); + Page lotteryWinnersPage = new PageImpl<>(lotteryWinnersList); + given(lotteryWinnerRepository.count()).willReturn(315L); + given(lotteryWinnerRepository.findAll(any(Pageable.class))) + .willReturn(lotteryWinnersPage); + + //when + LotteryEventWinnerListResponseDto lotteryEventWinners = adminService.getLotteryEventWinners(1, 0, ""); + + //then + LotteryEventWinnerResponseDto actualWinner = lotteryEventWinners.participantsList().get(0); + assertThat(actualWinner.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(actualWinner.linkClickedCounts()).isEqualTo(0); + assertThat(actualWinner.expectation()).isEqualTo(0); + assertThat(actualWinner.appliedCount()).isEqualTo(1); + assertThat(actualWinner.ranking()).isEqualTo(0); + assertThat(actualWinner.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(actualWinner.createdTime()).isEqualTo(LocalTime.of(0, 0)); + + assertThat(lotteryEventWinners.isLastPage()).isTrue(); + + assertThat(lotteryEventWinners.totalParticipants()).isEqualTo(315); } } From 8dbfd942851175f16f34c8df7baa42f428e64ab1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:11:08 +0900 Subject: [PATCH 37/55] =?UTF-8?q?feat:=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=A3=BC=EC=96=B4=EC=A1=8C=EC=9D=84=20?= =?UTF-8?q?=EB=95=8C=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EB=AA=85=EB=8B=A8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 82dd5e5f..abd9dabb 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1039,8 +1039,8 @@ void deleteLotteryEventWinnersTest_Success() { } @Test - @DisplayName("당첨자 명단 조회 테스트 - 성공") - void testName() { + @DisplayName("당첨자 명단 조회 테스트 - 성공 (전화번호가 주어지지 않은 경우)") + void getLotteryEventWinnersTest_Success_WithoutPhoneNumber() { //given List lotteryWinnersList = new ArrayList<>(); lotteryWinnersList.add(new LotteryWinners(lotteryParticipants)); @@ -1067,4 +1067,35 @@ void testName() { assertThat(lotteryEventWinners.totalParticipants()).isEqualTo(315); } + + @Test + @DisplayName("당첨자 명단 조회 테스트 - 성공 (전화번호가 주어진 경우)") + void getLotteryEventWinnersTest_Success_WithPhoneNumber() { + //given + List lotteryWinnersList = new ArrayList<>(); + lotteryWinnersList.add(new LotteryWinners(lotteryParticipants)); + Page lotteryWinnersPage = new PageImpl<>(lotteryWinnersList); + + given(lotteryWinnerRepository.count()).willReturn(315L); + given(lotteryWinnerRepository.findByPhoneNumber(eq("010-0000-0000"), any(Pageable.class))) + .willReturn(lotteryWinnersPage); + given(lotteryWinnerRepository.countByPhoneNumber("010-0000-0000")).willReturn(1L); + + //when + LotteryEventWinnerListResponseDto lotteryEventWinners = adminService.getLotteryEventWinners(1, 0, "010-0000-0000"); + + //then + LotteryEventWinnerResponseDto actualWinner = lotteryEventWinners.participantsList().get(0); + assertThat(actualWinner.phoneNumber()).isEqualTo("010-0000-0000"); + assertThat(actualWinner.linkClickedCounts()).isEqualTo(0); + assertThat(actualWinner.expectation()).isEqualTo(0); + assertThat(actualWinner.appliedCount()).isEqualTo(1); + assertThat(actualWinner.ranking()).isEqualTo(0); + assertThat(actualWinner.createdDate()).isEqualTo(LocalDate.of(2000, 9, 27)); + assertThat(actualWinner.createdTime()).isEqualTo(LocalTime.of(0, 0)); + + assertThat(lotteryEventWinners.isLastPage()).isTrue(); + + assertThat(lotteryEventWinners.totalParticipants()).isEqualTo(1); + } } From 191759a2885887c0a6f60938e4cfe92dfadd3ef9 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:13:08 +0900 Subject: [PATCH 38/55] =?UTF-8?q?feat:=20=EC=95=84=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=ED=95=98=EC=A7=80=20=EC=95=8A=EC=95=98=EC=9D=84=20?= =?UTF-8?q?=EB=95=8C=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=EC=9E=90=20=EB=AA=85=EB=8B=A8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminServiceTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index abd9dabb..2e20a46e 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1098,4 +1098,20 @@ void getLotteryEventWinnersTest_Success_WithPhoneNumber() { assertThat(lotteryEventWinners.totalParticipants()).isEqualTo(1); } + + @Test + @DisplayName("추첨 이벤트 당첨자 조회 테스트 - 실패 (아직 추첨하지 않음)") + void getLotteryEventWinnersTest_Failure_NotDrawn() { + //given + given(lotteryWinnerRepository.count()).willReturn(0L); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.getLotteryEventWinners(1, 0, "") + ); + + //then + assertEquals(CustomErrorCode.LOTTERY_EVENT_NOT_DRAWN, customException.getErrorCode()); + assertEquals("추첨 이벤트가 아직 추첨되지 않았습니다.", customException.getMessage()); + } } From 2af5b0c1126418d7a1388d335b24e6d24596e88d Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:23:56 +0900 Subject: [PATCH 39/55] =?UTF-8?q?test:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 59 ++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index a26e9de8..386e4232 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -410,6 +410,7 @@ public LotteryEventWinnerListResponseDto getLotteryEventWinners(int size, int pa return new LotteryEventWinnerListResponseDto(lotteryEventWinnerResponseDto, isLastPage, count); } + // 선착순 이벤트 업데이트 @Transactional public List updateRushEvents(List rushEventRequestDtoList) { LocalDateTime now = LocalDateTime.now(); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 2e20a46e..84354503 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -143,7 +143,7 @@ void setUp() { .subText("Sub Text 1") .resultMainText("Result Main Text 1") .resultSubText("Result Sub Text 1") - .imageUrl("http://example.com/leftImage.jpg").build(); + .imageUrl("http://example.com/image.jpg").build(); rightOptionRequestDto = RushEventOptionRequestDto.builder() .rushOptionId(1L) @@ -152,7 +152,7 @@ void setUp() { .subText("Sub Text 2") .resultMainText("Result Main Text 2") .resultSubText("Result Sub Text 2") - .imageUrl("http://example.com/rightImage.jpg").build(); + .imageUrl("http://example.com/image.jpg").build(); Set options = new HashSet<>(); options.add(leftOptionRequestDto); @@ -1114,4 +1114,59 @@ void getLotteryEventWinnersTest_Failure_NotDrawn() { assertEquals(CustomErrorCode.LOTTERY_EVENT_NOT_DRAWN, customException.getErrorCode()); assertEquals("추첨 이벤트가 아직 추첨되지 않았습니다.", customException.getMessage()); } + + @Test + @DisplayName("테스트") + void testName() { + //given + rushEvent.addOption(leftOption, rightOption); + List rushEventRequestDtoList = new ArrayList<>(); + rushEventRequestDtoList.add(rushEventRequestDto); + + List rushEventList = new ArrayList<>(); + rushEventList.add(rushEvent); + + given(rushEventRepository.findByRushEventId(1L)).willReturn(rushEvent); + given(rushEventRepository.findAll()).willReturn(rushEventList); + + //when + List rushEventResponseDtoList = adminService.updateRushEvents(rushEventRequestDtoList); + + //then + + AdminRushEventResponseDto actualRushEvent = rushEventResponseDtoList.iterator().next(); + assertThat(actualRushEvent.eventDate()).isEqualTo(LocalDate.of(2024, 8, 15)); + assertThat(actualRushEvent.startTime()).isEqualTo(LocalTime.of(0, 0)); + assertThat(actualRushEvent.endTime()).isEqualTo(LocalTime.of(23, 59)); + assertThat(actualRushEvent.winnerCount()).isEqualTo(100); + assertThat(actualRushEvent.prizeImageUrl()).isEqualTo("http://example.com/image.jpg"); + assertThat(actualRushEvent.prizeDescription()).isEqualTo("This is a detailed description of the prize."); + assertThat(actualRushEvent.status()).isEqualTo(EventStatus.AFTER); + + Set options = actualRushEvent.options(); + + boolean firstOptionFound = false; + boolean secondOptionFound = false; + + for (RushEventOptionResponseDto option : options) { + if (option.mainText().equals("Main Text 2") && + option.subText().equals("Sub Text 2") && + option.resultMainText().equals("Result Main Text 2") && + option.resultSubText().equals("Result Sub Text 2") && + option.imageUrl().equals("http://example.com/image.jpg") && + option.position().equals(Position.RIGHT)) { + firstOptionFound = true; + } else if (option.mainText().equals("Main Text 1") && + option.subText().equals("Sub Text 1") && + option.resultMainText().equals("Result Main Text 1") && + option.resultSubText().equals("Result Sub Text 1") && + option.imageUrl().equals("http://example.com/image.jpg") && + option.position().equals(Position.LEFT)) { + secondOptionFound = true; + } + } + + assertThat(firstOptionFound).isTrue(); + assertThat(secondOptionFound).isTrue(); + } } From 92b8a6a3a2652f4fdf8ba411c1b2f6890b88d305 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:30:24 +0900 Subject: [PATCH 40/55] =?UTF-8?q?test:=20=EC=A2=85=EB=A3=8C=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=9D=B4=20=EC=8B=9C=EC=9E=91=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EB=B3=B4=EB=8B=A4=20=EC=95=9E=EC=84=9C=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 84354503..f5f255d2 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1116,8 +1116,8 @@ void getLotteryEventWinnersTest_Failure_NotDrawn() { } @Test - @DisplayName("테스트") - void testName() { + @DisplayName("선착순 이벤트 업데이트 테스트 - 성공") + void updateRushEventTest_Success() { //given rushEvent.addOption(leftOption, rightOption); List rushEventRequestDtoList = new ArrayList<>(); @@ -1169,4 +1169,43 @@ void testName() { assertThat(firstOptionFound).isTrue(); assertThat(secondOptionFound).isTrue(); } + + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (종료 시간이 시작 시간보다 앞서는 경우)") + void testName() { + //given + rushEvent.addOption(leftOption, rightOption); + List rushEventRequestDtoList = new ArrayList<>(); + + Set options = new HashSet<>(); + options.add(leftOptionRequestDto); + options.add(rightOptionRequestDto); + + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.of(2024, 8, 15)) + .startTime(LocalTime.of(23, 59)) + .endTime(LocalTime.of(0, 0)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + rushEventRequestDtoList.add(rushEventRequestDto); + + List rushEventList = new ArrayList<>(); + rushEventList.add(rushEvent); + + given(rushEventRepository.findByRushEventId(1L)).willReturn(rushEvent); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.updateRushEvents(rushEventRequestDtoList) + ); + + //then + assertEquals(CustomErrorCode.EVENT_END_TIME_BEFORE_START_TIME, customException.getErrorCode()); + assertEquals("종료 시간은 시작 시간 이후로 설정해야 합니다.", customException.getMessage()); + } } From dc6913a67ac5ffdd4c9e1233afeae18a7543df7e Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:35:21 +0900 Subject: [PATCH 41/55] =?UTF-8?q?test:=20=EC=A7=84=ED=96=89=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=9D=98=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=20=EC=8B=9C=EA=B0=84=EC=9D=84=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=84=A0=EC=B0=A9?= =?UTF-8?q?=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index f5f255d2..7c4160de 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -877,7 +877,7 @@ void updateLotteryEventTest_Failure_EndBeforeStart() { @Test @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (이벤트가 진행중일 때, 시작 날짜를 수정하는 경우)") - void updateLotteryEventTest_Failure_Modifying_Ongoing_Event() { + void updateLotteryEventTest_Failure_ModifyingOngoingEvent() { //given List lotteryEventList = new ArrayList<>(); lotteryEventList.add(lotteryEvent); @@ -1172,7 +1172,7 @@ void updateRushEventTest_Success() { @Test @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (종료 시간이 시작 시간보다 앞서는 경우)") - void testName() { + void updateRushEventTest_Failure_EndBeforeStart() { //given rushEvent.addOption(leftOption, rightOption); List rushEventRequestDtoList = new ArrayList<>(); @@ -1208,4 +1208,62 @@ void testName() { assertEquals(CustomErrorCode.EVENT_END_TIME_BEFORE_START_TIME, customException.getErrorCode()); assertEquals("종료 시간은 시작 시간 이후로 설정해야 합니다.", customException.getMessage()); } + + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (진행중인 이벤트의 시작 시간을 수정하는 경우)") + void updateRushEventTest_Failure_ModifyingOngoingEvent() { + //given + Set options = new HashSet<>(); + options.add(leftOptionRequestDto); + options.add(rightOptionRequestDto); + + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.now()) + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.of(23, 59)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + rushEvent = new RushEvent( + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getStartTime()), + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getEndTime()), + rushEventRequestDto.getWinnerCount(), + "http://example.com/image.jpg", + rushEventRequestDto.getPrizeDescription() + ); + + rushEvent.addOption(leftOption, rightOption); + List rushEventRequestDtoList = new ArrayList<>(); + + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.now()) + .startTime(LocalTime.of(23, 58)) + .endTime(LocalTime.of(23, 59)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + rushEventRequestDtoList.add(rushEventRequestDto); + + List rushEventList = new ArrayList<>(); + rushEventList.add(rushEvent); + + given(rushEventRepository.findByRushEventId(1L)).willReturn(rushEvent); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.updateRushEvents(rushEventRequestDtoList) + ); + + //then + assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME, customException.getErrorCode()); + assertEquals("현재 진행 중인 이벤트의 시작 시간을 변경할 수 없습니다.", customException.getMessage()); + } } From b47ce0752af874452f0fa0d80a876ee1b6e18b24 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:39:56 +0900 Subject: [PATCH 42/55] =?UTF-8?q?test:=20=EC=A7=84=ED=96=89=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=9D=98=20=EC=A2=85?= =?UTF-8?q?=EB=A3=8C=20=EC=8B=9C=EA=B0=84=EC=9D=84=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=84=A0=EC=B0=A9?= =?UTF-8?q?=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 7c4160de..9f7a9da7 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1266,4 +1266,62 @@ void updateRushEventTest_Failure_ModifyingOngoingEvent() { assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_CHANGE_START_TIME, customException.getErrorCode()); assertEquals("현재 진행 중인 이벤트의 시작 시간을 변경할 수 없습니다.", customException.getMessage()); } + + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (진행중인 이벤트의 종료 시간을 수정하는 경우)") + void updateRushEventTest_Failure_EndBeforeNow() { + //given + Set options = new HashSet<>(); + options.add(leftOptionRequestDto); + options.add(rightOptionRequestDto); + + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.now()) + .startTime(LocalTime.of(0,0)) + .endTime(LocalTime.of(23, 59)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + rushEvent = new RushEvent( + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getStartTime()), + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getEndTime()), + rushEventRequestDto.getWinnerCount(), + "http://example.com/image.jpg", + rushEventRequestDto.getPrizeDescription() + ); + + rushEvent.addOption(leftOption, rightOption); + List rushEventRequestDtoList = new ArrayList<>(); + + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.now()) + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.now().minusSeconds(5)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + rushEventRequestDtoList.add(rushEventRequestDto); + + List rushEventList = new ArrayList<>(); + rushEventList.add(rushEvent); + + given(rushEventRepository.findByRushEventId(1L)).willReturn(rushEvent); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.updateRushEvents(rushEventRequestDtoList) + ); + + //then + assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW, customException.getErrorCode()); + assertEquals("현재 진행 중인 이벤트의 종료 시간을 현재 시간보다 이전으로 설정할 수 없습니다.", customException.getMessage()); + } } From 68cb970a9dcf8127b581dccd49c096ed07e88f63 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:42:26 +0900 Subject: [PATCH 43/55] =?UTF-8?q?test:=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=20=EC=A0=84=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 9f7a9da7..50d1328f 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1278,7 +1278,7 @@ void updateRushEventTest_Failure_EndBeforeNow() { rushEventRequestDto = RushEventRequestDto.builder() .rushEventId(1L) .eventDate(LocalDate.now()) - .startTime(LocalTime.of(0,0)) + .startTime(LocalTime.of(0, 0)) .endTime(LocalTime.of(23, 59)) .winnerCount(100) .prizeImageUrl("http://example.com/image.jpg") @@ -1324,4 +1324,63 @@ void updateRushEventTest_Failure_EndBeforeNow() { assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_END_TIME_BEFORE_NOW, customException.getErrorCode()); assertEquals("현재 진행 중인 이벤트의 종료 시간을 현재 시간보다 이전으로 설정할 수 없습니다.", customException.getMessage()); } + + @Test + @DisplayName("선착순 이벤트 업데이트 테스트 - 실패 (이벤트 시작 전인 경우)") + void updateRushEventTest_Failure_StartBeforeNow() { + //given + Set options = new HashSet<>(); + options.add(leftOptionRequestDto); + options.add(rightOptionRequestDto); + + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.of(2100, 1, 1)) + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.of(23, 59)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + rushEvent = new RushEvent( + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getStartTime()), + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getEndTime()), + rushEventRequestDto.getWinnerCount(), + "http://example.com/image.jpg", + rushEventRequestDto.getPrizeDescription() + ); + + rushEvent.addOption(leftOption, rightOption); + List rushEventRequestDtoList = new ArrayList<>(); + + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.of(1945,8,15)) + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.now().minusSeconds(5)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + rushEventRequestDtoList.add(rushEventRequestDto); + + List rushEventList = new ArrayList<>(); + rushEventList.add(rushEvent); + + given(rushEventRepository.findByRushEventId(1L)).willReturn(rushEvent); + + //when + CustomException customException = assertThrows(CustomException.class, () -> + adminService.updateRushEvents(rushEventRequestDtoList) + ); + + //then + assertEquals(CustomErrorCode.EVENT_BEFORE_START_TIME, customException.getErrorCode()); + assertEquals("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", customException.getMessage()); + } + } From 5a7bcf85e872947709e5db6396f70602d7f4934a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:44:33 +0900 Subject: [PATCH 44/55] =?UTF-8?q?test:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/adminService/AdminService.java | 1 + .../event/service/adminService/AdminServiceTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 386e4232..262bd89a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -460,6 +460,7 @@ else if (startDateTime.isBefore(now)) { return rushEventResponseDtoList; } + // 선착순 이벤트 삭제 @Transactional public ResponseDto deleteRushEvent(Long rushEventId) { RushEvent rushEvent = rushEventRepository.findById(rushEventId).orElseThrow(() -> new CustomException(CustomErrorCode.NO_RUSH_EVENT)); diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 50d1328f..acc5836c 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1383,4 +1383,16 @@ void updateRushEventTest_Failure_StartBeforeNow() { assertEquals("이벤트 시작 시간은 현재 시간 이후로 설정해야 합니다.", customException.getMessage()); } + @Test + @DisplayName("선착순 이벤트 삭제 테스트 - 성공") + void deleteRushEventTest_Success() { + //given + given(rushEventRepository.findById(1L)).willReturn(Optional.ofNullable(rushEvent)); + + //when + ResponseDto responseDto = adminService.deleteRushEvent(1L); + + //then + assertThat(responseDto.message()).isEqualTo("요청에 성공하였습니다."); + } } From 1a6d685fa5c1ab641aa1eb1bdaf704b145fa919e Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:46:46 +0900 Subject: [PATCH 45/55] =?UTF-8?q?test:=20=EC=9D=BC=EC=B9=98=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EA=B0=80=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C=20=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminServiceTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index acc5836c..1b0475a3 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1357,7 +1357,7 @@ void updateRushEventTest_Failure_StartBeforeNow() { rushEventRequestDto = RushEventRequestDto.builder() .rushEventId(1L) - .eventDate(LocalDate.of(1945,8,15)) + .eventDate(LocalDate.of(1945, 8, 15)) .startTime(LocalTime.of(0, 0)) .endTime(LocalTime.now().minusSeconds(5)) .winnerCount(100) @@ -1395,4 +1395,20 @@ void deleteRushEventTest_Success() { //then assertThat(responseDto.message()).isEqualTo("요청에 성공하였습니다."); } + + @Test + @DisplayName("선착순 이벤트 삭제 테스트 - 실패 (아이디와 일치하는 이벤트가 없는 경우)") + void deleteRushEventTest_Failure_NoLotteryEvent() { + //given + given(rushEventRepository.findById(1L)).willReturn(Optional.empty()); + + //when + CustomException customException = assertThrows(CustomException.class, + () -> adminService.deleteRushEvent(1L) + ); + + //then + assertEquals(CustomErrorCode.NO_RUSH_EVENT, customException.getErrorCode()); + assertEquals("선착순 이벤트를 찾을 수 없습니다.", customException.getMessage()); + } } From c84c6cd9b178a2a7a83b3c05794e467875dcb8d1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:48:51 +0900 Subject: [PATCH 46/55] =?UTF-8?q?test:=20=EC=A7=84=ED=96=89=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=9D=BC=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=84=A0=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AD=EC=A0=9C=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 1b0475a3..b0fb034c 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1411,4 +1411,45 @@ void deleteRushEventTest_Failure_NoLotteryEvent() { assertEquals(CustomErrorCode.NO_RUSH_EVENT, customException.getErrorCode()); assertEquals("선착순 이벤트를 찾을 수 없습니다.", customException.getMessage()); } + + @Test + @DisplayName("선착순 이벤트 삭제 테스트 - 실패 (진행중인 이벤트일 경우)") + void deleteRushEventTest_Failure_EventInProgress() { + //given + Set options = new HashSet<>(); + options.add(leftOptionRequestDto); + options.add(rightOptionRequestDto); + + rushEventRequestDto = RushEventRequestDto.builder() + .rushEventId(1L) + .eventDate(LocalDate.now()) + .startTime(LocalTime.of(0, 0)) + .endTime(LocalTime.of(23, 59)) + .winnerCount(100) + .prizeImageUrl("http://example.com/image.jpg") + .prizeDescription("This is a detailed description of the prize.") + .options(options) + .build(); + + rushEvent = new RushEvent( + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getStartTime()), + LocalDateTime.of(rushEventRequestDto.getEventDate(), rushEventRequestDto.getEndTime()), + rushEventRequestDto.getWinnerCount(), + "http://example.com/image.jpg", + rushEventRequestDto.getPrizeDescription() + ); + + given(rushEventRepository.findById(1L)).willReturn(Optional.ofNullable(rushEvent)); + + //when + CustomException customException = assertThrows(CustomException.class, + () -> adminService.deleteRushEvent(1L) + ); + + //then + assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_DELETE, customException.getErrorCode()); + assertEquals("진행중인 이벤트를 삭제할 수 없습니다.", customException.getMessage()); + + + } } From fd41aeba241170593dc97c1020a9c5073dff2ed6 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:51:32 +0900 Subject: [PATCH 47/55] =?UTF-8?q?test=20:=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=84=A0=ED=83=9D=EC=A7=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 262bd89a..4ce79b4f 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -475,6 +475,7 @@ public ResponseDto deleteRushEvent(Long rushEventId) { return ResponseDto.of("요청에 성공하였습니다."); } + // 선착순 이벤트 선택지 조회 public AdminRushEventOptionResponseDto getRushEventOptions(Long rushEventId) { return AdminRushEventOptionResponseDto.of( rushEventRepository.findById(rushEventId).orElseThrow( diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index b0fb034c..dd2f918f 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1449,7 +1449,44 @@ void deleteRushEventTest_Failure_EventInProgress() { //then assertEquals(CustomErrorCode.EVENT_IN_PROGRESS_CANNOT_DELETE, customException.getErrorCode()); assertEquals("진행중인 이벤트를 삭제할 수 없습니다.", customException.getMessage()); + } + @Test + @DisplayName("선착순 이벤트 선택지 조회 테스트 - 성공") + void getRushEventOptionsTest_Success() { + //given + rushEvent.addOption(leftOption, rightOption); + given(rushEventRepository.findById(1L)).willReturn(Optional.ofNullable(rushEvent)); + + //when + AdminRushEventOptionResponseDto rushEventOptions = adminService.getRushEventOptions(1L); + + //then + Set options = rushEventOptions.options(); + + boolean firstOptionFound = false; + boolean secondOptionFound = false; + + for (RushEventOptionResponseDto option : options) { + if (option.mainText().equals("Main Text 2") && + option.subText().equals("Sub Text 2") && + option.resultMainText().equals("Result Main Text 2") && + option.resultSubText().equals("Result Sub Text 2") && + option.imageUrl().equals("http://example.com/image.jpg") && + option.position().equals(Position.RIGHT)) { + firstOptionFound = true; + } else if (option.mainText().equals("Main Text 1") && + option.subText().equals("Sub Text 1") && + option.resultMainText().equals("Result Main Text 1") && + option.resultSubText().equals("Result Sub Text 1") && + option.imageUrl().equals("http://example.com/image.jpg") && + option.position().equals(Position.LEFT)) { + secondOptionFound = true; + } + } + + assertThat(firstOptionFound).isTrue(); + assertThat(secondOptionFound).isTrue(); } } From 8d56cc1e5ce256e89012cc7e787aaf22fdf30fe1 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 22:53:16 +0900 Subject: [PATCH 48/55] =?UTF-8?q?test:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=20=EC=8B=9C=20=EC=84=A0?= =?UTF-8?q?=EC=B0=A9=EC=88=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminServiceTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index dd2f918f..53798eef 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1489,4 +1489,20 @@ void getRushEventOptionsTest_Success() { assertThat(secondOptionFound).isTrue(); } + + @Test + @DisplayName("선착순 이벤트 선택지 조회 테스트 - 실패 (이벤트 조회 실패)") + void getRushEventOptionsTest_Failure_NoRushEvent() { + //given + given(rushEventRepository.findById(1L)).willReturn(Optional.empty()); + + //when + CustomException customException = assertThrows(CustomException.class, + () -> adminService.getRushEventOptions(1L) + ); + + //then + assertEquals(CustomErrorCode.NO_RUSH_EVENT, customException.getErrorCode()); + assertEquals("선착순 이벤트를 찾을 수 없습니다.", customException.getMessage()); + } } From ff8e84620cbfe94f4df996fd6d51f8591514d1ab Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 23:01:29 +0900 Subject: [PATCH 49/55] =?UTF-8?q?test:=20=EA=B8=B0=EB=8C=80=ED=8F=89=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 87 ++++++++++++++----- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 4ce79b4f..3214b8d4 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -484,6 +484,7 @@ public AdminRushEventOptionResponseDto getRushEventOptions(Long rushEventId) { ); } + // 기대평 조회 public LotteryEventExpectationsResponseDto getLotteryEventExpectations(int page, int size, Long participantId) { LotteryParticipants lotteryParticipant = lotteryParticipantsRepository.findById(participantId).orElseThrow( () -> new CustomException(CustomErrorCode.USER_NOT_FOUND) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 53798eef..372c38a7 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1,16 +1,15 @@ package JGS.CasperEvent.domain.event.service.adminService; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.LotteryEventRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventOptionRequestDto; import JGS.CasperEvent.domain.event.dto.RequestDto.rushEventDto.RushEventRequestDto; import JGS.CasperEvent.domain.event.dto.ResponseDto.ImageUrlResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventDetailResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsListResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventParticipantsResponseDto; -import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.*; import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.*; import JGS.CasperEvent.domain.event.entity.admin.Admin; +import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.entity.event.RushEvent; import JGS.CasperEvent.domain.event.entity.event.RushOption; @@ -90,12 +89,13 @@ class AdminServiceTest { private LotteryEvent lotteryEvent; private LotteryEventRequestDto lotteryEventRequestDto; private LotteryParticipants lotteryParticipants; + private CasperBotRequestDto casperBotRequestDto; + private CasperBot casperBot; private RushEventRequestDto rushEventRequestDto; private RushEventOptionRequestDto leftOptionRequestDto; private RushEventOptionRequestDto rightOptionRequestDto; - private RushParticipants rushParticipant1; - private RushParticipants rushParticipant2; + private RushParticipants rushParticipant; @InjectMocks AdminService adminService; @@ -201,13 +201,25 @@ void setUp() { ); // 선착순 이벤트 참여자 - rushParticipant1 = new RushParticipants(user1, rushEvent, 1); - rushParticipant1.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - rushParticipant1.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + rushParticipant = new RushParticipants(user1, rushEvent, 1); + rushParticipant.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + rushParticipant.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + + // 캐스퍼 봇 생성 + casperBotRequestDto = CasperBotRequestDto.builder() + .eyeShape(0) + .eyePosition(0) + .mouthShape(0) + .color(0) + .sticker(0) + .name("name") + .expectation("expectation") + .referralId("QEszP1K8IqcapUHAVwikXA==").build(); + + casperBot = new CasperBot(casperBotRequestDto, "010-0000-0000"); + casperBot.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + casperBot.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - rushParticipant2 = new RushParticipants(user1, rushEvent, 2); - rushParticipant2.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - rushParticipant2.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); } @Test @@ -557,7 +569,7 @@ void getRushEventsTest_Success() { void getRushEventParticipantsTest_Success_withPhoneNumberAndOptionId() { //given List rushParticipantsList = new ArrayList<>(); - rushParticipantsList.add(rushParticipant1); + rushParticipantsList.add(rushParticipant); Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); given(rushParticipantsRepository.findByRushEvent_RushEventIdAndOptionIdAndBaseUser_Id(eq(1L), eq(1), eq("010-0000-0000"), any(Pageable.class))) @@ -589,7 +601,7 @@ void getRushEventParticipantsTest_Success_withPhoneNumberAndOptionId() { void getRushEventParticipantsTest_Success_withoutPhoneNumberAndOptionId() { //given List rushParticipantsList = new ArrayList<>(); - rushParticipantsList.add(rushParticipant1); + rushParticipantsList.add(rushParticipant); Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); given(rushParticipantsRepository.findByRushEvent_RushEventId(eq(1L), any(Pageable.class))) @@ -620,7 +632,7 @@ void getRushEventParticipantsTest_Success_withoutPhoneNumberAndOptionId() { void getRushEventParticipantsTest_Success_withoutPhoneNumberWithOptionId() { //given List rushParticipantsList = new ArrayList<>(); - rushParticipantsList.add(rushParticipant1); + rushParticipantsList.add(rushParticipant); Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); given(rushParticipantsRepository.findByRushEvent_RushEventIdAndOptionId(eq(1L), eq(1), any(Pageable.class))) @@ -651,7 +663,7 @@ void getRushEventParticipantsTest_Success_withoutPhoneNumberWithOptionId() { void getRushEventParticipantsTest_Success_witPhoneNumberAndWithoutOptionId() { //given List rushParticipantsList = new ArrayList<>(); - rushParticipantsList.add(rushParticipant1); + rushParticipantsList.add(rushParticipant); Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); given(rushParticipantsRepository.findByRushEvent_RushEventIdAndBaseUser_Id(eq(1L), eq("010-0000-0000"), any(Pageable.class))) @@ -682,7 +694,7 @@ void getRushEventParticipantsTest_Success_witPhoneNumberAndWithoutOptionId() { void getRushEventWinnersTest_Success_withPhoneNumberAndOptionId() { //given List rushParticipantsList = new ArrayList<>(); - rushParticipantsList.add(rushParticipant1); + rushParticipantsList.add(rushParticipant); Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); @@ -717,7 +729,7 @@ void getRushEventWinnersTest_Success_withPhoneNumberAndOptionId() { void getRushEventWinnersTest_Success_withoutPhoneNumberAndOptionId() { //given List rushParticipantsList = new ArrayList<>(); - rushParticipantsList.add(rushParticipant1); + rushParticipantsList.add(rushParticipant); Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); @@ -752,7 +764,7 @@ void getRushEventWinnersTest_Success_withoutPhoneNumberAndOptionId() { void getRushEventWinnersTest_Success_withoutPhoneNumberAndWithOptionId() { //given List rushParticipantsList = new ArrayList<>(); - rushParticipantsList.add(rushParticipant1); + rushParticipantsList.add(rushParticipant); Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); @@ -787,7 +799,7 @@ void getRushEventWinnersTest_Success_withoutPhoneNumberAndWithOptionId() { void getRushEventWinnersTest_Success_withPhoneNumberAndWithoutOptionId() { //given List rushParticipantsList = new ArrayList<>(); - rushParticipantsList.add(rushParticipant1); + rushParticipantsList.add(rushParticipant); Page rushParticipantsPage = new PageImpl<>(rushParticipantsList); given(rushEventRepository.findById(1L)).willReturn(Optional.of(rushEvent)); @@ -1505,4 +1517,39 @@ void getRushEventOptionsTest_Failure_NoRushEvent() { assertEquals(CustomErrorCode.NO_RUSH_EVENT, customException.getErrorCode()); assertEquals("선착순 이벤트를 찾을 수 없습니다.", customException.getMessage()); } + + @Test + @DisplayName("기대평 조회 테스트 - 성공") + void getLotteryEventExpectationsTest_Success() { + //given + given(lotteryParticipantsRepository.findById(1L)).willReturn(Optional.ofNullable(lotteryParticipants)); + + List casperBotList = new ArrayList<>(); + casperBotList.add(casperBot); + Page casperBotPage = new PageImpl<>(casperBotList); + + given(casperBotRepository.findByPhoneNumberAndActiveExpectations(eq("010-0000-0000"), any(Pageable.class))) + .willReturn(casperBotPage); + + //when + LotteryEventExpectationsResponseDto lotteryEventExpectations = adminService.getLotteryEventExpectations(0, 1, 1L); + + //then + List expectations = lotteryEventExpectations.expectations(); + + boolean expectationFound = false; + + for (LotteryEventExpectationResponseDto exp : expectations) { + if (exp.expectation().equals("expectation") && + exp.createdDate().equals(LocalDate.of(2000, 9, 27)) && + exp.createdTime().equals(LocalTime.of(0, 0))) { + expectationFound = true; + break; + } + } + + assertThat(expectationFound).isTrue(); + assertThat(lotteryEventExpectations.isLastPage()).isTrue(); + assertThat(lotteryEventExpectations.totalExpectations()).isEqualTo(1); + } } From 3bc763e548eabd7c74eab41abb28ff4be0e03484 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 23:03:50 +0900 Subject: [PATCH 50/55] =?UTF-8?q?test:=20=EC=9C=A0=EC=A0=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=20=EC=8B=9C=20=EA=B8=B0=EB=8C=80?= =?UTF-8?q?=ED=8F=89=20=EC=A1=B0=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminServiceTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 372c38a7..7e0c2c0d 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -1552,4 +1552,21 @@ void getLotteryEventExpectationsTest_Success() { assertThat(lotteryEventExpectations.isLastPage()).isTrue(); assertThat(lotteryEventExpectations.totalExpectations()).isEqualTo(1); } + + @Test + @DisplayName("기대평 조회 테스트 - 실패 (참여자 조회 실패)") + void getLotteryEventExpectationsTest_Failure_UserNotFound() { + //given + given(lotteryParticipantsRepository.findById(1L)) + .willReturn(Optional.empty()); + + //when + CustomException customException = assertThrows(CustomException.class, + () -> adminService.getLotteryEventExpectations(0, 1, 1L) + ); + + //then + assertEquals(CustomErrorCode.USER_NOT_FOUND, customException.getErrorCode()); + assertEquals("응모하지 않은 사용자입니다.", customException.getMessage()); + } } From fcf91da27c4c46fa01a47ebade59500406786e8b Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 23:17:57 +0900 Subject: [PATCH 51/55] =?UTF-8?q?test:=20=EA=B8=B0=EB=8C=80=ED=8F=89=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 1 + .../adminService/AdminServiceTest.java | 38 ++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 3214b8d4..8e36cbd4 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -511,6 +511,7 @@ public LotteryEventExpectationsResponseDto getLotteryEventExpectations(int page, return new LotteryEventExpectationsResponseDto(lotteryEventExpectationResponseDtoList, isLastPage, casperBotPage.getTotalElements()); } + // 부적절한 기대평 삭제 @Transactional public void deleteLotteryEventExpectation(Long casperId) { CasperBot casperBot = casperBotRepository.findById(casperId).orElseThrow( diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 7e0c2c0d..074fc4b3 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -42,6 +42,8 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.redis.core.ListOperations; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.mock.web.MockMultipartFile; import java.time.LocalDate; @@ -52,9 +54,9 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class AdminServiceTest { @@ -77,6 +79,11 @@ class AdminServiceTest { private CasperBotRepository casperBotRepository; @Mock private LotteryWinnerRepository lotteryWinnerRepository; + @Mock + private RedisTemplate casperBotRedisTemplate; + @Mock + private ListOperations listOperations; + private RushEvent rushEvent; private RushOption leftOption; @@ -216,10 +223,10 @@ void setUp() { .expectation("expectation") .referralId("QEszP1K8IqcapUHAVwikXA==").build(); - casperBot = new CasperBot(casperBotRequestDto, "010-0000-0000"); - casperBot.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - casperBot.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - + casperBot = spy(new CasperBot(casperBotRequestDto, "010-0000-0000")); + lenient().when(casperBot.getCasperId()).thenReturn(1L); + lenient().when(casperBot.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(casperBot.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); } @Test @@ -1569,4 +1576,23 @@ void getLotteryEventExpectationsTest_Failure_UserNotFound() { assertEquals(CustomErrorCode.USER_NOT_FOUND, customException.getErrorCode()); assertEquals("응모하지 않은 사용자입니다.", customException.getMessage()); } + + @Test + @DisplayName("부적절한 기대평 삭제 테스트 - 성공") + void deleteLotteryEventExpectationTest_Success() { + //given + List casperBotResponseDtoList = new ArrayList<>(); + casperBotResponseDtoList.add(CasperBotResponseDto.of(casperBot)); + + given(casperBotRepository.findById(1L)).willReturn(Optional.ofNullable(casperBot)); + given(casperBotRedisTemplate.opsForList()).willReturn(listOperations); + given(casperBotRedisTemplate.opsForList().range(anyString(), eq(0L), eq(-1L))) + .willReturn(casperBotResponseDtoList); + + //when + adminService.deleteLotteryEventExpectation(1L); + + //then + + } } From f933c59de935b64d847b95662942225c5a13f0a6 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 23:21:39 +0900 Subject: [PATCH 52/55] =?UTF-8?q?chore:=20Setter=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=ED=9B=84=20Spy=20=EA=B0=9D=EC=B2=B4=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminService/AdminServiceTest.java | 89 ++++++++++++------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java index 074fc4b3..56572143 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/service/adminService/AdminServiceTest.java @@ -87,12 +87,10 @@ class AdminServiceTest { private RushEvent rushEvent; private RushOption leftOption; - @Mock private RushOption rightOption; private Admin admin; - private BaseUser user1; - private BaseUser user2; + private BaseUser user; private LotteryEvent lotteryEvent; private LotteryEventRequestDto lotteryEventRequestDto; private LotteryParticipants lotteryParticipants; @@ -113,14 +111,9 @@ void setUp() { admin = new Admin("adminId", "password", Role.ADMIN); // 유저 객체 - user1 = new BaseUser("010-0000-0000", Role.USER); - user1.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - user1.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - - user2 = new BaseUser("010-9999-9999", Role.USER); - user2.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - user2.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - + user = spy(new BaseUser("010-0000-0000", Role.USER)); + lenient().when(user.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(user.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); // 추첨 이벤트 생성 요청 DTO lotteryEventRequestDto = LotteryEventRequestDto.builder() .startDate(LocalDate.of(2000, 9, 27)) @@ -138,9 +131,9 @@ void setUp() { ); // 추첨 이벤트 참여자 엔티티 - lotteryParticipants = new LotteryParticipants(user1); - lotteryParticipants.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - lotteryParticipants.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lotteryParticipants = spy(new LotteryParticipants(user)); + lenient().when(lotteryParticipants.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(lotteryParticipants.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); // 선착순 이벤트 옵션 요청 DTO leftOptionRequestDto = RushEventOptionRequestDto.builder() @@ -208,25 +201,61 @@ void setUp() { ); // 선착순 이벤트 참여자 - rushParticipant = new RushParticipants(user1, rushEvent, 1); - rushParticipant.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - rushParticipant.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + rushParticipant = spy(new RushParticipants(user, rushEvent, 1)); + lenient().when(rushParticipant.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(rushParticipant.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + // 캐스퍼 봇 생성 casperBotRequestDto = CasperBotRequestDto.builder() - .eyeShape(0) - .eyePosition(0) - .mouthShape(0) - .color(0) - .sticker(0) - .name("name") - .expectation("expectation") - .referralId("QEszP1K8IqcapUHAVwikXA==").build(); - - casperBot = spy(new CasperBot(casperBotRequestDto, "010-0000-0000")); - lenient().when(casperBot.getCasperId()).thenReturn(1L); - lenient().when(casperBot.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - lenient().when(casperBot.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + . + + eyeShape(0) + . + + eyePosition(0) + . + + mouthShape(0) + . + + color(0) + . + + sticker(0) + . + + name("name") + . + + expectation("expectation") + . + + referralId("QEszP1K8IqcapUHAVwikXA=="). + + build(); + + casperBot = + + spy(new CasperBot(casperBotRequestDto, "010-0000-0000")); + + lenient(). + + when(casperBot.getCasperId()). + + thenReturn(1L); + + lenient(). + + when(casperBot.getCreatedAt()). + + thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + + lenient(). + + when(casperBot.getUpdatedAt()). + + thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); } @Test From 956d94cd058fb0af82a3cde7629d82182f5263d2 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 23:36:54 +0900 Subject: [PATCH 53/55] =?UTF-8?q?chore:=20BaseEntity=EC=9D=98=20Setter=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java index eabf111b..6a41fb05 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java +++ b/Server/src/main/java/JGS/CasperEvent/global/entity/BaseEntity.java @@ -8,7 +8,6 @@ import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; import lombok.Getter; -import lombok.Setter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -19,7 +18,6 @@ @EntityListeners(AuditingEntityListener.class) @MappedSuperclass @Getter -@Setter public class BaseEntity { @CreatedDate @JsonSerialize(using = LocalDateTimeSerializer.class) From a432639b34eaca36f0aaba8dc7bb94715868cb6f Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 23:37:18 +0900 Subject: [PATCH 54/55] =?UTF-8?q?chore:=20Setter=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C=ED=95=98=EA=B3=A0=20spy=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EB=AA=A8=ED=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminController/AdminControllerTest.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/adminController/AdminControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/adminController/AdminControllerTest.java index bcb27b8e..c9fbb6ef 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/adminController/AdminControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/adminController/AdminControllerTest.java @@ -46,8 +46,8 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.*; +import static org.mockito.Mockito.lenient; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -109,9 +109,9 @@ void setUp() throws Exception { admin = new Admin(adminId, password, Role.ADMIN); given(adminService.verifyAdmin(any())).willReturn(admin); - user = new BaseUser("010-0000-0000", Role.USER); - user.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - user.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + user = spy(new BaseUser("010-0000-0000", Role.USER)); + lenient().when(user.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(user.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); given(userService.verifyUser(any())).willReturn(user); // 엑세스 토큰 설정 this.accessToken = getToken(adminId, password); @@ -159,9 +159,9 @@ void setUp() throws Exception { .expectation("expectation") .referralId("QEszP1K8IqcapUHAVwikXA==").build(); - casperBot = new CasperBot(casperBotRequestDto, "010-0000-0000"); - casperBot.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - casperBot.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + casperBot = spy(new CasperBot(casperBotRequestDto, "010-0000-0000")); + lenient().when(casperBot.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(casperBot.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); // 추첨 이벤트 당첨자 엔티티 lotteryWinners = spy(new LotteryWinners(lotteryParticipants)); @@ -258,9 +258,9 @@ void setUp() throws Exception { adminRushEventResponseDto = AdminRushEventResponseDto.of(rushEvent); // 선착순 이벤트 참여자 엔티티 - rushParticipants = new RushParticipants(user, rushEvent, 1); - rushParticipants.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - rushParticipants.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + rushParticipants = spy(new RushParticipants(user, rushEvent, 1)); + lenient().when(rushParticipants.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(rushParticipants.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); // 선착순 이벤트 참여자 응답 DTO rushEventParticipantResponseDto = RushEventParticipantResponseDto.of(rushParticipants, 1L); @@ -397,20 +397,21 @@ void createRushEventSuccessTest() throws Exception { .andExpect(jsonPath("$.prizeImageUrl").value("prize image url")) .andExpect(jsonPath("$.prizeDescription").value("prize description")) .andExpect(jsonPath("$.status").value("AFTER")) - .andExpect(jsonPath("$.options[0].optionId").value(2)) - .andExpect(jsonPath("$.options[0].mainText").value("main text 2")) - .andExpect(jsonPath("$.options[0].subText").value("sub text 2")) - .andExpect(jsonPath("$.options[0].resultMainText").value("result main text 2")) - .andExpect(jsonPath("$.options[0].resultSubText").value("result sub text 2")) - .andExpect(jsonPath("$.options[0].imageUrl").value("image url 2")) - .andExpect(jsonPath("$.options[0].position").value("RIGHT")) - .andExpect(jsonPath("$.options[1].optionId").value(1)) - .andExpect(jsonPath("$.options[1].mainText").value("main text 1")) - .andExpect(jsonPath("$.options[1].subText").value("sub text 1")) - .andExpect(jsonPath("$.options[1].resultMainText").value("result main text 1")) - .andExpect(jsonPath("$.options[1].resultSubText").value("result sub text 1")) - .andExpect(jsonPath("$.options[1].imageUrl").value("image url 1")) - .andExpect(jsonPath("$.options[1].position").value("LEFT")) + .andExpect(jsonPath("$.options[0].optionId").value(1)) + .andExpect(jsonPath("$.options[0].mainText").value("main text 1")) + .andExpect(jsonPath("$.options[0].subText").value("sub text 1")) + .andExpect(jsonPath("$.options[0].resultMainText").value("result main text 1")) + .andExpect(jsonPath("$.options[0].resultSubText").value("result sub text 1")) + .andExpect(jsonPath("$.options[0].imageUrl").value("image url 1")) + .andExpect(jsonPath("$.options[0].position").value("LEFT")) + .andExpect(jsonPath("$.options[1].optionId").value(2)) + .andExpect(jsonPath("$.options[1].mainText").value("main text 2")) + .andExpect(jsonPath("$.options[1].subText").value("sub text 2")) + .andExpect(jsonPath("$.options[1].resultMainText").value("result main text 2")) + .andExpect(jsonPath("$.options[1].resultSubText").value("result sub text 2")) + .andExpect(jsonPath("$.options[1].imageUrl").value("image url 2")) + .andExpect(jsonPath("$.options[1].position").value("RIGHT")) + .andDo(print()); } From 6a11f717699cd852a07bfbc7eb4bab1bf0f338e7 Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Sun, 18 Aug 2024 23:37:18 +0900 Subject: [PATCH 55/55] =?UTF-8?q?chore:=20Setter=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C=ED=95=98=EA=B3=A0=20spy=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EB=AA=A8=ED=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminService/AdminService.java | 2 - .../adminController/AdminControllerTest.java | 51 ++++++++++--------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index 8e36cbd4..d3a27033 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -27,8 +27,6 @@ import JGS.CasperEvent.global.enums.Position; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; -import JGS.CasperEvent.global.error.exception.TooManyLotteryEventException; -import JGS.CasperEvent.global.error.exception.TooManyRushEventException; import JGS.CasperEvent.global.response.ResponseDto; import JGS.CasperEvent.global.service.S3Service; import lombok.RequiredArgsConstructor; diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/adminController/AdminControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/adminController/AdminControllerTest.java index bcb27b8e..c9fbb6ef 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/adminController/AdminControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/adminController/AdminControllerTest.java @@ -46,8 +46,8 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.*; +import static org.mockito.Mockito.lenient; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -109,9 +109,9 @@ void setUp() throws Exception { admin = new Admin(adminId, password, Role.ADMIN); given(adminService.verifyAdmin(any())).willReturn(admin); - user = new BaseUser("010-0000-0000", Role.USER); - user.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - user.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + user = spy(new BaseUser("010-0000-0000", Role.USER)); + lenient().when(user.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(user.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); given(userService.verifyUser(any())).willReturn(user); // 엑세스 토큰 설정 this.accessToken = getToken(adminId, password); @@ -159,9 +159,9 @@ void setUp() throws Exception { .expectation("expectation") .referralId("QEszP1K8IqcapUHAVwikXA==").build(); - casperBot = new CasperBot(casperBotRequestDto, "010-0000-0000"); - casperBot.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - casperBot.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + casperBot = spy(new CasperBot(casperBotRequestDto, "010-0000-0000")); + lenient().when(casperBot.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(casperBot.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); // 추첨 이벤트 당첨자 엔티티 lotteryWinners = spy(new LotteryWinners(lotteryParticipants)); @@ -258,9 +258,9 @@ void setUp() throws Exception { adminRushEventResponseDto = AdminRushEventResponseDto.of(rushEvent); // 선착순 이벤트 참여자 엔티티 - rushParticipants = new RushParticipants(user, rushEvent, 1); - rushParticipants.setCreatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); - rushParticipants.setUpdatedAt(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + rushParticipants = spy(new RushParticipants(user, rushEvent, 1)); + lenient().when(rushParticipants.getCreatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); + lenient().when(rushParticipants.getUpdatedAt()).thenReturn(LocalDateTime.of(2000, 9, 27, 0, 0, 0)); // 선착순 이벤트 참여자 응답 DTO rushEventParticipantResponseDto = RushEventParticipantResponseDto.of(rushParticipants, 1L); @@ -397,20 +397,21 @@ void createRushEventSuccessTest() throws Exception { .andExpect(jsonPath("$.prizeImageUrl").value("prize image url")) .andExpect(jsonPath("$.prizeDescription").value("prize description")) .andExpect(jsonPath("$.status").value("AFTER")) - .andExpect(jsonPath("$.options[0].optionId").value(2)) - .andExpect(jsonPath("$.options[0].mainText").value("main text 2")) - .andExpect(jsonPath("$.options[0].subText").value("sub text 2")) - .andExpect(jsonPath("$.options[0].resultMainText").value("result main text 2")) - .andExpect(jsonPath("$.options[0].resultSubText").value("result sub text 2")) - .andExpect(jsonPath("$.options[0].imageUrl").value("image url 2")) - .andExpect(jsonPath("$.options[0].position").value("RIGHT")) - .andExpect(jsonPath("$.options[1].optionId").value(1)) - .andExpect(jsonPath("$.options[1].mainText").value("main text 1")) - .andExpect(jsonPath("$.options[1].subText").value("sub text 1")) - .andExpect(jsonPath("$.options[1].resultMainText").value("result main text 1")) - .andExpect(jsonPath("$.options[1].resultSubText").value("result sub text 1")) - .andExpect(jsonPath("$.options[1].imageUrl").value("image url 1")) - .andExpect(jsonPath("$.options[1].position").value("LEFT")) + .andExpect(jsonPath("$.options[0].optionId").value(1)) + .andExpect(jsonPath("$.options[0].mainText").value("main text 1")) + .andExpect(jsonPath("$.options[0].subText").value("sub text 1")) + .andExpect(jsonPath("$.options[0].resultMainText").value("result main text 1")) + .andExpect(jsonPath("$.options[0].resultSubText").value("result sub text 1")) + .andExpect(jsonPath("$.options[0].imageUrl").value("image url 1")) + .andExpect(jsonPath("$.options[0].position").value("LEFT")) + .andExpect(jsonPath("$.options[1].optionId").value(2)) + .andExpect(jsonPath("$.options[1].mainText").value("main text 2")) + .andExpect(jsonPath("$.options[1].subText").value("sub text 2")) + .andExpect(jsonPath("$.options[1].resultMainText").value("result main text 2")) + .andExpect(jsonPath("$.options[1].resultSubText").value("result sub text 2")) + .andExpect(jsonPath("$.options[1].imageUrl").value("image url 2")) + .andExpect(jsonPath("$.options[1].position").value("RIGHT")) + .andDo(print()); }