From 8a7036e5b967ca681bfbc17b4d2fe570f0e183e4 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 26 Mar 2024 23:43:57 +0900 Subject: [PATCH 01/48] =?UTF-8?q?refactor:=20Collectors.toList()=EB=A5=BC?= =?UTF-8?q?=20Stream.toList()=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/app/application/mission/MissionService.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/sopt/app/application/mission/MissionService.java b/src/main/java/org/sopt/app/application/mission/MissionService.java index 4651dc6b..ddb0f97a 100644 --- a/src/main/java/org/sopt/app/application/mission/MissionService.java +++ b/src/main/java/org/sopt/app/application/mission/MissionService.java @@ -3,7 +3,6 @@ import java.util.Comparator; import java.util.List; import java.util.function.Predicate; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.val; import org.sopt.app.domain.entity.Mission; @@ -36,7 +35,7 @@ public List findAllMission(Long userId) { .build()) .sorted(Comparator.comparing(MissionInfo.Completeness::getLevel) .thenComparing(MissionInfo.Completeness::getTitle)) - .collect(Collectors.toList()); + .toList(); } private Boolean isCompletedMission(Long missionId, List completedStamps) { @@ -60,7 +59,7 @@ public Mission uploadMission(MissionRequest.RegisterMissionRequest registerMissi @Transactional(readOnly = true) public List getCompleteMission(Long userId) { val stampList = stampRepository.findAllByUserId(userId); - val missionIdList = stampList.stream().map(Stamp::getMissionId).collect(Collectors.toList()); + val missionIdList = stampList.stream().map(Stamp::getMissionId).toList(); return missionRepository.findMissionInOrderByLevelAndTitle(missionIdList); } @@ -69,11 +68,11 @@ public List getIncompleteMission(Long userId) { //전체 미션 조회하기 val missionList = missionRepository.findAllByDisplay(true); - val missionIdList = missionList.stream().map(Mission::getId).collect(Collectors.toList()); + val missionIdList = missionList.stream().map(Mission::getId).toList(); //stamp에서 userId로 달성한 mission 조회하기 val stampList = stampRepository.findAllByUserId(userId); - val completeMissionIdList = stampList.stream().map(Stamp::getMissionId).collect(Collectors.toList()); + val completeMissionIdList = stampList.stream().map(Stamp::getMissionId).toList(); //두 리스트 비교해서 중복값 제거 val inCompleteIdList = missionIdList.stream() From 4bdd44dfd3cb584211a1f9faadd2823baf301b6b Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 3 Apr 2024 15:02:20 +0900 Subject: [PATCH 02/48] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/app/application/soptamp/SoptampPointService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java b/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java index 3eab6fd7..fec5676e 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java @@ -1,6 +1,5 @@ package org.sopt.app.application.soptamp; -import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; From b01bbbafd93782edf448bc772cb7a7b3b22f4d32 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 3 Apr 2024 16:52:53 +0900 Subject: [PATCH 03/48] =?UTF-8?q?feat:=20=ED=98=84=EC=9E=AC=20=ED=8F=AC?= =?UTF-8?q?=EC=9D=B8=ED=8A=B8=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=20=EC=84=B1=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/SoptampPointServiceTest.java | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/test/java/org/sopt/app/application/SoptampPointServiceTest.java diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java new file mode 100644 index 00000000..12c74e1d --- /dev/null +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -0,0 +1,106 @@ +package org.sopt.app.application; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.when; + +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.junit.jupiter.api.Test; +import org.mockito.junit.jupiter.MockitoExtension; +import org.sopt.app.application.soptamp.SoptampPointInfo.Point; +import org.sopt.app.application.soptamp.SoptampPointService; +import org.sopt.app.domain.entity.SoptampPoint; +import org.sopt.app.interfaces.postgres.SoptampPointRepository; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.util.ReflectionTestUtils; + +@ExtendWith(MockitoExtension.class) +class SoptampPointServiceTest { + + @Mock + private SoptampPointRepository soptampPointRepository; + + @InjectMocks + private SoptampPointService soptampPointService; + + @BeforeEach + void setUp() { + ReflectionTestUtils.setField(soptampPointService, "currentGeneration", 34L); + } + + @Test + @DisplayName("SUCCESS_현재 포인트 리스트 찾기") + void SUCCESS_findCurrentPointList() { + //given + final Long anyGeneration = anyLong(); + + List soptampPointList = List.of( + SoptampPoint.builder() + .id(1L) + .generation(anyGeneration) + .soptampUserId(1L) + .points(100L) + .build(), + SoptampPoint.builder() + .id(2L) + .generation(anyGeneration) + .soptampUserId(2L) + .points(200L) + .build() + ); + //when + when(soptampPointRepository.findAllByGeneration(anyGeneration)).thenReturn(soptampPointList); + + List result = soptampPointService.findCurrentPointList(); + List expected = List.of( + Point.builder() + .id(1L) + .generation(anyGeneration) + .soptampUserId(1L) + .points(100L) + .build(), + Point.builder() + .id(2L) + .generation(anyGeneration) + .soptampUserId(2L) + .points(200L) + .build() + + ); + //then + + assertThat(result).usingRecursiveComparison().isEqualTo(expected); + } + + /* TODO: Implement test cases for the following methods + @Test + void findCurrentPointListBySoptampUserIds() { + } + + @Test + void addPoint() { + } + + @Test + void subtractPoint() { + } + + @Test + void upsertSoptampPoint() { + } + + @Test + void findPartRanks() { + } + + @Test + void calculateSumOfPoints() { + } + + */ +} \ No newline at end of file From 575f27319a318014107022ce60e9032341614cf5 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Apr 2024 16:10:27 +0900 Subject: [PATCH 04/48] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A1=9C=20?= =?UTF-8?q?=ED=98=84=EC=9E=AC=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B0=BE=EA=B8=B0=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/SoptampPointServiceTest.java | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index 12c74e1d..cdd194fd 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -1,6 +1,7 @@ package org.sopt.app.application; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; @@ -16,7 +17,6 @@ import org.sopt.app.application.soptamp.SoptampPointService; import org.sopt.app.domain.entity.SoptampPoint; import org.sopt.app.interfaces.postgres.SoptampPointRepository; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.util.ReflectionTestUtils; @ExtendWith(MockitoExtension.class) @@ -53,6 +53,7 @@ void SUCCESS_findCurrentPointList() { .points(200L) .build() ); + //when when(soptampPointRepository.findAllByGeneration(anyGeneration)).thenReturn(soptampPointList); @@ -72,16 +73,56 @@ void SUCCESS_findCurrentPointList() { .build() ); - //then + //then assertThat(result).usingRecursiveComparison().isEqualTo(expected); } - /* TODO: Implement test cases for the following methods + @Test - void findCurrentPointListBySoptampUserIds() { + @DisplayName("SUCCESS_유저 아이디 리스트로 현재 포인트 리스트 찾기") + void SUCCESS_findCurrentPointListBySoptampUserIds() { + //given + List soptampUserIdList = any(); + Long anyGeneration = anyLong(); + List soptampPointList = List.of( + SoptampPoint.builder() + .id(1L) + .generation(anyGeneration) + .soptampUserId(1L) + .points(100L) + .build(), + SoptampPoint.builder() + .id(2L) + .generation(anyGeneration) + .soptampUserId(2L) + .points(200L) + .build() + ); + + //when + when(soptampPointRepository.findAllBySoptampUserIdInAndGeneration(soptampUserIdList, anyGeneration)).thenReturn(soptampPointList); + List result = soptampPointService.findCurrentPointListBySoptampUserIds(soptampUserIdList); + List expected = List.of( + Point.builder() + .id(1L) + .generation(anyGeneration) + .soptampUserId(1L) + .points(100L) + .build(), + Point.builder() + .id(2L) + .generation(anyGeneration) + .soptampUserId(2L) + .points(200L) + .build() + ); + + //then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); } + /* TODO: Implement test cases for the following methods @Test void addPoint() { } From 8fc32142bfff66ef4a27ef2d4d400801623118a6 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Apr 2024 18:12:14 +0900 Subject: [PATCH 05/48] =?UTF-8?q?feat:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EC=84=B1=EA=B3=B5=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/SoptampPointServiceTest.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index cdd194fd..21bef526 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -2,10 +2,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.extension.ExtendWith; @@ -83,7 +86,6 @@ void SUCCESS_findCurrentPointList() { @DisplayName("SUCCESS_유저 아이디 리스트로 현재 포인트 리스트 찾기") void SUCCESS_findCurrentPointListBySoptampUserIds() { //given - List soptampUserIdList = any(); Long anyGeneration = anyLong(); List soptampPointList = List.of( SoptampPoint.builder() @@ -101,8 +103,8 @@ void SUCCESS_findCurrentPointListBySoptampUserIds() { ); //when - when(soptampPointRepository.findAllBySoptampUserIdInAndGeneration(soptampUserIdList, anyGeneration)).thenReturn(soptampPointList); - List result = soptampPointService.findCurrentPointListBySoptampUserIds(soptampUserIdList); + when(soptampPointRepository.findAllBySoptampUserIdInAndGeneration(any(), anyGeneration)).thenReturn(soptampPointList); + List result = soptampPointService.findCurrentPointListBySoptampUserIds(any()); List expected = List.of( Point.builder() .id(1L) @@ -122,11 +124,34 @@ void SUCCESS_findCurrentPointListBySoptampUserIds() { assertThat(result).usingRecursiveComparison().isEqualTo(expected); } - /* TODO: Implement test cases for the following methods @Test - void addPoint() { + @DisplayName("SUCCESS_솝탬프 포인트가 없을 때 포인트 추가") + void SUCCESS_addPointSoptampNotPresent() { + //given + SoptampPoint soptampPoint = SoptampPoint.builder() + .id(1L) + .generation(34L) + .soptampUserId(1L) + .points(100L) + .build(); + + //when + when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.of(soptampPoint)); + + //then + Assertions.assertDoesNotThrow(() -> soptampPointService.addPoint(anyLong(), anyInt())); } + @Test + @DisplayName("SUCCESS_솝탬프 포인트가 없으면 아무것도 안함") + void SUCCESS_addPoint() { + //when + when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.empty()); + //then + Assertions.assertDoesNotThrow(() -> soptampPointService.addPoint(anyLong(), anyInt())); + } + + /* TODO: Implement test cases for the following methods @Test void subtractPoint() { } From f5e334c77e03828ee7d735bdb45438d2db74a559 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Apr 2024 18:15:30 +0900 Subject: [PATCH 06/48] =?UTF-8?q?refactor:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8?= =?UTF-8?q?=20=EB=B9=BC=EA=B8=B0=20=EB=A1=9C=EC=A7=81=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80=20=EB=A1=9C=EC=A7=81=EA=B3=BC=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../soptamp/SoptampPointService.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java b/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java index fec5676e..33973bef 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java @@ -68,17 +68,16 @@ public void addPoint(Long soptampUserId, Integer level) { @Transactional public void subtractPoint(Long soptampUserId, Integer level) { val soptampPoint = soptampPointRepository.findAllBySoptampUserIdAndGeneration(soptampUserId, currentGeneration); - if(soptampPoint.isEmpty()){ - return; + if(soptampPoint.isPresent()){ + val soptampPointEntity = soptampPoint.get(); + val newSoptampPoint = SoptampPoint.builder() + .id(soptampPointEntity.getId()) + .generation(soptampPointEntity.getGeneration()) + .soptampUserId(soptampPointEntity.getSoptampUserId()) + .points(soptampPointEntity.getPoints() - level) + .build(); + soptampPointRepository.save(newSoptampPoint); } - val soptampPointEntity = soptampPoint.get(); - val newSoptampPoint = SoptampPoint.builder() - .id(soptampPointEntity.getId()) - .generation(soptampPointEntity.getGeneration()) - .soptampUserId(soptampPointEntity.getSoptampUserId()) - .points(soptampPointEntity.getPoints() - level) - .build(); - soptampPointRepository.save(newSoptampPoint); } @Transactional From 40d97a9cfac6b4962a4abf3735953df47c456a9e Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Apr 2024 18:19:05 +0900 Subject: [PATCH 07/48] =?UTF-8?q?feat:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EB=B9=BC=EA=B8=B0=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/SoptampPointServiceTest.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index 21bef526..78432e0f 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -125,8 +125,8 @@ void SUCCESS_findCurrentPointListBySoptampUserIds() { } @Test - @DisplayName("SUCCESS_솝탬프 포인트가 없을 때 포인트 추가") - void SUCCESS_addPointSoptampNotPresent() { + @DisplayName("SUCCESS_솝탬프 포인트가 있을 때 포인트 추가") + void SUCCESS_addPointSoptampIsPresent() { //given SoptampPoint soptampPoint = SoptampPoint.builder() .id(1L) @@ -144,18 +144,41 @@ void SUCCESS_addPointSoptampNotPresent() { @Test @DisplayName("SUCCESS_솝탬프 포인트가 없으면 아무것도 안함") - void SUCCESS_addPoint() { + void SUCCESS_addPointSoptampNotPresent() { //when when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.empty()); //then Assertions.assertDoesNotThrow(() -> soptampPointService.addPoint(anyLong(), anyInt())); } - /* TODO: Implement test cases for the following methods @Test - void subtractPoint() { + @DisplayName("SUCCESS_솝탬프 포인트가 있을 때 포인트 추가") + void SUCCESS_subtractPointIsPresent() { + //given + SoptampPoint soptampPoint = SoptampPoint.builder() + .id(1L) + .generation(34L) + .soptampUserId(1L) + .points(100L) + .build(); + + //when + when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.of(soptampPoint)); + + //then + Assertions.assertDoesNotThrow(() -> soptampPointService.subtractPoint(anyLong(), anyInt())); } + @Test + @DisplayName("SUCCESS_솝탬프 포인트가 없으면 아무것도 안함") + void SUCCESS_subtractPointSoptampNotPresent() { + //when + when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.empty()); + //then + Assertions.assertDoesNotThrow(() -> soptampPointService.subtractPoint(anyLong(), anyInt())); + } + + /* TODO: Implement test cases for the following methods @Test void upsertSoptampPoint() { } From f6859af0102a5c1db1da56b0218e818f9d5e658d Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Apr 2024 18:22:23 +0900 Subject: [PATCH 08/48] =?UTF-8?q?fix:=20=EC=9C=A0=EC=A0=80=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A1=9C=20?= =?UTF-8?q?=ED=98=84=EC=9E=AC=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B0=BE=EA=B8=B0=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/app/application/SoptampPointServiceTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index 78432e0f..404cf96d 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -86,6 +86,7 @@ void SUCCESS_findCurrentPointList() { @DisplayName("SUCCESS_유저 아이디 리스트로 현재 포인트 리스트 찾기") void SUCCESS_findCurrentPointListBySoptampUserIds() { //given + List soptampUserIdList = any(); Long anyGeneration = anyLong(); List soptampPointList = List.of( SoptampPoint.builder() @@ -103,8 +104,8 @@ void SUCCESS_findCurrentPointListBySoptampUserIds() { ); //when - when(soptampPointRepository.findAllBySoptampUserIdInAndGeneration(any(), anyGeneration)).thenReturn(soptampPointList); - List result = soptampPointService.findCurrentPointListBySoptampUserIds(any()); + when(soptampPointRepository.findAllBySoptampUserIdInAndGeneration(soptampUserIdList, anyGeneration)).thenReturn(soptampPointList); + List result = soptampPointService.findCurrentPointListBySoptampUserIds(soptampUserIdList); List expected = List.of( Point.builder() .id(1L) From 57aead855d475c98d662067686bbfd345f675ce9 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Apr 2024 21:36:42 +0900 Subject: [PATCH 09/48] =?UTF-8?q?feat:=20=EC=86=9D=ED=83=AC=ED=94=84=20?= =?UTF-8?q?=EC=97=85=EC=84=9C=ED=8A=B8=20=EC=84=B1=EA=B3=B5=20=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/SoptampPointServiceTest.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index 404cf96d..4f9dd39e 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -19,6 +19,7 @@ import org.sopt.app.application.soptamp.SoptampPointInfo.Point; import org.sopt.app.application.soptamp.SoptampPointService; import org.sopt.app.domain.entity.SoptampPoint; +import org.sopt.app.domain.enums.UserStatus; import org.sopt.app.interfaces.postgres.SoptampPointRepository; import org.springframework.test.util.ReflectionTestUtils; @@ -179,11 +180,38 @@ void SUCCESS_subtractPointSoptampNotPresent() { Assertions.assertDoesNotThrow(() -> soptampPointService.subtractPoint(anyLong(), anyInt())); } - /* TODO: Implement test cases for the following methods @Test - void upsertSoptampPoint() { + @DisplayName("SUCCESS_유저 상태가 ACTIVE일 때 솝탬프 포인트 업서트") + void SUCCESS_upsertSoptampPointUserStatusACTIVE() { + //given + Long anyUserId = anyLong(); + + //when + when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyUserId, anyLong())) + .thenReturn(Optional.of(new SoptampPoint())); + + //then + Assertions.assertDoesNotThrow(() -> soptampPointService.upsertSoptampPoint(UserStatus.ACTIVE, anyUserId)); + } + + @Test + @DisplayName("SUCCESS_유저 상태가 INACTIVE일 때 업서트하지 않음") + void SUCCESS_upsertSoptampPointUserStatusINACTIVE() { + //then + Assertions.assertDoesNotThrow(() -> soptampPointService.upsertSoptampPoint(UserStatus.INACTIVE, 1L)); + } + + @Test + @DisplayName("SUCCESS_솝탬프 포인트가 Empty일 때 업서트하지 않음") + void SUCCESS_upsertSoptampPointNotPresent() { + //when + when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())) + .thenReturn(Optional.empty()); + //then + Assertions.assertDoesNotThrow(() -> soptampPointService.upsertSoptampPoint(UserStatus.ACTIVE, 1L)); } + /* TODO: Implement test cases for the following methods @Test void findPartRanks() { } From 519a6dd5588473328d6c68027f1a5a9027fdc69c Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 15 Apr 2024 21:45:28 +0900 Subject: [PATCH 10/48] =?UTF-8?q?feat:=20findPartRanks=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/SoptampPointServiceTest.java | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index 4f9dd39e..68840e0d 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -7,6 +7,7 @@ import static org.mockito.Mockito.when; import java.util.List; +import java.util.Map; import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -16,9 +17,11 @@ import org.mockito.Mock; import org.junit.jupiter.api.Test; import org.mockito.junit.jupiter.MockitoExtension; +import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; import org.sopt.app.application.soptamp.SoptampPointInfo.Point; import org.sopt.app.application.soptamp.SoptampPointService; import org.sopt.app.domain.entity.SoptampPoint; +import org.sopt.app.domain.enums.Part; import org.sopt.app.domain.enums.UserStatus; import org.sopt.app.interfaces.postgres.SoptampPointRepository; import org.springframework.test.util.ReflectionTestUtils; @@ -211,11 +214,59 @@ void SUCCESS_upsertSoptampPointNotPresent() { Assertions.assertDoesNotThrow(() -> soptampPointService.upsertSoptampPoint(UserStatus.ACTIVE, 1L)); } - /* TODO: Implement test cases for the following methods @Test - void findPartRanks() { + @DisplayName("SUCCESS_파트 랭킹 찾기") + void SUCCESS_findPartRanks() { + //given + Map partPoints = Map.of( + Part.PLAN, 50L, + Part.DESIGN, 0L, + Part.IOS, 20L, + Part.ANDROID, 10L, + Part.WEB, 30L, + Part.SERVER, 40L + ); + + //when + Map result = soptampPointService.findPartRanks(partPoints); + Map expected = Map.of( + Part.PLAN, PartRank.builder() + .part(Part.PLAN.getPartName()) + .rank(1) + .points(50L) + .build(), + Part.DESIGN, PartRank.builder() + .part(Part.DESIGN.getPartName()) + .rank(6) + .points(0L) + .build(), + Part.IOS, PartRank.builder() + .part(Part.IOS.getPartName()) + .rank(4) + .points(20L) + .build(), + Part.ANDROID, PartRank.builder() + .part(Part.ANDROID.getPartName()) + .rank(5) + .points(10L) + .build(), + Part.WEB, PartRank.builder() + .part(Part.WEB.getPartName()) + .rank(3) + .points(30L) + .build(), + Part.SERVER, PartRank.builder() + .part(Part.SERVER.getPartName()) + .rank(2) + .points(40L) + .build() + ); + + //then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); } + /* TODO: Implement test cases for the following methods @Test void calculateSumOfPoints() { } From f797d92a2689f3203e635b6e5662277706908d59 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Apr 2024 17:36:53 +0900 Subject: [PATCH 11/48] =?UTF-8?q?feat:=20calculateSumOfPoints=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/SoptampPointServiceTest.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index 68840e0d..01f083b8 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -266,10 +266,23 @@ void SUCCESS_findPartRanks() { assertThat(result).usingRecursiveComparison().isEqualTo(expected); } - /* TODO: Implement test cases for the following methods @Test - void calculateSumOfPoints() { - } + @DisplayName("SUCCESS_파트 랭킹 계산") + void SUCCESS_calculateSumOfPoints() { + //given + List soptampPointList = List.of( + Point.builder() + .points(100L) + .build(), + Point.builder() + .points(200L) + .build() + ); + + //when + Long result = soptampPointService.calculateSumOfPoints(soptampPointList); - */ + //then + assertThat(result).isEqualTo(300L); + } } \ No newline at end of file From 933df8d14bd4018414b42d40d58e04caeaeef615 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Apr 2024 17:37:29 +0900 Subject: [PATCH 12/48] =?UTF-8?q?feat:=20SoptampPointRepositoryTest=20?= =?UTF-8?q?=ED=8B=80=20=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgres/SoptampPointRepositoryTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java diff --git a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java new file mode 100644 index 00000000..0886e758 --- /dev/null +++ b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java @@ -0,0 +1,36 @@ +package org.sopt.app.interfaces.postgres; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +@DataJpaTest +class SoptampPointRepositoryTest { + + @BeforeEach + void beforeTest() { + + } + + /* TODO: Implement following test + + @Autowired + private SoptampPointRepository soptampPointRepository; + + @Test + @DisplayName("SUCCESS_기수별 솝탬프 포인트 찾기") + void SUCCESS_findAllByGeneration() { + + } + + @Test + void SUCCESS_findAllBySoptampUserIdAndGeneration() { + } + + @Test + void SUCCESS_findAllBySoptampUserIdInAndGeneration() { + } + */ +} \ No newline at end of file From 642dc4847c108541f9c4022770d4e04507c02d30 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Apr 2024 17:49:33 +0900 Subject: [PATCH 13/48] =?UTF-8?q?feat:=20findAllMission=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/MissionServiceTest.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/java/org/sopt/app/application/mission/MissionServiceTest.java diff --git a/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java b/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java new file mode 100644 index 00000000..4e402090 --- /dev/null +++ b/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java @@ -0,0 +1,81 @@ +package org.sopt.app.application.mission; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.when; + +import java.util.List; +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 org.sopt.app.application.mission.MissionInfo.Completeness; +import org.sopt.app.domain.entity.Mission; +import org.sopt.app.domain.entity.Stamp; +import org.sopt.app.interfaces.postgres.MissionRepository; +import org.sopt.app.interfaces.postgres.StampRepository; + +@ExtendWith(MockitoExtension.class) +class MissionServiceTest { + + @Mock + private MissionRepository missionRepository; + + @Mock + private StampRepository stampRepository; + + @InjectMocks + private MissionService missionService; + + @Test + @DisplayName("SUCCESS_모든 미션 조회") + void SUCCESS_findAllMission() { + // given + final Long anyUserId = anyLong(); + final List stampList = List.of( + Stamp.builder().missionId(1L).build(), + Stamp.builder().missionId(2L).build() + ); + final List missionList = List.of( + Mission.builder().id(1L).title("title1").level(1).build(), + Mission.builder().id(2L).title("title2").level(2).build(), + Mission.builder().id(3L).title("title3").level(3).build() + ); + + // when + when(stampRepository.findAllByUserId(anyUserId)).thenReturn(stampList); + when(missionRepository.findAllByDisplay(true)).thenReturn(missionList); + + List result = missionService.findAllMission(anyUserId); + List expected = List.of( + Completeness.builder().id(1L).title("title1").level(1).isCompleted(true).build(), + Completeness.builder().id(2L).title("title2").level(2).isCompleted(true).build(), + Completeness.builder().id(3L).title("title3").level(3).isCompleted(false).build() + ); + + // then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); + } + + /* TODO: implement following test case + + @Test + void uploadMission() { + } + + @Test + void getCompleteMission() { + } + + @Test + void getIncompleteMission() { + } + + @Test + void getMissionById() { + } + + */ +} \ No newline at end of file From 0c36fad5e1d3ba06a194b6e32da448f858a1cf16 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Apr 2024 17:56:59 +0900 Subject: [PATCH 14/48] =?UTF-8?q?feat:=20uploadMission=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/MissionServiceTest.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java b/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java index 4e402090..2f2f5281 100644 --- a/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java +++ b/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java @@ -1,6 +1,7 @@ package org.sopt.app.application.mission; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; @@ -8,6 +9,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -16,6 +18,7 @@ import org.sopt.app.domain.entity.Stamp; import org.sopt.app.interfaces.postgres.MissionRepository; import org.sopt.app.interfaces.postgres.StampRepository; +import org.sopt.app.presentation.mission.MissionRequest.RegisterMissionRequest; @ExtendWith(MockitoExtension.class) class MissionServiceTest { @@ -59,12 +62,31 @@ void SUCCESS_findAllMission() { assertThat(result).usingRecursiveComparison().isEqualTo(expected); } - /* TODO: implement following test case @Test - void uploadMission() { + @DisplayName("SUCCESS_미션 업로드") + void SUCCESS_uploadMission() { + // given + RegisterMissionRequest registerMissionRequest = new RegisterMissionRequest(); + registerMissionRequest.setTitle("title"); + registerMissionRequest.setLevel(1); + registerMissionRequest.setImage("image"); + + // when + Mission expected = Mission.builder() + .title("title") + .level(1) + .profileImage(List.of("image")) + .build(); + when(missionRepository.save(any(Mission.class))).thenReturn(expected); + + Mission result = missionService.uploadMission(registerMissionRequest); + + // then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); } + /* TODO: implement following test case @Test void getCompleteMission() { } From 1854e36932a8b8a431af4701ba6b81ecd1d58901 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Apr 2024 18:02:34 +0900 Subject: [PATCH 15/48] =?UTF-8?q?feat:=20getCompleteMission=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/MissionServiceTest.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java b/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java index 2f2f5281..fddb0be2 100644 --- a/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java +++ b/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java @@ -86,11 +86,33 @@ void SUCCESS_uploadMission() { assertThat(result).usingRecursiveComparison().isEqualTo(expected); } - /* TODO: implement following test case @Test - void getCompleteMission() { + @DisplayName("SUCCESS_완료한 미션 조회") + void SUCCESS_getCompleteMission() { + // given + final Long anyUserId = anyLong(); + final List stampList = List.of( + Stamp.builder().missionId(1L).build(), + Stamp.builder().missionId(2L).build() + ); + final List missionIdList = List.of(1L, 2L); + + + // when + final List expected = List.of( + Mission.builder().id(1L).build(), + Mission.builder().id(2L).build() + ); + when(stampRepository.findAllByUserId(anyUserId)).thenReturn(stampList); + when(missionRepository.findMissionInOrderByLevelAndTitle(missionIdList)).thenReturn(expected); + + List result = missionService.getCompleteMission(anyUserId); + + // then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); } + /* TODO: implement following test case @Test void getIncompleteMission() { } From 249e4794cfbbce34d902d940050a9a46b7e04adb Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Apr 2024 18:05:40 +0900 Subject: [PATCH 16/48] =?UTF-8?q?refactor:=20Collections.toList=20->=20toL?= =?UTF-8?q?ist=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sopt/app/application/mission/MissionService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/app/application/mission/MissionService.java b/src/main/java/org/sopt/app/application/mission/MissionService.java index 4651dc6b..ce2a3b23 100644 --- a/src/main/java/org/sopt/app/application/mission/MissionService.java +++ b/src/main/java/org/sopt/app/application/mission/MissionService.java @@ -69,11 +69,11 @@ public List getIncompleteMission(Long userId) { //전체 미션 조회하기 val missionList = missionRepository.findAllByDisplay(true); - val missionIdList = missionList.stream().map(Mission::getId).collect(Collectors.toList()); + val missionIdList = missionList.stream().map(Mission::getId).toList(); //stamp에서 userId로 달성한 mission 조회하기 val stampList = stampRepository.findAllByUserId(userId); - val completeMissionIdList = stampList.stream().map(Stamp::getMissionId).collect(Collectors.toList()); + val completeMissionIdList = stampList.stream().map(Stamp::getMissionId).toList(); //두 리스트 비교해서 중복값 제거 val inCompleteIdList = missionIdList.stream() From 3da12bfb0e75fd9affe0437823c40e19213eb2e6 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Apr 2024 19:28:06 +0900 Subject: [PATCH 17/48] =?UTF-8?q?feat:=20getIncompleteMission=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{mission => }/MissionServiceTest.java | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) rename src/test/java/org/sopt/app/application/{mission => }/MissionServiceTest.java (73%) diff --git a/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java b/src/test/java/org/sopt/app/application/MissionServiceTest.java similarity index 73% rename from src/test/java/org/sopt/app/application/mission/MissionServiceTest.java rename to src/test/java/org/sopt/app/application/MissionServiceTest.java index fddb0be2..4fb6a5b3 100644 --- a/src/test/java/org/sopt/app/application/mission/MissionServiceTest.java +++ b/src/test/java/org/sopt/app/application/MissionServiceTest.java @@ -1,4 +1,4 @@ -package org.sopt.app.application.mission; +package org.sopt.app.application; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -9,11 +9,11 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.sopt.app.application.mission.MissionInfo.Completeness; +import org.sopt.app.application.mission.MissionService; import org.sopt.app.domain.entity.Mission; import org.sopt.app.domain.entity.Stamp; import org.sopt.app.interfaces.postgres.MissionRepository; @@ -32,24 +32,26 @@ class MissionServiceTest { @InjectMocks private MissionService missionService; + private List stampList = List.of( + Stamp.builder().missionId(1L).build(), + Stamp.builder().missionId(2L).build() + ); + + private List displayedMissionList = List.of( + Mission.builder().id(1L).title("title1").level(1).display(true).build(), + Mission.builder().id(2L).title("title2").level(2).display(true).build(), + Mission.builder().id(3L).title("title3").level(3).display(true).build() + ); + @Test @DisplayName("SUCCESS_모든 미션 조회") void SUCCESS_findAllMission() { // given final Long anyUserId = anyLong(); - final List stampList = List.of( - Stamp.builder().missionId(1L).build(), - Stamp.builder().missionId(2L).build() - ); - final List missionList = List.of( - Mission.builder().id(1L).title("title1").level(1).build(), - Mission.builder().id(2L).title("title2").level(2).build(), - Mission.builder().id(3L).title("title3").level(3).build() - ); // when when(stampRepository.findAllByUserId(anyUserId)).thenReturn(stampList); - when(missionRepository.findAllByDisplay(true)).thenReturn(missionList); + when(missionRepository.findAllByDisplay(true)).thenReturn(displayedMissionList); List result = missionService.findAllMission(anyUserId); List expected = List.of( @@ -91,13 +93,8 @@ void SUCCESS_uploadMission() { void SUCCESS_getCompleteMission() { // given final Long anyUserId = anyLong(); - final List stampList = List.of( - Stamp.builder().missionId(1L).build(), - Stamp.builder().missionId(2L).build() - ); final List missionIdList = List.of(1L, 2L); - // when final List expected = List.of( Mission.builder().id(1L).build(), @@ -112,11 +109,26 @@ void SUCCESS_getCompleteMission() { assertThat(result).usingRecursiveComparison().isEqualTo(expected); } - /* TODO: implement following test case @Test - void getIncompleteMission() { + @DisplayName("SUCCESS_미완료한 미션 조회") + void SUCCESS_getIncompleteMission() { + // given + Long anyUserId = anyLong(); + + // when + List expected = List.of(Mission.builder().id(3L).build()); + + when(stampRepository.findAllByUserId(anyUserId)).thenReturn(stampList); + when(missionRepository.findMissionInOrderByLevelAndTitleAndDisplayTrue(any())).thenReturn(expected); + when(missionRepository.findAllByDisplay(true)).thenReturn(displayedMissionList); + + List result = missionService.getIncompleteMission(anyUserId); + + // then + assertThat(result).usingRecursiveComparison().isEqualTo(expected); } + /* TODO: implement following test case @Test void getMissionById() { } From 0686a1c0eab695e7b750bfc119eb3bc58e594365 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 16 Apr 2024 19:36:37 +0900 Subject: [PATCH 18/48] =?UTF-8?q?feat:=20getMissionById=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5,=20=EC=8B=A4=ED=8C=A8=20=EC=BC=80=EC=9D=B4=EC=8A=A4?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/application/MissionServiceTest.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/sopt/app/application/MissionServiceTest.java b/src/test/java/org/sopt/app/application/MissionServiceTest.java index 4fb6a5b3..fd338733 100644 --- a/src/test/java/org/sopt/app/application/MissionServiceTest.java +++ b/src/test/java/org/sopt/app/application/MissionServiceTest.java @@ -6,6 +6,8 @@ import static org.mockito.Mockito.when; import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -13,6 +15,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.sopt.app.application.mission.MissionInfo.Completeness; +import org.sopt.app.application.mission.MissionInfo.Level; import org.sopt.app.application.mission.MissionService; import org.sopt.app.domain.entity.Mission; import org.sopt.app.domain.entity.Stamp; @@ -128,10 +131,34 @@ void SUCCESS_getIncompleteMission() { assertThat(result).usingRecursiveComparison().isEqualTo(expected); } - /* TODO: implement following test case @Test - void getMissionById() { + @DisplayName("SUCCESS_미션 조회") + void SUCCESS_getMissionById() { + // given + final Long anyMissionId = anyLong(); + final Integer level = 1; + + // when + when(missionRepository.findById(anyMissionId)).thenReturn( + Optional.of(Mission.builder().id(anyMissionId).level(level).build())); + Level result = missionService.getMissionById(anyMissionId); + + // then + assertThat(result.getLevel()).isEqualTo(level); } - */ + @Test + @DisplayName("FAIL_미션 조회") + void FAIL_getMissionById() { + // given + final Long anyMissionId = anyLong(); + + // when + when(missionRepository.findById(anyMissionId)).thenReturn(Optional.empty()); + + // then + Assertions.assertThrows(IllegalArgumentException.class, () -> { + missionService.getMissionById(anyMissionId); + }); + } } \ No newline at end of file From 4460feda2db28162798e210fdc2a6df094bc8770 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 15:07:58 +0900 Subject: [PATCH 19/48] =?UTF-8?q?chore:=20=EA=B0=80=EB=8F=85=EC=84=B1?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=B4=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/app/interfaces/postgres/UserRepositoryTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/UserRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/UserRepositoryTest.java index 710a0732..f8b7451d 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/UserRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/UserRepositoryTest.java @@ -19,11 +19,12 @@ @Import(QuerydslConfiguration.class) class UserRepositoryTest { - User user1 = new User(); - User user2 = new User(); @Autowired private UserRepository userRepository; + private User user1 = new User(); + private User user2 = new User(); + @BeforeEach void beforeTest() { From d23bcc3b0d9ef819804f90cf2bc9e59152bcef57 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 15:08:24 +0900 Subject: [PATCH 20/48] =?UTF-8?q?feat:=20findMissionInOrderByLevelAndTitle?= =?UTF-8?q?AndDisplayTrue=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgres/MissionRepositoryTest.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java diff --git a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java new file mode 100644 index 00000000..1ec02665 --- /dev/null +++ b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java @@ -0,0 +1,78 @@ +package org.sopt.app.interfaces.postgres; + +import java.util.List; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.sopt.app.common.config.QuerydslConfiguration; +import org.sopt.app.domain.entity.Mission; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +@DataJpaTest +@AutoConfigureTestDatabase(replace = Replace.NONE) +@Import(QuerydslConfiguration.class) +class MissionRepositoryTest { + + @Autowired + private MissionRepository missionRepository; + + private Mission mission1; + private Mission mission2; + private Mission mission3; + + @BeforeEach + void beforeTest() { + mission1 = missionRepository.save( + Mission.builder() + .display(true) + .build() + ); + mission2 = missionRepository.save( + Mission.builder() + .display(false) + .build() + ); + + mission3 = missionRepository.save( + Mission.builder() + .display(true) + .build() + ); + } + + + + @Test + @DisplayName("SUCCESS_미션 아이디 리스트로 Display True인 미션 리스트 조회") + void SUCCESS_findMissionInOrderByLevelAndTitleAndDisplayTrue() { + // given + List missionList = List.of( + mission1.getId(), + mission2.getId(), + mission3.getId() + ); + + // when + List result = missionRepository.findMissionInOrderByLevelAndTitleAndDisplayTrue(missionList); + List expected = List.of(mission1, mission3); + + // then + Assertions.assertThat(result).containsExactlyElementsOf(expected); + } + + /* TODO: implement following test + @Test + void findMissionInOrderByLevelAndTitle() { + } + + @Test + void findAllByDisplay() { + } + + */ +} \ No newline at end of file From 2ff97600168e7d94d6a2d83f79ca6668285670dc Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 16:17:06 +0900 Subject: [PATCH 21/48] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20new=20=EC=84=A0=EC=96=B8=20=EC=82=AD=EC=A0=9C=20(#2?= =?UTF-8?q?17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/interfaces/postgres/UserRepositoryTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/UserRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/UserRepositoryTest.java index f8b7451d..61a91b32 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/UserRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/UserRepositoryTest.java @@ -22,21 +22,19 @@ class UserRepositoryTest { @Autowired private UserRepository userRepository; - private User user1 = new User(); - private User user2 = new User(); + private User user1; + private User user2; @BeforeEach void beforeTest() { user1 = userRepository.save( User.builder() - .id(1L) .playgroundId(generateUniquePlaygroundId()) .build() ); user2 = userRepository.save( User.builder() - .id(2L) .playgroundId(generateUniquePlaygroundId()) .build() ); From e052696e86b7141ac073987e1923f21a6908c639 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 16:17:56 +0900 Subject: [PATCH 22/48] =?UTF-8?q?feat:=20findMissionInOrderByLevelAndTitle?= =?UTF-8?q?=20=EC=84=B1=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgres/MissionRepositoryTest.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java index 1ec02665..cf56484c 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java @@ -37,7 +37,6 @@ void beforeTest() { .display(false) .build() ); - mission3 = missionRepository.save( Mission.builder() .display(true) @@ -45,8 +44,6 @@ void beforeTest() { ); } - - @Test @DisplayName("SUCCESS_미션 아이디 리스트로 Display True인 미션 리스트 조회") void SUCCESS_findMissionInOrderByLevelAndTitleAndDisplayTrue() { @@ -65,11 +62,25 @@ void SUCCESS_findMissionInOrderByLevelAndTitleAndDisplayTrue() { Assertions.assertThat(result).containsExactlyElementsOf(expected); } - /* TODO: implement following test @Test - void findMissionInOrderByLevelAndTitle() { + @DisplayName("SUCCESS_미션 아이디 리스트로 미션 리스트 조회") + void SUCCESS_findMissionInOrderByLevelAndTitle() { + // given + List missionList = List.of( + mission1.getId(), + mission2.getId(), + mission3.getId() + ); + + // when + List result = missionRepository.findMissionInOrderByLevelAndTitle(missionList); + List expected = List.of(mission1, mission2, mission3); + + // then + Assertions.assertThat(result).containsExactlyElementsOf(expected); } + /* TODO: implement following test @Test void findAllByDisplay() { } From 6f3ebf697edc00b1abccc44de24d82454bffdcf6 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 16:37:39 +0900 Subject: [PATCH 23/48] =?UTF-8?q?feat:=20findAllByDisplay=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgres/MissionRepositoryTest.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java index cf56484c..0f5936b9 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java @@ -21,25 +21,25 @@ class MissionRepositoryTest { @Autowired private MissionRepository missionRepository; - private Mission mission1; - private Mission mission2; - private Mission mission3; + private Mission displayedMission1; + private Mission displayedMission2; + private Mission notDisplayedMission; @BeforeEach void beforeTest() { - mission1 = missionRepository.save( + displayedMission1 = missionRepository.save( Mission.builder() .display(true) .build() ); - mission2 = missionRepository.save( + displayedMission2 = missionRepository.save( Mission.builder() - .display(false) + .display(true) .build() ); - mission3 = missionRepository.save( + notDisplayedMission = missionRepository.save( Mission.builder() - .display(true) + .display(false) .build() ); } @@ -49,14 +49,14 @@ void beforeTest() { void SUCCESS_findMissionInOrderByLevelAndTitleAndDisplayTrue() { // given List missionList = List.of( - mission1.getId(), - mission2.getId(), - mission3.getId() + displayedMission1.getId(), + notDisplayedMission.getId(), + displayedMission2.getId() ); // when List result = missionRepository.findMissionInOrderByLevelAndTitleAndDisplayTrue(missionList); - List expected = List.of(mission1, mission3); + List expected = List.of(displayedMission1, displayedMission2); // then Assertions.assertThat(result).containsExactlyElementsOf(expected); @@ -67,23 +67,26 @@ void SUCCESS_findMissionInOrderByLevelAndTitleAndDisplayTrue() { void SUCCESS_findMissionInOrderByLevelAndTitle() { // given List missionList = List.of( - mission1.getId(), - mission2.getId(), - mission3.getId() + displayedMission1.getId(), + displayedMission2.getId(), + notDisplayedMission.getId() ); // when List result = missionRepository.findMissionInOrderByLevelAndTitle(missionList); - List expected = List.of(mission1, mission2, mission3); + List expected = List.of(displayedMission1, displayedMission2, notDisplayedMission); // then - Assertions.assertThat(result).containsExactlyElementsOf(expected); + Assertions.assertThat(result).hasSameElementsAs(expected); } - /* TODO: implement following test @Test - void findAllByDisplay() { - } + @DisplayName("SUCCESS_Display True인 모든 미션 리스트 조회") + void SUCCESS_findAllByDisplay() { + List result = missionRepository.findAllByDisplay(true); - */ + Assertions.assertThat(result) + .containsAll(List.of(displayedMission1, displayedMission2)) + .doesNotContain(notDisplayedMission); + } } \ No newline at end of file From b2040866da30e789ed9615b0e6e1ac797e94bac8 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 16:54:15 +0900 Subject: [PATCH 24/48] =?UTF-8?q?feat:=20findAllByGeneration=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgres/SoptampPointRepositoryTest.java | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java index 0886e758..bf506ed3 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java @@ -1,30 +1,64 @@ package org.sopt.app.interfaces.postgres; +import java.util.List; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.sopt.app.common.config.QuerydslConfiguration; +import org.sopt.app.domain.entity.SoptampPoint; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; @DataJpaTest +@AutoConfigureTestDatabase(replace = Replace.NONE) +@Import(QuerydslConfiguration.class) class SoptampPointRepositoryTest { + @Autowired + private SoptampPointRepository soptampPointRepository; + + private SoptampPoint generation1soptampPointId1; + private SoptampPoint generation1soptampPointId2; + private SoptampPoint generation2soptampPointId3; + @BeforeEach void beforeTest() { + generation1soptampPointId1 = soptampPointRepository.save( + SoptampPoint.builder() + .generation(1L) + .soptampUserId(1L) + .build() + ); - } - - /* TODO: Implement following test + generation1soptampPointId2 = soptampPointRepository.save( + SoptampPoint.builder() + .generation(1L) + .soptampUserId(2L) + .build() + ); - @Autowired - private SoptampPointRepository soptampPointRepository; + generation2soptampPointId3 = soptampPointRepository.save( + SoptampPoint.builder() + .generation(2L) + .soptampUserId(3L) + .build() + ); + } @Test @DisplayName("SUCCESS_기수별 솝탬프 포인트 찾기") void SUCCESS_findAllByGeneration() { - + Assertions.assertThat(soptampPointRepository.findAllByGeneration(1L)) + .hasSameElementsAs( + List.of(generation1soptampPointId1, generation1soptampPointId2) + ); } + /* TODO: Implement following test @Test void SUCCESS_findAllBySoptampUserIdAndGeneration() { } From 17b325ba2928500051a1c2ef9aa7b3cf16879a5a Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 16:55:24 +0900 Subject: [PATCH 25/48] =?UTF-8?q?refactor:=20=EB=A6=AC=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20assert=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/app/interfaces/postgres/MissionRepositoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java index 0f5936b9..cb9fc270 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java @@ -59,7 +59,7 @@ void SUCCESS_findMissionInOrderByLevelAndTitleAndDisplayTrue() { List expected = List.of(displayedMission1, displayedMission2); // then - Assertions.assertThat(result).containsExactlyElementsOf(expected); + Assertions.assertThat(result).hasSameElementsAs(expected); } @Test From db2f2cc4ceb76e269da902c51ef3d00eb9245d0f Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 17:03:16 +0900 Subject: [PATCH 26/48] =?UTF-8?q?feat:=20findAllBySoptampUserIdAndGenerati?= =?UTF-8?q?on=20=EC=84=B1=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interfaces/postgres/SoptampPointRepositoryTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java index bf506ed3..ce68010a 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java @@ -1,6 +1,7 @@ package org.sopt.app.interfaces.postgres; import java.util.List; +import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -58,11 +59,15 @@ void SUCCESS_findAllByGeneration() { ); } - /* TODO: Implement following test @Test + @DisplayName("SUCCESS_유저 아이디와 기수로 솝탬프 포인트 리스트 찾기") void SUCCESS_findAllBySoptampUserIdAndGeneration() { + Assertions.assertThat(soptampPointRepository.findAllBySoptampUserIdAndGeneration(1L, 1L) + .orElseThrow().getId()) + .isEqualTo(generation1soptampPointId1.getId()); } + /* TODO: Implement following test @Test void SUCCESS_findAllBySoptampUserIdInAndGeneration() { } From 00563e3890d7b565b557184c7b50a85055e38298 Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 17:07:23 +0900 Subject: [PATCH 27/48] =?UTF-8?q?feat:=20findAllBySoptampUserIdInAndGenera?= =?UTF-8?q?tion=20=EC=84=B1=EA=B3=B5=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgres/SoptampPointRepositoryTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java index ce68010a..9cbd1d53 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java @@ -24,7 +24,6 @@ class SoptampPointRepositoryTest { private SoptampPoint generation1soptampPointId1; private SoptampPoint generation1soptampPointId2; - private SoptampPoint generation2soptampPointId3; @BeforeEach void beforeTest() { @@ -42,7 +41,7 @@ void beforeTest() { .build() ); - generation2soptampPointId3 = soptampPointRepository.save( + soptampPointRepository.save( SoptampPoint.builder() .generation(2L) .soptampUserId(3L) @@ -67,9 +66,19 @@ void SUCCESS_findAllBySoptampUserIdAndGeneration() { .isEqualTo(generation1soptampPointId1.getId()); } - /* TODO: Implement following test @Test + @DisplayName("SUCCESS_유저 아이디 리스트와 기수로 솝탬프 포인트 리스트 찾기") void SUCCESS_findAllBySoptampUserIdInAndGeneration() { + // given + List userIdList = List.of(1L, 2L); + + // when + List result = soptampPointRepository.findAllBySoptampUserIdInAndGeneration(userIdList, 1L); + + // then + Assertions.assertThat(result) + .hasSameElementsAs( + List.of(generation1soptampPointId1, generation1soptampPointId2) + ); } - */ } \ No newline at end of file From 09dcd17b2c7093c3729cb4dc75894c9da55ec03e Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 17:12:42 +0900 Subject: [PATCH 28/48] =?UTF-8?q?refactor:=20=EB=8D=94=20=EC=A0=95?= =?UTF-8?q?=ED=99=95=ED=95=9C=20assert=EB=AC=B8=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=8B=A0=EB=A2=B0=EC=84=B1=20?= =?UTF-8?q?=ED=96=A5=EC=83=81=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgres/SoptampPointRepositoryTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java index 9cbd1d53..f2b4b18f 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java @@ -43,17 +43,25 @@ void beforeTest() { soptampPointRepository.save( SoptampPoint.builder() - .generation(2L) + .generation(1L) .soptampUserId(3L) .build() ); + + soptampPointRepository.save( + SoptampPoint.builder() + .generation(2L) + .soptampUserId(4L) + .build() + ); + } @Test @DisplayName("SUCCESS_기수별 솝탬프 포인트 찾기") void SUCCESS_findAllByGeneration() { Assertions.assertThat(soptampPointRepository.findAllByGeneration(1L)) - .hasSameElementsAs( + .containsAll( List.of(generation1soptampPointId1, generation1soptampPointId2) ); } From ba094235cfa2d50430fd9ad1e44f883f09ff6acd Mon Sep 17 00:00:00 2001 From: kseysh Date: Thu, 18 Apr 2024 17:13:13 +0900 Subject: [PATCH 29/48] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=EB=AC=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java index f2b4b18f..00e9b451 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java @@ -1,7 +1,6 @@ package org.sopt.app.interfaces.postgres; import java.util.List; -import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; From 52dca81dbf94127029f2f0ed2390c7f5fa88cdcf Mon Sep 17 00:00:00 2001 From: kseysh Date: Fri, 19 Apr 2024 13:34:37 +0900 Subject: [PATCH 30/48] =?UTF-8?q?fix:=20prod=20=ED=99=98=EA=B2=BD=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=8B=A4=ED=8C=A8=EC=B2=98=EB=A6=AC=EB=90=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20(#217)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/interfaces/postgres/MissionRepositoryTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java index cb9fc270..fda9c142 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/MissionRepositoryTest.java @@ -30,16 +30,22 @@ void beforeTest() { displayedMission1 = missionRepository.save( Mission.builder() .display(true) + .title("title1") + .level(1) .build() ); displayedMission2 = missionRepository.save( Mission.builder() .display(true) + .title("title2") + .level(2) .build() ); notDisplayedMission = missionRepository.save( Mission.builder() .display(false) + .title("title3") + .level(3) .build() ); } From da84b616d95b273c2d3048a57cc78c42120d7514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Sun, 12 May 2024 16:09:22 +0900 Subject: [PATCH 31/48] =?UTF-8?q?feat:=20=EC=A4=91=EB=B3=B5=20=EB=8B=89?= =?UTF-8?q?=EB=84=A4=EC=9E=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/soptamp/SoptampUserInfo.java | 1 + .../soptamp/SoptampUserService.java | 39 ++++++++++++++----- .../sopt/app/domain/entity/SoptampUser.java | 5 ++- .../sopt/app/facade/AdminSoptampFacade.java | 9 +++-- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampUserInfo.java b/src/main/java/org/sopt/app/application/soptamp/SoptampUserInfo.java index c121a872..eb42646d 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampUserInfo.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampUserInfo.java @@ -29,6 +29,7 @@ public static class SoptampUserPlaygroundInfo { private Long userId; private Long playgroundId; + private String name; private Long generation; private String part; } diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java b/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java index 5caa3de5..48d64fbb 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java @@ -2,9 +2,11 @@ import static org.sopt.app.domain.enums.PlaygroundPart.findPlaygroundPart; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -242,36 +244,53 @@ public List initAllCurrentGenerationSoptampUser( List userInfoList ) { val validatedSoptampUserList = validateNickname(soptampUserList); - validatedSoptampUserList.stream().forEach(e -> System.out.println(e)); - soptampUserList.stream().forEach(soptampUser -> { + validatedSoptampUserList.stream().forEach(soptampUser -> { val userInfo = userInfoList.stream() .filter(e -> soptampUser.getUserId().equals(e.getUserId())) .findFirst().get(); PlaygroundPart part = findPlaygroundPart(userInfo.getPart()); - soptampUser.updateNicknameAndGenerationAndPart( - part.getSoptampNickname() + soptampUser.getNickname(), + soptampUser.updateGenerationAndPart( userInfo.getGeneration(), part ); }); - soptampUserRepository.saveAll(soptampUserList); + soptampUserRepository.saveAll(validatedSoptampUserList); - return soptampUserList; + return validatedSoptampUserList; } public List validateNickname(List soptampUserList) { + // 닉네임 정렬 soptampUserList = soptampUserList.stream().sorted(Comparator.comparing(SoptampUser::getNickname)) .collect(Collectors.toList()); + + // uniqueNickname map 생성 + val nicknameMap = new HashMap>(); val nicknameList = soptampUserList.stream().map(SoptampUser::getNickname).collect(Collectors.toList()); val uniqueNicknameList = nicknameList.stream().distinct().collect(Collectors.toList()); - uniqueNicknameList.stream().forEach(nickname -> { val count = Collections.frequency(nicknameList, nickname); - val alphabetList = Arrays.asList("ABCDEFGHIJKLMNOPQRSTUVWXYZ".substring(0, count).split("")); - // 동명이인 처리 + if (count == 1) { + nicknameMap.put(nickname, new ArrayList<>(List.of())); + } else { + val alphabetList = Arrays.asList("ABCDEFGHIJKLMNOPQRSTUVWXYZ".substring(0, count).split("")); + val changedList = alphabetList.stream().map(alphabet -> nickname + alphabet).toList(); + nicknameMap.put(nickname, new ArrayList<>(changedList)); + } }); + + // soptampUser 리스트 userId 기준으로 중복 닉네임 알파벳 부여 + soptampUserList.stream().sorted(Comparator.comparing(SoptampUser::getUserId)).forEach(soptampUser -> { + val validatedNicknameList = nicknameMap.get(soptampUser.getNickname()); + if (validatedNicknameList.size() > 0) { + val validatedNickname = validatedNicknameList.get(0); + validatedNicknameList.remove(0); + nicknameMap.put(soptampUser.getNickname(), validatedNicknameList); + soptampUser.updateNickname(validatedNickname); + } + }); + return soptampUserList; } - } \ No newline at end of file diff --git a/src/main/java/org/sopt/app/domain/entity/SoptampUser.java b/src/main/java/org/sopt/app/domain/entity/SoptampUser.java index 936609ad..63eb4eb3 100644 --- a/src/main/java/org/sopt/app/domain/entity/SoptampUser.java +++ b/src/main/java/org/sopt/app/domain/entity/SoptampUser.java @@ -47,8 +47,11 @@ public void initTotalPoints() { this.totalPoints = 0L; } - public void updateNicknameAndGenerationAndPart(String nickname, Long generation, PlaygroundPart part) { + public void updateNickname(String nickname) { this.nickname = nickname; + } + + public void updateGenerationAndPart(Long generation, PlaygroundPart part) { this.generation = generation; this.part = part.name(); } diff --git a/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java b/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java index 1562d347..e7351a13 100644 --- a/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java +++ b/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java @@ -64,6 +64,7 @@ public int initCurrentGenerationInfo(User user) { SoptampUserPlaygroundInfo.builder() .userId(userProfile.get().getUserId()) .playgroundId(userProfile.get().getPlaygroundId()) + .name(userProfile.get().getName()) .generation(Long.parseLong(memberProfile.getLatestActivity().getGeneration())) .part(memberProfile.getLatestActivity().getPart()) .build(); @@ -74,11 +75,11 @@ public int initCurrentGenerationInfo(User user) { val updatedSoptampUserList = soptampUserService.initAllCurrentGenerationSoptampUser(soptampUserList, userInfoList); - // 플그 아이디로 SoptampPoint 현활기수 row 추가 - val currentGenerationSoptampPointList = soptampPointService.createCurrentGenerationSoptampPointList( - updatedSoptampUserList); +// // 플그 아이디로 SoptampPoint 현활기수 row 추가 +// val currentGenerationSoptampPointList = soptampPointService.createCurrentGenerationSoptampPointList( +// updatedSoptampUserList); - return currentGenerationSoptampPointList.size(); + return updatedSoptampUserList.size(); } private void validateAdminUser(User user) { From aed4360ab2da0637749bea6f7639b304f09a46a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Sun, 12 May 2024 16:40:02 +0900 Subject: [PATCH 32/48] =?UTF-8?q?feat:=20=ED=98=84=ED=99=9C=EA=B8=B0?= =?UTF-8?q?=EC=88=98=20soptampPoint=20row=20=EC=97=86=EC=9D=84=20=EB=95=8C?= =?UTF-8?q?=EB=A7=8C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../soptamp/SoptampPointService.java | 26 ++++++++++++++----- .../sopt/app/facade/AdminSoptampFacade.java | 15 +++++++---- .../admin/AdminSoptampController.java | 3 +-- .../admin/AdminSoptampResponse.java | 8 ++++-- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java b/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java index cedb82f4..8f70d216 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampPointService.java @@ -138,14 +138,26 @@ public void deleteAll() { public List createCurrentGenerationSoptampPointList( List soptampUserList ) { - val soptampPointList = soptampUserList.stream().map(e -> - SoptampPoint - .builder() - .generation(currentGeneration) - .points(0L) - .soptampUserId(e.getId()) - .build()) + val soptampUserIdList = soptampUserList.stream().map(SoptampUser::getId).toList(); + + val prevSoptampUserIdList = soptampPointRepository.findAllBySoptampUserIdInAndGeneration( + soptampUserIdList, currentGeneration + ).stream().map(SoptampPoint::getSoptampUserId).toList(); + + val newSoptampUserList = soptampUserList.stream() + .map(soptampUser -> prevSoptampUserIdList.contains(soptampUser.getId()) ? null : soptampUser) + .filter(x -> x != null) .toList(); + + val soptampPointList = newSoptampUserList.stream().map(soptampUser -> + SoptampPoint + .builder() + .generation(currentGeneration) + .points(0L) + .soptampUserId(soptampUser.getId()) + .build() + ).toList(); + soptampPointRepository.saveAll(soptampPointList); return soptampPointList; } diff --git a/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java b/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java index e7351a13..9f41f7cc 100644 --- a/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java +++ b/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java @@ -12,6 +12,8 @@ import org.sopt.app.application.user.UserService; import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.domain.entity.User; +import org.sopt.app.presentation.admin.AdminSoptampResponse; +import org.sopt.app.presentation.admin.AdminSoptampResponse.Rows; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -36,7 +38,7 @@ public void initAllMissionAndStampAndPoints(User user) { } @Transactional - public int initCurrentGenerationInfo(User user) { + public AdminSoptampResponse.Rows initCurrentGenerationInfo(User user) { validateAdminUser(user); // 플그에서 현재 기수 멤버 아이디 조회 @@ -75,11 +77,14 @@ public int initCurrentGenerationInfo(User user) { val updatedSoptampUserList = soptampUserService.initAllCurrentGenerationSoptampUser(soptampUserList, userInfoList); -// // 플그 아이디로 SoptampPoint 현활기수 row 추가 -// val currentGenerationSoptampPointList = soptampPointService.createCurrentGenerationSoptampPointList( -// updatedSoptampUserList); + // 플그 아이디로 SoptampPoint 현활기수 row 추가 + val currentGenerationSoptampPointList = soptampPointService.createCurrentGenerationSoptampPointList( + updatedSoptampUserList); - return updatedSoptampUserList.size(); + return Rows.builder() + .soptampUserRows(updatedSoptampUserList.size()) + .soptampPointRows(currentGenerationSoptampPointList.size()) + .build(); } private void validateAdminUser(User user) { diff --git a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java index 9a038f01..6d47dcf1 100644 --- a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java +++ b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java @@ -8,7 +8,6 @@ import lombok.val; import org.sopt.app.domain.entity.User; import org.sopt.app.facade.AdminSoptampFacade; -import org.sopt.app.presentation.admin.AdminSoptampResponse.Rows; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -48,6 +47,6 @@ public ResponseEntity initCurrentGenerationInfo( @AuthenticationPrincipal User user ) { val rows = adminSoptampFacade.initCurrentGenerationInfo(user); - return ResponseEntity.status(HttpStatus.OK).body(Rows.builder().rows(rows).build()); + return ResponseEntity.status(HttpStatus.OK).body(rows); } } diff --git a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampResponse.java b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampResponse.java index 39f9f0c5..6dc25a58 100644 --- a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampResponse.java +++ b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampResponse.java @@ -14,7 +14,11 @@ public class AdminSoptampResponse { @Builder public static class Rows { - @Schema(description = "초기화 성공 회원 수", example = "200") - private int rows; + @Schema(description = "SoptampUser 초기화 성공 회원 수", example = "200") + private int soptampUserRows; + + + @Schema(description = "SoptampPoint 초기화 성공 회원 수", example = "200") + private int soptampPointRows; } } From ce71d9e3fcc29d8b22ed45a9f8a0cad7a1ec2214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Sun, 12 May 2024 17:34:11 +0900 Subject: [PATCH 33/48] =?UTF-8?q?feat:=20admin=20validation=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/common/response/ErrorCode.java | 1 + .../sopt/app/facade/AdminSoptampFacade.java | 13 +---------- .../admin/AdminSoptampController.java | 22 ++++++++++++++++--- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/sopt/app/common/response/ErrorCode.java b/src/main/java/org/sopt/app/common/response/ErrorCode.java index 5b055a9c..a4450aa8 100644 --- a/src/main/java/org/sopt/app/common/response/ErrorCode.java +++ b/src/main/java/org/sopt/app/common/response/ErrorCode.java @@ -66,6 +66,7 @@ public enum ErrorCode { FRIENDSHIP_NOT_FOUND("해당 친구관계는 존재하지 않습니다."), // ADMIN + INVALID_APP_ADMIN_PASSWORD("잘못된 앱 어드민 패스워드입니다."), ADMIN_INIT_SOPTAMP_USER_FAILED("솝탬프 유저 초기화에 실패했습니다."), // S3 diff --git a/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java b/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java index 9f41f7cc..074a5389 100644 --- a/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java +++ b/src/main/java/org/sopt/app/facade/AdminSoptampFacade.java @@ -10,7 +10,6 @@ import org.sopt.app.application.soptamp.SoptampUserService; import org.sopt.app.application.stamp.StampService; import org.sopt.app.application.user.UserService; -import org.sopt.app.common.exception.BadRequestException; import org.sopt.app.domain.entity.User; import org.sopt.app.presentation.admin.AdminSoptampResponse; import org.sopt.app.presentation.admin.AdminSoptampResponse.Rows; @@ -29,8 +28,7 @@ public class AdminSoptampFacade { private final UserService userService; @Transactional - public void initAllMissionAndStampAndPoints(User user) { - validateAdminUser(user); + public void initAllMissionAndStampAndPoints() { missionService.deleteAll(); stampService.deleteAll(); soptampPointService.deleteAll(); @@ -39,8 +37,6 @@ public void initAllMissionAndStampAndPoints(User user) { @Transactional public AdminSoptampResponse.Rows initCurrentGenerationInfo(User user) { - validateAdminUser(user); - // 플그에서 현재 기수 멤버 아이디 조회 val currentGenerationPlaygroundIdList = playgroundAuthService.getPlayGroundUserIds(user.getPlaygroundToken()) .getUserIds(); @@ -86,11 +82,4 @@ public AdminSoptampResponse.Rows initCurrentGenerationInfo(User user) { .soptampPointRows(currentGenerationSoptampPointList.size()) .build(); } - - private void validateAdminUser(User user) { - // TODO: Admin User 구현 곧 할게요 - if (!user.getUsername().equals("주어랑")) { - throw new BadRequestException("NONO"); - } - } } diff --git a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java index 6d47dcf1..eade822f 100644 --- a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java +++ b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java @@ -6,12 +6,16 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; import lombok.val; +import org.sopt.app.common.exception.BadRequestException; +import org.sopt.app.common.response.ErrorCode; import org.sopt.app.domain.entity.User; import org.sopt.app.facade.AdminSoptampFacade; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -21,6 +25,8 @@ public class AdminSoptampController { private final AdminSoptampFacade adminSoptampFacade; + @Value("${makers.app.admin.password}") + private val adminPassword; @Operation(summary = "미션/스탬프/포인트 전체 초기화") @ApiResponses({ @@ -30,9 +36,11 @@ public class AdminSoptampController { }) @DeleteMapping(value = "/point") public ResponseEntity initAllMissionAndStampAndPoints( - @AuthenticationPrincipal User user + @AuthenticationPrincipal User user, + @PathVariable(name = "password") String password ) { - adminSoptampFacade.initAllMissionAndStampAndPoints(user); + validateAdmin(password); + adminSoptampFacade.initAllMissionAndStampAndPoints(); return ResponseEntity.status(HttpStatus.OK).body(null); } @@ -44,9 +52,17 @@ public ResponseEntity initAllMissionAndStampAndPoints( }) @DeleteMapping(value = "/user") public ResponseEntity initCurrentGenerationInfo( - @AuthenticationPrincipal User user + @AuthenticationPrincipal User user, + @PathVariable(name = "password") String password ) { + validateAdmin(password); val rows = adminSoptampFacade.initCurrentGenerationInfo(user); return ResponseEntity.status(HttpStatus.OK).body(rows); } + + private void validateAdmin(String password) { + if (!password.equals(adminPassword)) { + throw new BadRequestException(ErrorCode.INVALID_APP_ADMIN_PASSWORD.getMessage()); + } + } } From 8591364fddf2021a30b33fb2d2c5b89c894bfeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Sun, 12 May 2024 23:27:47 +0900 Subject: [PATCH 34/48] =?UTF-8?q?feat:=20admin=20validation=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/presentation/admin/AdminSoptampController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java index eade822f..3335f441 100644 --- a/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java +++ b/src/main/java/org/sopt/app/presentation/admin/AdminSoptampController.java @@ -15,8 +15,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -26,7 +26,7 @@ public class AdminSoptampController { private final AdminSoptampFacade adminSoptampFacade; @Value("${makers.app.admin.password}") - private val adminPassword; + private String adminPassword; @Operation(summary = "미션/스탬프/포인트 전체 초기화") @ApiResponses({ @@ -37,7 +37,7 @@ public class AdminSoptampController { @DeleteMapping(value = "/point") public ResponseEntity initAllMissionAndStampAndPoints( @AuthenticationPrincipal User user, - @PathVariable(name = "password") String password + @RequestParam(name = "password") String password ) { validateAdmin(password); adminSoptampFacade.initAllMissionAndStampAndPoints(); @@ -53,7 +53,7 @@ public ResponseEntity initAllMissionAndStampAndPoints( @DeleteMapping(value = "/user") public ResponseEntity initCurrentGenerationInfo( @AuthenticationPrincipal User user, - @PathVariable(name = "password") String password + @RequestParam(name = "password") String password ) { validateAdmin(password); val rows = adminSoptampFacade.initCurrentGenerationInfo(user); From 77b667148ad79abfbc35ee729794c243abdc6031 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 14 May 2024 21:22:48 +0900 Subject: [PATCH 35/48] =?UTF-8?q?modify:=20=ED=94=8C=EA=B7=B8=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=20=ED=94=84=EB=A1=9C=ED=95=84=EC=9D=84=20=EB=B0=9B?= =?UTF-8?q?=EC=95=84=EC=98=A4=EA=B8=B0=20=EC=9C=84=ED=95=B4=20=ED=94=8C?= =?UTF-8?q?=EA=B7=B8=20=EC=95=84=EC=9D=B4=EB=94=94=EB=A5=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EB=A1=9C=20=EC=9A=94=EC=B2=AD=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/PlaygroundAuthService.java | 18 +++++++++--------- .../org/sopt/app/facade/DescriptionFacade.java | 2 +- .../java/org/sopt/app/facade/UserFacade.java | 3 ++- .../interfaces/external/PlaygroundClient.java | 4 ++-- .../user/UserOriginalController.java | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java index ab20e65c..b81d8166 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java @@ -32,7 +32,7 @@ public class PlaygroundAuthService { public PlaygroundAuthInfo.PlaygroundMain getPlaygroundInfo(String token) { val member = this.getPlaygroundMember(token); - val playgroundProfile = this.getPlaygroundMemberProfile(token); + val playgroundProfile = this.getPlaygroundMemberProfile(token, member.getId()); val generationList = playgroundProfile.getActivities().stream() .map(activity -> activity.getCardinalActivities().get(0).getGeneration()).collect(Collectors.toList()); member.setAccessToken(token); @@ -74,12 +74,12 @@ public PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(AppAuthRequest.A } } - public PlaygroundAuthInfo.MainView getPlaygroundUserForMainView(String accessToken) { - val playgroundProfile = this.getPlaygroundMemberProfile(accessToken); + public PlaygroundAuthInfo.MainView getPlaygroundUserForMainView(String accessToken, Long playgroundId) { + val playgroundProfile = this.getPlaygroundMemberProfile(accessToken, playgroundId); val profileImage = playgroundProfile.getProfileImage() == null ? "" : playgroundProfile.getProfileImage(); val generationList = playgroundProfile.getActivities().stream() - .map(activity -> activity.getCardinalActivities().get(0).getGeneration()).collect(Collectors.toList()); - Collections.sort(generationList, Collections.reverseOrder()); + .map(activity -> activity.getCardinalActivities().get(0).getGeneration()) + .sorted(Collections.reverseOrder()).toList(); val mainViewUser = PlaygroundAuthInfo.MainViewUser.builder() .status(this.getStatus(generationList)) .name(playgroundProfile.getName()) @@ -93,11 +93,11 @@ private UserStatus getStatus(List generationList) { return generationList.contains(currentGeneration) ? UserStatus.ACTIVE : UserStatus.INACTIVE; } - private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String accessToken) { + private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String accessToken, Long playgroundId) { Map headers = createDefaultHeader(); headers.put("Authorization", accessToken); try { - return playgroundClient.getPlaygroundMemberProfile(headers); + return playgroundClient.getPlaygroundMemberProfile(headers, playgroundId); } catch (BadRequest e) { throw new BadRequestException(ErrorCode.PLAYGROUND_PROFILE_NOT_EXISTS.getMessage()); } catch (ExpiredJwtException e) { @@ -105,8 +105,8 @@ private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String a } } - public PlaygroundAuthInfo.UserActiveInfo getPlaygroundUserActiveInfo(String accessToken) { - val playgroundProfile = this.getPlaygroundMemberProfile(accessToken); + public PlaygroundAuthInfo.UserActiveInfo getPlaygroundUserActiveInfo(String accessToken, Long playgroundId) { + val playgroundProfile = this.getPlaygroundMemberProfile(accessToken, playgroundId); val generationList = playgroundProfile.getActivities().stream() .map(activity -> activity.getCardinalActivities().get(0).getGeneration()).toList(); val userStatus = this.getStatus(generationList); diff --git a/src/main/java/org/sopt/app/facade/DescriptionFacade.java b/src/main/java/org/sopt/app/facade/DescriptionFacade.java index 6fd0d795..86ea0cbb 100644 --- a/src/main/java/org/sopt/app/facade/DescriptionFacade.java +++ b/src/main/java/org/sopt/app/facade/DescriptionFacade.java @@ -18,7 +18,7 @@ public class DescriptionFacade { @Transactional(readOnly = true) public MainDescription getMainDescriptionForUser(User user) { - val userActiveInfo = playgroundAuthService.getPlaygroundUserActiveInfo(user.getPlaygroundToken()); + val userActiveInfo = playgroundAuthService.getPlaygroundUserActiveInfo(user.getPlaygroundToken(), user.getPlaygroundId()); return descriptionService.getMainDescription(userActiveInfo.getStatus()); } } diff --git a/src/main/java/org/sopt/app/facade/UserFacade.java b/src/main/java/org/sopt/app/facade/UserFacade.java index 0aa52310..61a259a0 100644 --- a/src/main/java/org/sopt/app/facade/UserFacade.java +++ b/src/main/java/org/sopt/app/facade/UserFacade.java @@ -25,7 +25,8 @@ public class UserFacade { @Transactional(readOnly = true) public MainView getMainViewInfo(User user) { - val mainViewUser = playgroundAuthService.getPlaygroundUserForMainView(user.getPlaygroundToken()); + val mainViewUser = playgroundAuthService.getPlaygroundUserForMainView(user.getPlaygroundToken(), + user.getPlaygroundId()); val dummyOperation = OperationInfo.MainView.builder().announcement("공지다!").attendanceScore(2D).build(); val mainViewNotification = notificationService.getNotificationConfirmStatus(user); return userResponseMapper.ofMainView(mainViewUser, dummyOperation, mainViewNotification); diff --git a/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java b/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java index 0eeec703..e80d0f94 100644 --- a/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java +++ b/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java @@ -18,8 +18,8 @@ public interface PlaygroundClient { @RequestLine("GET /internal/api/v1/members/me") PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(@HeaderMap Map headers); - @RequestLine("GET /internal/api/v1/members/profile/me") - PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(@HeaderMap Map headers); + @RequestLine("GET /internal/api/v1/members/profile?memberIds={memberId}") + PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(@HeaderMap Map headers, @Param("memberId") Long playgroundId); @RequestLine("POST /internal/api/v1/idp/auth/token") PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(@HeaderMap Map headers, AppAuthRequest.AccessTokenRequest tokenRequest); diff --git a/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java b/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java index 74a98d51..82ee1488 100644 --- a/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java +++ b/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java @@ -55,7 +55,7 @@ public ResponseEntity getGenerationInfo( @AuthenticationPrincipal User user ) { val generationUser = playgroundAuthService.getPlaygroundUserActiveInfo( - user.getPlaygroundToken()); + user.getPlaygroundToken(), user.getPlaygroundId()); val response = userResponseMapper.ofGeneration(generationUser); return ResponseEntity.status(HttpStatus.OK).body(response); } From 460c9d6edbc186544dd6cc496d74c0ce09537fc5 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 14 May 2024 21:23:11 +0900 Subject: [PATCH 36/48] =?UTF-8?q?modify:=20=ED=94=8C=EA=B7=B8=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=20=ED=94=84=EB=A1=9C=ED=95=84=EC=9D=84=20=EB=B0=9B?= =?UTF-8?q?=EC=95=84=EC=98=A4=EA=B8=B0=20=EC=9C=84=ED=95=B4=20=ED=94=8C?= =?UTF-8?q?=EA=B7=B8=20=EC=95=84=EC=9D=B4=EB=94=94=EB=A5=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EB=A1=9C=20=EC=9A=94=EC=B2=AD=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=8B=A4=ED=8C=A8=ED=95=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlaygroundAuthServiceTest.java | 32 ++++++++++--------- .../app/facade/DescriptionFacadeTest.java | 12 ++++--- .../org/sopt/app/facade/UserFacadeTest.java | 4 ++- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java index e7a03514..9f542bed 100644 --- a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java +++ b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java @@ -1,6 +1,7 @@ package org.sopt.app.application; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; import io.jsonwebtoken.ExpiredJwtException; @@ -62,9 +63,10 @@ void SUCCESS_getPlaygroundInfo() { playgroundProfile.setName("name"); PlaygroundMain playgroundMain = new PlaygroundMain(); playgroundMain.setName("name"); + playgroundMain.setId(1L); when(playgroundClient.getPlaygroundMember(any())).thenReturn(playgroundMain); - when(playgroundClient.getPlaygroundMemberProfile(any())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); PlaygroundMain result = playgroundAuthService.getPlaygroundInfo(token); Assertions.assertEquals(token, result.getAccessToken()); @@ -173,9 +175,9 @@ void SUCCESS_getPlaygroundUserForMainViewWithProfileImage() { MainViewUser mainViewUser = MainViewUser.builder().name("name").profileImage("profileImage").build(); MainView mainView = MainView.builder().user(mainViewUser).build(); - when(playgroundClient.getPlaygroundMemberProfile(any())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); - MainView result = playgroundAuthService.getPlaygroundUserForMainView(token); + MainView result = playgroundAuthService.getPlaygroundUserForMainView(token, 1L); Assertions.assertEquals(mainView.getUser().getName(), result.getUser().getName()); } @@ -193,9 +195,9 @@ void SUCCESS_getPlaygroundUserForMainViewWithoutProfileImage() { MainViewUser mainViewUser = MainViewUser.builder().name("name").profileImage("").build(); MainView mainView = MainView.builder().user(mainViewUser).build(); - when(playgroundClient.getPlaygroundMemberProfile(any())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); - MainView result = playgroundAuthService.getPlaygroundUserForMainView(token); + MainView result = playgroundAuthService.getPlaygroundUserForMainView(token, 1L); Assertions.assertEquals(mainView.getUser().getName(), result.getUser().getName()); Assertions.assertEquals(mainView.getUser().getProfileImage(), result.getUser().getProfileImage()); } @@ -211,9 +213,9 @@ void SUCCESS_getPlaygroundUserActiveInfoActive() { PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of(playgroundActivity)); - when(playgroundClient.getPlaygroundMemberProfile(any())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); - UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token); + UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); Assertions.assertEquals(UserStatus.ACTIVE, result.getStatus()); } @@ -227,9 +229,9 @@ void SUCCESS_getPlaygroundUserActiveInfoInactive() { PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of()); - when(playgroundClient.getPlaygroundMemberProfile(any())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); - UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token); + UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); Assertions.assertEquals(UserStatus.INACTIVE, result.getStatus()); } @@ -241,29 +243,29 @@ void SUCCESS_getPlaygroundUserActiveInfoEmptyList() { PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of()); - when(playgroundClient.getPlaygroundMemberProfile(any())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); - UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token); + UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); Assertions.assertEquals(UserStatus.INACTIVE, result.getStatus()); } @Test @DisplayName("FAIL_플레이그라운드 프로필을 등록하지 않은 유저 활동 정보 조회 BadRequestException") void FAIL_getPlaygroundUserActiveInfoNotRegisteredBadRequestException() { - when(playgroundClient.getPlaygroundMemberProfile(any())).thenThrow(BadRequest.class); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenThrow(BadRequest.class); Assertions.assertThrows(BadRequestException.class, () -> { - playgroundAuthService.getPlaygroundUserActiveInfo(token); + playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); }); } @Test @DisplayName("FAIL_플레이그라운드 토큰이 만료된 유저 활동 정보 조회 UnauthorizedException") void FAIL_getPlaygroundUserActiveInfoExpiredJwtUnauthorizedException() { - when(playgroundClient.getPlaygroundMemberProfile(any())).thenThrow(ExpiredJwtException.class); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenThrow(ExpiredJwtException.class); Assertions.assertThrows(UnauthorizedException.class, () -> { - playgroundAuthService.getPlaygroundUserActiveInfo(token); + playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); }); } diff --git a/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java b/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java index 63d054b5..decb829e 100644 --- a/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java @@ -1,6 +1,8 @@ package org.sopt.app.facade; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -33,14 +35,15 @@ public class DescriptionFacadeTest { @Test @DisplayName("SUCCESS_활동 유저 메인 문구 조회") void SUCCESS_getMainDescriptionForUserActive() { + User user = User.builder().playgroundId(1L).playgroundToken("token").build(); UserStatus userStatus = UserStatus.ACTIVE; - Mockito.when(playgroundAuthService.getPlaygroundUserActiveInfo(any())) + Mockito.when(playgroundAuthService.getPlaygroundUserActiveInfo(anyString(), anyLong())) .thenReturn(UserActiveInfo.builder().currentGeneration(34L).status(userStatus).build()); Mockito.when(descriptionService.getMainDescription(userStatus)) .thenReturn(DescriptionInfo.MainDescription.builder().topDescription("activeTop") .bottomDescription("activeBottom").build()); - MainDescription result = descriptionFacade.getMainDescriptionForUser(new User()); + MainDescription result = descriptionFacade.getMainDescriptionForUser(user); Assertions.assertEquals("activeTop", result.getTopDescription()); Assertions.assertEquals("activeBottom", result.getBottomDescription()); } @@ -48,14 +51,15 @@ void SUCCESS_getMainDescriptionForUserActive() { @Test @DisplayName("SUCCESS_비활동 유저 메인 문구 조회") void SUCCESS_getMainDescriptionForUserInactive() { + User user = User.builder().playgroundId(1L).playgroundToken("token").build(); UserStatus userStatus = UserStatus.INACTIVE; - Mockito.when(playgroundAuthService.getPlaygroundUserActiveInfo(any())) + Mockito.when(playgroundAuthService.getPlaygroundUserActiveInfo(anyString(), anyLong())) .thenReturn(UserActiveInfo.builder().currentGeneration(29L).status(userStatus).build()); Mockito.when(descriptionService.getMainDescription(userStatus)) .thenReturn(DescriptionInfo.MainDescription.builder().topDescription("inactiveTop") .bottomDescription("inactiveBottom").build()); - MainDescription result = descriptionFacade.getMainDescriptionForUser(new User()); + MainDescription result = descriptionFacade.getMainDescriptionForUser(user); Assertions.assertEquals("inactiveTop", result.getTopDescription()); Assertions.assertEquals("inactiveBottom", result.getBottomDescription()); } diff --git a/src/test/java/org/sopt/app/facade/UserFacadeTest.java b/src/test/java/org/sopt/app/facade/UserFacadeTest.java index 48b26fae..f17bf4a8 100644 --- a/src/test/java/org/sopt/app/facade/UserFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/UserFacadeTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; @@ -50,7 +51,7 @@ void getMainViewInfo() { .build(); //when - when(playgroundAuthService.getPlaygroundUserForMainView(anyString())).thenReturn(playgroundAuthInfo); + when(playgroundAuthService.getPlaygroundUserForMainView(anyString(), anyLong())).thenReturn(playgroundAuthInfo); when(notificationService.getNotificationConfirmStatus(any(User.class))).thenReturn(isNotificationConfirm); when(userResponseMapper.ofMainView(any(MainView.class), any(OperationInfo.MainView.class), anyBoolean())).thenReturn(mainViewResponse); @@ -63,6 +64,7 @@ void getMainViewInfo() { UserResponse.MainView result = userFacade.getMainViewInfo( User.builder() .playgroundToken(anyString()) + .playgroundId(anyLong()) .build() ); From 98c058dfb483ae129bb59c529d0fa73dcc82a43e Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 14 May 2024 22:36:06 +0900 Subject: [PATCH 37/48] =?UTF-8?q?modify:=20PlaygroundActivity=20DTO?= =?UTF-8?q?=EC=97=90=EC=84=9C=20cardinalActivities=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/auth/PlaygroundAuthInfo.java | 1 - .../auth/PlaygroundAuthService.java | 24 +++++++++++++------ .../sopt/app/common/response/ErrorCode.java | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java index 597e2889..261afb61 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java @@ -62,7 +62,6 @@ public static class PlaygroundProfile { public static class PlaygroundActivity { private String cardinalInfo; - private List cardinalActivities; } @Getter diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java index b81d8166..0a77865b 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java @@ -33,8 +33,7 @@ public class PlaygroundAuthService { public PlaygroundAuthInfo.PlaygroundMain getPlaygroundInfo(String token) { val member = this.getPlaygroundMember(token); val playgroundProfile = this.getPlaygroundMemberProfile(token, member.getId()); - val generationList = playgroundProfile.getActivities().stream() - .map(activity -> activity.getCardinalActivities().get(0).getGeneration()).collect(Collectors.toList()); + val generationList = this.getMemberGenerationList(playgroundProfile); member.setAccessToken(token); member.setStatus(this.getStatus(generationList)); return member; @@ -77,9 +76,7 @@ public PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(AppAuthRequest.A public PlaygroundAuthInfo.MainView getPlaygroundUserForMainView(String accessToken, Long playgroundId) { val playgroundProfile = this.getPlaygroundMemberProfile(accessToken, playgroundId); val profileImage = playgroundProfile.getProfileImage() == null ? "" : playgroundProfile.getProfileImage(); - val generationList = playgroundProfile.getActivities().stream() - .map(activity -> activity.getCardinalActivities().get(0).getGeneration()) - .sorted(Collections.reverseOrder()).toList(); + val generationList = this.getMemberGenerationList(playgroundProfile); val mainViewUser = PlaygroundAuthInfo.MainViewUser.builder() .status(this.getStatus(generationList)) .name(playgroundProfile.getName()) @@ -107,8 +104,7 @@ private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String a public PlaygroundAuthInfo.UserActiveInfo getPlaygroundUserActiveInfo(String accessToken, Long playgroundId) { val playgroundProfile = this.getPlaygroundMemberProfile(accessToken, playgroundId); - val generationList = playgroundProfile.getActivities().stream() - .map(activity -> activity.getCardinalActivities().get(0).getGeneration()).toList(); + val generationList = this.getMemberGenerationList(playgroundProfile); val userStatus = this.getStatus(generationList); return PlaygroundAuthInfo.UserActiveInfo.builder() .status(userStatus) @@ -116,6 +112,20 @@ public PlaygroundAuthInfo.UserActiveInfo getPlaygroundUserActiveInfo(String acce .build(); } + private List getMemberGenerationList(PlaygroundAuthInfo.PlaygroundProfile playgroundProfile) { + return playgroundProfile.getActivities().stream() + .map(activity -> + { + try { + return Long.parseLong(activity.getCardinalInfo().split(",")[0]); + } catch (NumberFormatException e){ + throw new BadRequestException(ErrorCode.INVALID_PLAYGROUND_CARDINAL_INFO.getMessage()); + } + }) + .sorted(Collections.reverseOrder()) + .toList(); + } + // Header 생성 메서드 private Map createDefaultHeader() { return new HashMap<>(Map.of("content-type", "application/json;charset=UTF-8")); diff --git a/src/main/java/org/sopt/app/common/response/ErrorCode.java b/src/main/java/org/sopt/app/common/response/ErrorCode.java index 5b055a9c..cc25d370 100644 --- a/src/main/java/org/sopt/app/common/response/ErrorCode.java +++ b/src/main/java/org/sopt/app/common/response/ErrorCode.java @@ -19,6 +19,7 @@ public enum ErrorCode { // PLAYGROUND PLAYGROUND_USER_NOT_EXISTS("플레이그라운드 유저 정보를 가져올 수 없습니다."), PLAYGROUND_PROFILE_NOT_EXISTS("플레이그라운드 프로필을 등록하지 않은 유저입니다."), + INVALID_PLAYGROUND_CARDINAL_INFO("플레이그라운드 활동 정보가 유효하지 않습니다."), // OPERATION OPERATION_PROFILE_NOT_EXISTS("운영 서비스에 존재하지 않는 회원입니다."), From 6c0339a1dd6114537b02b05009c369002f99e657 Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 14 May 2024 23:02:57 +0900 Subject: [PATCH 38/48] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20DTO=20=EC=82=AD=EC=A0=9C=20(#2?= =?UTF-8?q?16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/application/auth/PlaygroundAuthInfo.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java index 261afb61..43a6075d 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -13,6 +12,7 @@ import lombok.ToString; import org.sopt.app.domain.enums.UserStatus; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class PlaygroundAuthInfo { @Getter @@ -64,18 +64,6 @@ public static class PlaygroundActivity { private String cardinalInfo; } - @Getter - @Setter - @ToString - public static class PlaygroundCardinalActivity { - - private Long id; - private Long generation; - private String team; - private String part; - private Boolean isProject; - } - @Getter @Builder @ToString @@ -147,7 +135,7 @@ public static class MemberProfile { public ActivityCardinalInfo getLatestActivity() { return activities.stream() .sorted(Comparator.comparing(ActivityCardinalInfo::getGeneration, Comparator.reverseOrder())) - .collect(Collectors.toList()) + .toList() .get(0); } } From 5b07523fb3e24dfcfb3c17440ccc7dca1b058f3e Mon Sep 17 00:00:00 2001 From: kseysh Date: Tue, 14 May 2024 23:06:39 +0900 Subject: [PATCH 39/48] =?UTF-8?q?modify:=20DTO=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=8B=A4=ED=8C=A8=ED=95=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=93=A4=20=EC=88=98=EC=A0=95=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlaygroundAuthServiceTest.java | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java index 9f542bed..9c40ddad 100644 --- a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java +++ b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java @@ -5,9 +5,7 @@ import static org.mockito.Mockito.when; import io.jsonwebtoken.ExpiredJwtException; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -21,7 +19,6 @@ import org.sopt.app.application.auth.PlaygroundAuthInfo.MainViewUser; import org.sopt.app.application.auth.PlaygroundAuthInfo.MemberProfile; import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundActivity; -import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundCardinalActivity; import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundMain; import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile; import org.sopt.app.application.auth.PlaygroundAuthInfo.RefreshedToken; @@ -33,30 +30,28 @@ import org.sopt.app.interfaces.external.PlaygroundClient; import org.sopt.app.presentation.auth.AppAuthRequest.AccessTokenRequest; import org.sopt.app.presentation.auth.AppAuthRequest.CodeRequest; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.client.HttpClientErrorException.BadRequest; @ExtendWith(MockitoExtension.class) -public class PlaygroundAuthServiceTest { +class PlaygroundAuthServiceTest { @Mock private PlaygroundClient playgroundClient; @InjectMocks private PlaygroundAuthService playgroundAuthService; - private String token = "header.payload.signature"; - private Map createDefaultHeader() { - return new HashMap<>(Map.of("content-type", "application/json;charset=UTF-8")); - } + private final String token = "header.payload.signature"; // getPlaygroundInfo @Test @DisplayName("SUCCESS_플레이그라운드 정보 조회") void SUCCESS_getPlaygroundInfo() { + // given String token = "token"; - PlaygroundCardinalActivity playgroundCardinalActivity = new PlaygroundCardinalActivity(); PlaygroundActivity playgroundActivity = new PlaygroundActivity(); - playgroundActivity.setCardinalActivities(List.of(playgroundCardinalActivity)); + playgroundActivity.setCardinalInfo("29,서버"); PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of(playgroundActivity)); playgroundProfile.setProfileImage("profileImage"); @@ -65,13 +60,15 @@ void SUCCESS_getPlaygroundInfo() { playgroundMain.setName("name"); playgroundMain.setId(1L); + // when when(playgroundClient.getPlaygroundMember(any())).thenReturn(playgroundMain); when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); - PlaygroundMain result = playgroundAuthService.getPlaygroundInfo(token); + + // then Assertions.assertEquals(token, result.getAccessToken()); Assertions.assertEquals(playgroundMain.getName(), result.getName()); - Assertions.assertEquals(UserStatus.ACTIVE, result.getStatus()); + Assertions.assertEquals(UserStatus.INACTIVE, result.getStatus()); } @Test @@ -164,10 +161,8 @@ void FAIL_refreshPlaygroundTokenExpiredJwtUnauthorizedException() { @Test @DisplayName("SUCCESS_플레이그라운드 이미지 있는 유저 메인 뷰 조회") void SUCCESS_getPlaygroundUserForMainViewWithProfileImage() { - PlaygroundCardinalActivity playgroundCardinalActivity = new PlaygroundCardinalActivity(); - playgroundCardinalActivity.setGeneration(null); PlaygroundActivity playgroundActivity = new PlaygroundActivity(); - playgroundActivity.setCardinalActivities(List.of(playgroundCardinalActivity)); + playgroundActivity.setCardinalInfo("29,서버"); PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of(playgroundActivity)); playgroundProfile.setProfileImage("profileImage"); @@ -184,10 +179,8 @@ void SUCCESS_getPlaygroundUserForMainViewWithProfileImage() { @Test @DisplayName("SUCCESS_플레이그라운드 이미지 없는 유저 메인 뷰 조회") void SUCCESS_getPlaygroundUserForMainViewWithoutProfileImage() { - PlaygroundCardinalActivity playgroundCardinalActivity = new PlaygroundCardinalActivity(); - playgroundCardinalActivity.setGeneration(null); PlaygroundActivity playgroundActivity = new PlaygroundActivity(); - playgroundActivity.setCardinalActivities(List.of(playgroundCardinalActivity)); + playgroundActivity.setCardinalInfo("1,서버"); PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of(playgroundActivity)); playgroundProfile.setProfileImage(null); @@ -206,26 +199,24 @@ void SUCCESS_getPlaygroundUserForMainViewWithoutProfileImage() { @Test @DisplayName("SUCCESS_플레이그라운드 활동 유저 활동 정보 조회") void SUCCESS_getPlaygroundUserActiveInfoActive() { - PlaygroundCardinalActivity playgroundCardinalActivity = new PlaygroundCardinalActivity(); - playgroundCardinalActivity.setGeneration(null); + // given PlaygroundActivity playgroundActivity = new PlaygroundActivity(); - playgroundActivity.setCardinalActivities(List.of(playgroundCardinalActivity)); + playgroundActivity.setCardinalInfo("1,서버"); PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of(playgroundActivity)); + ReflectionTestUtils.setField(playgroundAuthService, "currentGeneration", 1L); + // when when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); - UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); + + // then Assertions.assertEquals(UserStatus.ACTIVE, result.getStatus()); } @Test @DisplayName("SUCCESS_플레이그라운드 비활동 유저 활동 정보 조회") void SUCCESS_getPlaygroundUserActiveInfoInactive() { - PlaygroundCardinalActivity playgroundCardinalActivity = new PlaygroundCardinalActivity(); - playgroundCardinalActivity.setGeneration(0L); - PlaygroundActivity playgroundActivity = new PlaygroundActivity(); - playgroundActivity.setCardinalActivities(List.of(playgroundCardinalActivity)); PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of()); @@ -238,8 +229,6 @@ void SUCCESS_getPlaygroundUserActiveInfoInactive() { @Test @DisplayName("SUCCESS_플레이그라운드 엠티 유저 활동 정보 조회") void SUCCESS_getPlaygroundUserActiveInfoEmptyList() { - PlaygroundActivity playgroundActivity = new PlaygroundActivity(); - playgroundActivity.setCardinalActivities(List.of()); PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of()); @@ -286,9 +275,6 @@ void SUCCESS_getPlayGroundUserIds() { @Test @DisplayName("FAIL_플레이그라운드 프로필을 등록하지 않은 유저 아이디 조회 BadRequestException") void FAIL_getPlayGroundUserIdsNotRegisteredBadRequestException() { - PlaygroundAuthInfo.ActiveUserIds userIds = new ActiveUserIds(); - userIds.setUserIds(List.of(1L)); - when(playgroundClient.getPlaygroundUserIds(any(), any())).thenThrow(BadRequest.class); Assertions.assertThrows(BadRequestException.class, () -> { From 1fd66fd61bc45c1a139911de882a65b7038751e3 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 15 May 2024 18:10:30 +0900 Subject: [PATCH 40/48] =?UTF-8?q?refactor:=20catch=EB=B8=94=EB=A1=9D=20?= =?UTF-8?q?=EA=B0=80=EB=8F=85=EC=84=B1=20=EC=A2=8B=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/application/auth/PlaygroundAuthService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java index 0a77865b..df814917 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java @@ -66,11 +66,9 @@ public PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(AppAuthRequest.A headers.put("x-request-from", requestFrom); try { return playgroundClient.refreshPlaygroundToken(headers, tokenRequest); - } catch (BadRequest badRequest) { + } catch (BadRequest | ExpiredJwtException badRequest) { throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage()); - } catch (ExpiredJwtException e) { - throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage()); - } + } } public PlaygroundAuthInfo.MainView getPlaygroundUserForMainView(String accessToken, Long playgroundId) { From 54d086e7d4bdf58434a7a26b5731d64531457d6a Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 15 May 2024 18:22:21 +0900 Subject: [PATCH 41/48] =?UTF-8?q?refactor:=20String=20=EA=B0=92=20?= =?UTF-8?q?=EC=83=81=EC=88=98=EB=A1=9C=20=EC=88=98=EC=A0=95=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/PlaygroundAuthService.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java index df814917..62fc49fa 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java @@ -1,7 +1,6 @@ package org.sopt.app.application.auth; import io.jsonwebtoken.ExpiredJwtException; - import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.*; @@ -15,6 +14,8 @@ import org.sopt.app.interfaces.external.PlaygroundClient; import org.sopt.app.presentation.auth.AppAuthRequest; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.web.client.HttpClientErrorException.BadRequest; @@ -50,7 +51,7 @@ public AppAuthRequest.AccessTokenRequest getPlaygroundAccessToken(AppAuthRequest private PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(String accessToken) { Map headers = createDefaultHeader(); - headers.put("Authorization", accessToken); + headers.put(HttpHeaders.AUTHORIZATION, accessToken); try { return playgroundClient.getPlaygroundMember(headers); } catch (ExpiredJwtException e) { @@ -90,7 +91,7 @@ private UserStatus getStatus(List generationList) { private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String accessToken, Long playgroundId) { Map headers = createDefaultHeader(); - headers.put("Authorization", accessToken); + headers.put(HttpHeaders.AUTHORIZATION, accessToken); try { return playgroundClient.getPlaygroundMemberProfile(headers, playgroundId); } catch (BadRequest e) { @@ -113,25 +114,25 @@ public PlaygroundAuthInfo.UserActiveInfo getPlaygroundUserActiveInfo(String acce private List getMemberGenerationList(PlaygroundAuthInfo.PlaygroundProfile playgroundProfile) { return playgroundProfile.getActivities().stream() .map(activity -> - { - try { - return Long.parseLong(activity.getCardinalInfo().split(",")[0]); - } catch (NumberFormatException e){ - throw new BadRequestException(ErrorCode.INVALID_PLAYGROUND_CARDINAL_INFO.getMessage()); - } - }) + { + try { + return Long.parseLong(activity.getCardinalInfo().split(",")[0]); + } catch (NumberFormatException e) { + throw new BadRequestException(ErrorCode.INVALID_PLAYGROUND_CARDINAL_INFO.getMessage()); + } + }) .sorted(Collections.reverseOrder()) .toList(); } // Header 생성 메서드 private Map createDefaultHeader() { - return new HashMap<>(Map.of("content-type", "application/json;charset=UTF-8")); + return new HashMap<>(Map.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)); } public PlaygroundAuthInfo.ActiveUserIds getPlayGroundUserIds(String accessToken) { Map headers = createDefaultHeader(); - headers.put("Authorization", accessToken); + headers.put(HttpHeaders.AUTHORIZATION, accessToken); try { return playgroundClient.getPlaygroundUserIds(headers, currentGeneration); } catch (BadRequest e) { @@ -141,14 +142,16 @@ public PlaygroundAuthInfo.ActiveUserIds getPlayGroundUserIds(String accessToken) } } - public List getPlaygroundMemberProfiles(String accessToken, List memberIds) { + public List getPlaygroundMemberProfiles(String accessToken, + List memberIds) { Map defaultHeader = createDefaultHeader(); - defaultHeader.put("Authorization", accessToken); + defaultHeader.put(HttpHeaders.AUTHORIZATION, accessToken); String stringifyIds = memberIds.stream() .map(String::valueOf) .collect(Collectors.joining(",")); try { - return playgroundClient.getMemberProfiles(defaultHeader, URLEncoder.encode(stringifyIds, StandardCharsets.UTF_8)); + return playgroundClient.getMemberProfiles(defaultHeader, + URLEncoder.encode(stringifyIds, StandardCharsets.UTF_8)); } catch (BadRequest e) { throw new BadRequestException(ErrorCode.PLAYGROUND_PROFILE_NOT_EXISTS.getMessage()); } catch (ExpiredJwtException e) { From 60e121053522eab597d765e12ce5741a568e51be Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 15 May 2024 18:24:59 +0900 Subject: [PATCH 42/48] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=9D=B8=EC=88=98=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/app/presentation/user/UserOriginalController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java b/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java index 82ee1488..4d39e803 100644 --- a/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java +++ b/src/main/java/org/sopt/app/presentation/user/UserOriginalController.java @@ -67,9 +67,7 @@ public ResponseEntity getGenerationInfo( @ApiResponse(responseCode = "500", description = "server error", content = @Content) }) @GetMapping(value = "/app-service") - public ResponseEntity> getAppServiceInfo( - @AuthenticationPrincipal User user - ) { + public ResponseEntity> getAppServiceInfo() { val response = userFacade.getAppServiceInfo(); return ResponseEntity.status(HttpStatus.OK).body(response); } From 0dcc21d5726d9da665ae398de29d3a3cb78952ad Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 15 May 2024 18:25:22 +0900 Subject: [PATCH 43/48] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=A0=91=EA=B7=BC=20=EC=A0=9C?= =?UTF-8?q?=EC=96=B4=EC=9E=90=20=EC=A0=9C=EA=B1=B0=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java b/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java index decb829e..4d22f8ea 100644 --- a/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java +++ b/src/test/java/org/sopt/app/facade/DescriptionFacadeTest.java @@ -21,7 +21,7 @@ import org.sopt.app.domain.enums.UserStatus; @ExtendWith(MockitoExtension.class) -public class DescriptionFacadeTest { +class DescriptionFacadeTest { @Mock private DescriptionService descriptionService; From 23241ce70bab5945437a20443ddbdbb1645618d6 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 15 May 2024 18:28:30 +0900 Subject: [PATCH 44/48] =?UTF-8?q?refactor:=20=EB=9E=8C=EB=8B=A4=EB=AC=B8?= =?UTF-8?q?=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EC=A4=91=EA=B4=84?= =?UTF-8?q?=ED=98=B8=20=EC=A0=9C=EA=B1=B0=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlaygroundAuthServiceTest.java | 54 +++++++------------ 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java index 9c40ddad..486677d3 100644 --- a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java +++ b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java @@ -76,9 +76,7 @@ void SUCCESS_getPlaygroundInfo() { void FAIL_getPlaygroundInfoBadRequestException() { when(playgroundClient.getPlaygroundMember(any())).thenThrow(BadRequest.class); - Assertions.assertThrows(BadRequestException.class, () -> { - playgroundAuthService.getPlaygroundInfo(token); - }); + Assertions.assertThrows(BadRequestException.class, () -> playgroundAuthService.getPlaygroundInfo(token)); } @Test @@ -86,9 +84,7 @@ void FAIL_getPlaygroundInfoBadRequestException() { void FAIL_getPlaygroundInfoExpiredJwtUnauthorizedException() { when(playgroundClient.getPlaygroundMember(any())).thenThrow(ExpiredJwtException.class); - Assertions.assertThrows(UnauthorizedException.class, () -> { - playgroundAuthService.getPlaygroundInfo(token); - }); + Assertions.assertThrows(UnauthorizedException.class, () -> playgroundAuthService.getPlaygroundInfo(token)); } // getPlaygroundAccessToken @@ -113,9 +109,8 @@ void FAIL_getPlaygroundAccessTokenBadRequestException() { when(playgroundClient.getAccessToken(any(), any())).thenThrow(BadRequest.class); - Assertions.assertThrows(BadRequestException.class, () -> { - playgroundAuthService.getPlaygroundAccessToken(codeRequest); - }); + Assertions.assertThrows(BadRequestException.class, + () -> playgroundAuthService.getPlaygroundAccessToken(codeRequest)); } // refreshPlaygroundToken @@ -140,9 +135,8 @@ void FAIL_refreshPlaygroundTokenUnauthorizedException() { when(playgroundClient.refreshPlaygroundToken(any(), any())).thenThrow(BadRequest.class); - Assertions.assertThrows(UnauthorizedException.class, () -> { - playgroundAuthService.refreshPlaygroundToken(accessTokenRequest); - }); + Assertions.assertThrows(UnauthorizedException.class, + () -> playgroundAuthService.refreshPlaygroundToken(accessTokenRequest)); } @Test @@ -152,9 +146,8 @@ void FAIL_refreshPlaygroundTokenExpiredJwtUnauthorizedException() { when(playgroundClient.refreshPlaygroundToken(any(), any())).thenThrow(ExpiredJwtException.class); - Assertions.assertThrows(UnauthorizedException.class, () -> { - playgroundAuthService.refreshPlaygroundToken(accessTokenRequest); - }); + Assertions.assertThrows(UnauthorizedException.class, + () -> playgroundAuthService.refreshPlaygroundToken(accessTokenRequest)); } // getPlaygroundUserForMainView @@ -243,9 +236,8 @@ void SUCCESS_getPlaygroundUserActiveInfoEmptyList() { void FAIL_getPlaygroundUserActiveInfoNotRegisteredBadRequestException() { when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenThrow(BadRequest.class); - Assertions.assertThrows(BadRequestException.class, () -> { - playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); - }); + Assertions.assertThrows(BadRequestException.class, + () -> playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L)); } @Test @@ -253,9 +245,8 @@ void FAIL_getPlaygroundUserActiveInfoNotRegisteredBadRequestException() { void FAIL_getPlaygroundUserActiveInfoExpiredJwtUnauthorizedException() { when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenThrow(ExpiredJwtException.class); - Assertions.assertThrows(UnauthorizedException.class, () -> { - playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); - }); + Assertions.assertThrows(UnauthorizedException.class, + () -> playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L)); } // getPlayGroundUserIds @@ -277,22 +268,15 @@ void SUCCESS_getPlayGroundUserIds() { void FAIL_getPlayGroundUserIdsNotRegisteredBadRequestException() { when(playgroundClient.getPlaygroundUserIds(any(), any())).thenThrow(BadRequest.class); - Assertions.assertThrows(BadRequestException.class, () -> { - playgroundAuthService.getPlayGroundUserIds(token); - }); + Assertions.assertThrows(BadRequestException.class, () -> playgroundAuthService.getPlayGroundUserIds(token)); } @Test @DisplayName("FAIL_플레이그라운드 토큰이 만료된 유저 아이디 조회 UnauthorizedException") void FAIL_getPlayGroundUserIdsExpiredJwtUnauthorizedException() { - PlaygroundAuthInfo.ActiveUserIds userIds = new ActiveUserIds(); - userIds.setUserIds(List.of(1L)); - when(playgroundClient.getPlaygroundUserIds(any(), any())).thenThrow(ExpiredJwtException.class); - Assertions.assertThrows(UnauthorizedException.class, () -> { - playgroundAuthService.getPlayGroundUserIds(token); - }); + Assertions.assertThrows(UnauthorizedException.class, () -> playgroundAuthService.getPlayGroundUserIds(token)); } // getPlaygroundMemberProfiles @@ -313,9 +297,8 @@ void SUCCESS_getPlaygroundMemberProfiles() { void FAIL_getPlaygroundMemberProfilesNotRegisteredBadRequestException() { when(playgroundClient.getMemberProfiles(any(), any())).thenThrow(BadRequest.class); - Assertions.assertThrows(BadRequestException.class, () -> { - playgroundAuthService.getPlaygroundMemberProfiles(token, List.of()); - }); + Assertions.assertThrows(BadRequestException.class, + () -> playgroundAuthService.getPlaygroundMemberProfiles(token, List.of())); } @Test @@ -323,8 +306,7 @@ void FAIL_getPlaygroundMemberProfilesNotRegisteredBadRequestException() { void FAIL_getPlaygroundMemberProfilesExpiredJwtUnauthorizedException() { when(playgroundClient.getMemberProfiles(any(), any())).thenThrow(ExpiredJwtException.class); - Assertions.assertThrows(UnauthorizedException.class, () -> { - playgroundAuthService.getPlaygroundMemberProfiles(token, List.of()); - }); + Assertions.assertThrows(UnauthorizedException.class, + () -> playgroundAuthService.getPlaygroundMemberProfiles(token, List.of())); } } From d1edb757b61874da2db1c246937bd7cfe0f40b82 Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 15 May 2024 19:01:58 +0900 Subject: [PATCH 45/48] =?UTF-8?q?modify:=20member=20profile=20=EB=B0=9B?= =?UTF-8?q?=EC=A7=80=20=EB=AA=BB=ED=96=88=EB=8D=98=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sopt/app/application/auth/PlaygroundAuthInfo.java | 1 + .../org/sopt/app/application/auth/PlaygroundAuthService.java | 2 +- .../java/org/sopt/app/interfaces/external/PlaygroundClient.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java index 43a6075d..3beae8ae 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java @@ -51,6 +51,7 @@ public static class PlaygroundMain { @ToString public static class PlaygroundProfile { + private Long memberId; private String name; private String profileImage; private List activities; diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java index 62fc49fa..f092f834 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java @@ -93,7 +93,7 @@ private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String a Map headers = createDefaultHeader(); headers.put(HttpHeaders.AUTHORIZATION, accessToken); try { - return playgroundClient.getPlaygroundMemberProfile(headers, playgroundId); + return playgroundClient.getPlaygroundMemberProfile(headers, playgroundId).get(0); } catch (BadRequest e) { throw new BadRequestException(ErrorCode.PLAYGROUND_PROFILE_NOT_EXISTS.getMessage()); } catch (ExpiredJwtException e) { diff --git a/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java b/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java index e80d0f94..c527da58 100644 --- a/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java +++ b/src/main/java/org/sopt/app/interfaces/external/PlaygroundClient.java @@ -19,7 +19,7 @@ public interface PlaygroundClient { PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(@HeaderMap Map headers); @RequestLine("GET /internal/api/v1/members/profile?memberIds={memberId}") - PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(@HeaderMap Map headers, @Param("memberId") Long playgroundId); + List getPlaygroundMemberProfile(@HeaderMap Map headers, @Param("memberId") Long playgroundId); @RequestLine("POST /internal/api/v1/idp/auth/token") PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(@HeaderMap Map headers, AppAuthRequest.AccessTokenRequest tokenRequest); From ea28f85bd06d85be69e75d95687220551d30bb9a Mon Sep 17 00:00:00 2001 From: kseysh Date: Wed, 15 May 2024 19:02:14 +0900 Subject: [PATCH 46/48] =?UTF-8?q?modify:=20=EB=B3=80=EA=B2=BD=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B8=ED=95=B4=20=EC=8B=A4=ED=8C=A8=ED=95=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20(#216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlaygroundAuthServiceTest.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java index 486677d3..3ad180ff 100644 --- a/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java +++ b/src/test/java/org/sopt/app/application/PlaygroundAuthServiceTest.java @@ -62,7 +62,7 @@ void SUCCESS_getPlaygroundInfo() { // when when(playgroundClient.getPlaygroundMember(any())).thenReturn(playgroundMain); - when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); PlaygroundMain result = playgroundAuthService.getPlaygroundInfo(token); // then @@ -163,7 +163,7 @@ void SUCCESS_getPlaygroundUserForMainViewWithProfileImage() { MainViewUser mainViewUser = MainViewUser.builder().name("name").profileImage("profileImage").build(); MainView mainView = MainView.builder().user(mainViewUser).build(); - when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); MainView result = playgroundAuthService.getPlaygroundUserForMainView(token, 1L); Assertions.assertEquals(mainView.getUser().getName(), result.getUser().getName()); @@ -181,7 +181,7 @@ void SUCCESS_getPlaygroundUserForMainViewWithoutProfileImage() { MainViewUser mainViewUser = MainViewUser.builder().name("name").profileImage("").build(); MainView mainView = MainView.builder().user(mainViewUser).build(); - when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); MainView result = playgroundAuthService.getPlaygroundUserForMainView(token, 1L); Assertions.assertEquals(mainView.getUser().getName(), result.getUser().getName()); @@ -200,7 +200,7 @@ void SUCCESS_getPlaygroundUserActiveInfoActive() { ReflectionTestUtils.setField(playgroundAuthService, "currentGeneration", 1L); // when - when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); // then @@ -213,7 +213,7 @@ void SUCCESS_getPlaygroundUserActiveInfoInactive() { PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of()); - when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); Assertions.assertEquals(UserStatus.INACTIVE, result.getStatus()); @@ -225,7 +225,7 @@ void SUCCESS_getPlaygroundUserActiveInfoEmptyList() { PlaygroundAuthInfo.PlaygroundProfile playgroundProfile = new PlaygroundProfile(); playgroundProfile.setActivities(List.of()); - when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(playgroundProfile); + when(playgroundClient.getPlaygroundMemberProfile(any(), anyLong())).thenReturn(List.of(playgroundProfile)); UserActiveInfo result = playgroundAuthService.getPlaygroundUserActiveInfo(token, 1L); Assertions.assertEquals(UserStatus.INACTIVE, result.getStatus()); @@ -295,18 +295,22 @@ void SUCCESS_getPlaygroundMemberProfiles() { @Test @DisplayName("FAIL_플레이그라운드 프로필을 등록하지 않은 유저 프로필 조회 BadRequestException") void FAIL_getPlaygroundMemberProfilesNotRegisteredBadRequestException() { + List memberIds = List.of(); + when(playgroundClient.getMemberProfiles(any(), any())).thenThrow(BadRequest.class); Assertions.assertThrows(BadRequestException.class, - () -> playgroundAuthService.getPlaygroundMemberProfiles(token, List.of())); + () -> playgroundAuthService.getPlaygroundMemberProfiles(token, memberIds)); } @Test @DisplayName("FAIL_플레이그라운드 토큰이 만료된 유저 프로필 조회 UnauthorizedException") void FAIL_getPlaygroundMemberProfilesExpiredJwtUnauthorizedException() { + List memberIds = List.of(); + when(playgroundClient.getMemberProfiles(any(), any())).thenThrow(ExpiredJwtException.class); Assertions.assertThrows(UnauthorizedException.class, - () -> playgroundAuthService.getPlaygroundMemberProfiles(token, List.of())); + () -> playgroundAuthService.getPlaygroundMemberProfiles(token, memberIds)); } } From 82b2b5fb347d85e24b6e306f31459090132a4222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Fri, 17 May 2024 20:51:21 +0900 Subject: [PATCH 47/48] =?UTF-8?q?refactor:=20unique=20nickname=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../soptamp/SoptampUserService.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java b/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java index 48d64fbb..f6532864 100644 --- a/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java +++ b/src/main/java/org/sopt/app/application/soptamp/SoptampUserService.java @@ -229,6 +229,7 @@ public void initPoint(Long userId) { soptampUserRepository.save(newSoptampUser); } + @Transactional public void initAllSoptampUserPoints() { val soptampUserList = soptampUserRepository.findAll(); soptampUserList.forEach(SoptampUser::initTotalPoints); @@ -239,6 +240,7 @@ public List getSoptampUserInfoList(List userIdList) { return soptampUserRepository.findAllByUserIdIn(userIdList); } + @Transactional public List initAllCurrentGenerationSoptampUser( List soptampUserList, List userInfoList @@ -260,14 +262,19 @@ public List initAllCurrentGenerationSoptampUser( return validatedSoptampUserList; } + @Transactional public List validateNickname(List soptampUserList) { - // 닉네임 정렬 - soptampUserList = soptampUserList.stream().sorted(Comparator.comparing(SoptampUser::getNickname)) - .collect(Collectors.toList()); - // uniqueNickname map 생성 + val nicknameMap = generateUniqueNicknameMap( + soptampUserList.stream().sorted(Comparator.comparing(SoptampUser::getNickname)) + .map(SoptampUser::getNickname).toList()); + + // soptampUser 리스트 userId 기준으로 중복 닉네임 알파벳 부여 + return updateUniqueNickname(soptampUserList, nicknameMap); + } + + private HashMap> generateUniqueNicknameMap(List nicknameList) { val nicknameMap = new HashMap>(); - val nicknameList = soptampUserList.stream().map(SoptampUser::getNickname).collect(Collectors.toList()); val uniqueNicknameList = nicknameList.stream().distinct().collect(Collectors.toList()); uniqueNicknameList.stream().forEach(nickname -> { val count = Collections.frequency(nicknameList, nickname); @@ -279,8 +286,13 @@ public List validateNickname(List soptampUserList) { nicknameMap.put(nickname, new ArrayList<>(changedList)); } }); + return nicknameMap; + } - // soptampUser 리스트 userId 기준으로 중복 닉네임 알파벳 부여 + private List updateUniqueNickname( + List soptampUserList, + HashMap> nicknameMap + ) { soptampUserList.stream().sorted(Comparator.comparing(SoptampUser::getUserId)).forEach(soptampUser -> { val validatedNicknameList = nicknameMap.get(soptampUser.getNickname()); if (validatedNicknameList.size() > 0) { @@ -290,7 +302,6 @@ public List validateNickname(List soptampUserList) { soptampUser.updateNickname(validatedNickname); } }); - return soptampUserList; } } \ No newline at end of file From 820bb57588a79285fb3c64d857d231a5ce65a1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A3=BC=EC=96=B4=EC=A7=84=EC=82=AC=EB=9E=91=28eojinjoo?= =?UTF-8?q?=29?= Date: Fri, 17 May 2024 21:29:03 +0900 Subject: [PATCH 48/48] =?UTF-8?q?findBySoptampUserIdAndGeneration=20test?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/SoptampPointServiceTest.java | 73 ++++++++++--------- .../postgres/SoptampPointRepositoryTest.java | 4 +- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java index 01f083b8..b9611dd5 100644 --- a/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java +++ b/src/test/java/org/sopt/app/application/SoptampPointServiceTest.java @@ -12,10 +12,10 @@ import org.junit.jupiter.api.Assertions; 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.junit.jupiter.api.Test; import org.mockito.junit.jupiter.MockitoExtension; import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; import org.sopt.app.application.soptamp.SoptampPointInfo.Point; @@ -47,18 +47,18 @@ void SUCCESS_findCurrentPointList() { final Long anyGeneration = anyLong(); List soptampPointList = List.of( - SoptampPoint.builder() - .id(1L) - .generation(anyGeneration) - .soptampUserId(1L) - .points(100L) - .build(), - SoptampPoint.builder() - .id(2L) - .generation(anyGeneration) - .soptampUserId(2L) - .points(200L) - .build() + SoptampPoint.builder() + .id(1L) + .generation(anyGeneration) + .soptampUserId(1L) + .points(100L) + .build(), + SoptampPoint.builder() + .id(2L) + .generation(anyGeneration) + .soptampUserId(2L) + .points(200L) + .build() ); //when @@ -79,7 +79,7 @@ void SUCCESS_findCurrentPointList() { .points(200L) .build() - ); + ); //then assertThat(result).usingRecursiveComparison().isEqualTo(expected); @@ -93,22 +93,23 @@ void SUCCESS_findCurrentPointListBySoptampUserIds() { List soptampUserIdList = any(); Long anyGeneration = anyLong(); List soptampPointList = List.of( - SoptampPoint.builder() - .id(1L) - .generation(anyGeneration) - .soptampUserId(1L) - .points(100L) - .build(), - SoptampPoint.builder() - .id(2L) - .generation(anyGeneration) - .soptampUserId(2L) - .points(200L) - .build() + SoptampPoint.builder() + .id(1L) + .generation(anyGeneration) + .soptampUserId(1L) + .points(100L) + .build(), + SoptampPoint.builder() + .id(2L) + .generation(anyGeneration) + .soptampUserId(2L) + .points(200L) + .build() ); //when - when(soptampPointRepository.findAllBySoptampUserIdInAndGeneration(soptampUserIdList, anyGeneration)).thenReturn(soptampPointList); + when(soptampPointRepository.findAllBySoptampUserIdInAndGeneration(soptampUserIdList, anyGeneration)).thenReturn( + soptampPointList); List result = soptampPointService.findCurrentPointListBySoptampUserIds(soptampUserIdList); List expected = List.of( Point.builder() @@ -123,7 +124,7 @@ void SUCCESS_findCurrentPointListBySoptampUserIds() { .soptampUserId(2L) .points(200L) .build() - ); + ); //then assertThat(result).usingRecursiveComparison().isEqualTo(expected); @@ -141,7 +142,8 @@ void SUCCESS_addPointSoptampIsPresent() { .build(); //when - when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.of(soptampPoint)); + when(soptampPointRepository.findBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn( + Optional.of(soptampPoint)); //then Assertions.assertDoesNotThrow(() -> soptampPointService.addPoint(anyLong(), anyInt())); @@ -151,7 +153,8 @@ void SUCCESS_addPointSoptampIsPresent() { @DisplayName("SUCCESS_솝탬프 포인트가 없으면 아무것도 안함") void SUCCESS_addPointSoptampNotPresent() { //when - when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.empty()); + when(soptampPointRepository.findBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn( + Optional.empty()); //then Assertions.assertDoesNotThrow(() -> soptampPointService.addPoint(anyLong(), anyInt())); } @@ -168,7 +171,8 @@ void SUCCESS_subtractPointIsPresent() { .build(); //when - when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.of(soptampPoint)); + when(soptampPointRepository.findBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn( + Optional.of(soptampPoint)); //then Assertions.assertDoesNotThrow(() -> soptampPointService.subtractPoint(anyLong(), anyInt())); @@ -178,7 +182,8 @@ void SUCCESS_subtractPointIsPresent() { @DisplayName("SUCCESS_솝탬프 포인트가 없으면 아무것도 안함") void SUCCESS_subtractPointSoptampNotPresent() { //when - when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn(Optional.empty()); + when(soptampPointRepository.findBySoptampUserIdAndGeneration(anyLong(), anyLong())).thenReturn( + Optional.empty()); //then Assertions.assertDoesNotThrow(() -> soptampPointService.subtractPoint(anyLong(), anyInt())); } @@ -190,7 +195,7 @@ void SUCCESS_upsertSoptampPointUserStatusACTIVE() { Long anyUserId = anyLong(); //when - when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyUserId, anyLong())) + when(soptampPointRepository.findBySoptampUserIdAndGeneration(anyUserId, anyLong())) .thenReturn(Optional.of(new SoptampPoint())); //then @@ -208,7 +213,7 @@ void SUCCESS_upsertSoptampPointUserStatusINACTIVE() { @DisplayName("SUCCESS_솝탬프 포인트가 Empty일 때 업서트하지 않음") void SUCCESS_upsertSoptampPointNotPresent() { //when - when(soptampPointRepository.findAllBySoptampUserIdAndGeneration(anyLong(), anyLong())) + when(soptampPointRepository.findBySoptampUserIdAndGeneration(anyLong(), anyLong())) .thenReturn(Optional.empty()); //then Assertions.assertDoesNotThrow(() -> soptampPointService.upsertSoptampPoint(UserStatus.ACTIVE, 1L)); diff --git a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java index 00e9b451..756d30f1 100644 --- a/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java +++ b/src/test/java/org/sopt/app/interfaces/postgres/SoptampPointRepositoryTest.java @@ -68,8 +68,8 @@ void SUCCESS_findAllByGeneration() { @Test @DisplayName("SUCCESS_유저 아이디와 기수로 솝탬프 포인트 리스트 찾기") void SUCCESS_findAllBySoptampUserIdAndGeneration() { - Assertions.assertThat(soptampPointRepository.findAllBySoptampUserIdAndGeneration(1L, 1L) - .orElseThrow().getId()) + Assertions.assertThat(soptampPointRepository.findBySoptampUserIdAndGeneration(1L, 1L) + .orElseThrow().getId()) .isEqualTo(generation1soptampPointId1.getId()); }