From dde67f7a125b706703a2ebbf88913cc212d46522 Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Fri, 30 Aug 2024 22:22:03 +0900 Subject: [PATCH 01/12] =?UTF-8?q?feat:=20IdentityRepository=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../identity/domain/repository/jpa/IdentityRepository.kt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt b/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt new file mode 100644 index 0000000..d54405a --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt @@ -0,0 +1,8 @@ +package uoslife.springaccount.app.identity.domain.repository.jpa + +import org.springframework.data.jpa.repository.JpaRepository +import uoslife.springaccount.app.identity.domain.entity.Identity + +interface IdentityRepository : JpaRepository { + fun getUserIdentityList(uuid: String): List? +} \ No newline at end of file From 49383f5225c88c5ecc6e5b3348d9d2f1bc4da349 Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sat, 31 Aug 2024 03:07:16 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20IdentityDto=20Reponse=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/identity/dto/response/IdentityDto.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.kt diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.kt b/src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.kt new file mode 100644 index 0000000..ac6d919 --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.kt @@ -0,0 +1,29 @@ +package uoslife.springaccount.app.identity.dto.response + +import uoslife.springaccount.app.identity.domain.entity.Identity + +class IdentityDto { + data class IdentityReponse ( + val type: String, + val status: String, + val idNumber: String, + val university: String? = null, + val department: String? = null, + val major: String? = null, // null 가능성 고려 + val isActive: Boolean + ) + + companion object { + fun toResponse(identity : Identity) : IdentityReponse{ + return IdentityReponse( + type = identity.type, + status = identity.status, + idNumber = identity.idNumber, + university = identity.university, + department = identity.department, + major = identity.major, + isActive = identity.isActive, + ) + } + } +} \ No newline at end of file From 6bd4e2763a3245389d999df00859703fc882281c Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sat, 31 Aug 2024 03:07:56 +0900 Subject: [PATCH 03/12] =?UTF-8?q?refactor:=20IdentityRepository=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/identity/domain/repository/jpa/IdentityRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt b/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt index d54405a..02362f8 100644 --- a/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt +++ b/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt @@ -4,5 +4,5 @@ import org.springframework.data.jpa.repository.JpaRepository import uoslife.springaccount.app.identity.domain.entity.Identity interface IdentityRepository : JpaRepository { - fun getUserIdentityList(uuid: String): List? + fun findIdentityListByUuid(uuid: String): List? } \ No newline at end of file From a96fefde5576c8afc4aced1a2fd3b2cfa82bc0ff Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sat, 31 Aug 2024 17:39:01 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat:=20IdentityService=EC=9D=98=20getIde?= =?UTF-8?q?ntityList=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/identity/service/IdentityService.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt b/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt new file mode 100644 index 0000000..dc7b27d --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt @@ -0,0 +1,15 @@ +package uoslife.springaccount.app.identity.service + +import uoslife.springaccount.app.identity.domain.entity.Identity +import uoslife.springaccount.app.identity.domain.repository.jpa.IdentityRepository +import uoslife.springaccount.app.identity.dto.response.IdentityDto + +class IdentityService( + private val identityRepository : IdentityRepository, +) { + fun getIdentityList(uuid: String):List? { + val identityList = identityRepository.findIdentityListByUuid(uuid); + + return identityList?.map { identity: Identity -> IdentityDto.toResponse(identity) } + } +} From 901a425fa92c1e16c694b3f519ce7f196ec32a08 Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sun, 1 Sep 2024 01:12:52 +0900 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20repository=20IdentityList=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../identity/domain/repository/jpa/IdentityRepository.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt b/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt index 02362f8..ea2f8da 100644 --- a/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt +++ b/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt @@ -1,8 +1,15 @@ package uoslife.springaccount.app.identity.domain.repository.jpa import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Modifying +import org.springframework.data.jpa.repository.Query import uoslife.springaccount.app.identity.domain.entity.Identity interface IdentityRepository : JpaRepository { - fun findIdentityListByUuid(uuid: String): List? + fun findIdentitiesByUserId(userId: Long): List? + + // 추후 queryDsl로 변경 예정. + @Modifying + @Query("UPDATE Identity i SET i.isActive = CASE WHEN i.id = :identityId THEN true ELSE false END WHERE i.userId = :userId") + fun updateActiveIdentityList(identityId:String) } \ No newline at end of file From d3b08e57276328b5a8c667e3000c412ce7bde31b Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sun, 1 Sep 2024 01:14:48 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20identity=20=EB=B0=B0=EC=97=B4?= =?UTF-8?q?=EC=9D=84=20response=20dto=EB=A1=9C=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=ED=95=98=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/identity/dto/response/IdentityDto.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.kt b/src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.kt index ac6d919..1328b54 100644 --- a/src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.kt +++ b/src/main/kotlin/uoslife/springaccount/app/identity/dto/response/IdentityDto.kt @@ -3,7 +3,7 @@ package uoslife.springaccount.app.identity.dto.response import uoslife.springaccount.app.identity.domain.entity.Identity class IdentityDto { - data class IdentityReponse ( + data class IdentityResponse ( val type: String, val status: String, val idNumber: String, @@ -14,8 +14,8 @@ class IdentityDto { ) companion object { - fun toResponse(identity : Identity) : IdentityReponse{ - return IdentityReponse( + fun toResponse(identity : Identity) : IdentityResponse{ + return IdentityResponse( type = identity.type, status = identity.status, idNumber = identity.idNumber, @@ -25,5 +25,9 @@ class IdentityDto { isActive = identity.isActive, ) } + + fun toResponseIdentityList (identityList: List?): List? { + return identityList?.map { toResponse(it) } + } } } \ No newline at end of file From 7657066d4d1ca592696e264c6519bd949a978eb7 Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sun, 1 Sep 2024 01:28:50 +0900 Subject: [PATCH 07/12] =?UTF-8?q?feat:=20Service=20=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=EC=97=90=EC=84=9C=20=EB=8C=80=ED=91=9C=20=EC=8B=A0?= =?UTF-8?q?=EB=B6=84=20=EC=84=A4=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/identity/service/IdentityService.kt | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt b/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt index dc7b27d..b021def 100644 --- a/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt +++ b/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt @@ -1,15 +1,35 @@ package uoslife.springaccount.app.identity.service +import org.springframework.stereotype.Service import uoslife.springaccount.app.identity.domain.entity.Identity import uoslife.springaccount.app.identity.domain.repository.jpa.IdentityRepository import uoslife.springaccount.app.identity.dto.response.IdentityDto +@Service class IdentityService( private val identityRepository : IdentityRepository, ) { - fun getIdentityList(uuid: String):List? { - val identityList = identityRepository.findIdentityListByUuid(uuid); - return identityList?.map { identity: Identity -> IdentityDto.toResponse(identity) } + // 유저의 신분 정보를 가져옵니다. + // 리빌드 이전의 시대생 유저인 경우, 복수 신분이 존재할 수 있습니다. + fun getIdentityList(userId: Long):List? { + val identityList = identityRepository.findIdentitiesByUserId(userId); + + return IdentityDto.toResponseIdentityList(identityList); + } + + // 여러 신분 중 대표 신분 설정합니다. + fun selectRepresentativeIdentityFromList(userId: Long) :List?{ + val identityList = identityRepository.findIdentitiesByUserId(userId); + + // 신분의 개수가 1개인 경우 업데이트 로직을 실행하지 않습니다. + if (identityList?.size == 1) return null; + + // 여러 신분 중 대표 신분으로 설정하는 로직입니다. + identityList?.forEach { identity: Identity -> + identityRepository.updateActiveIdentityList(identity.id) + } + + return IdentityDto.toResponseIdentityList(identityList); } } From de4e7c257513b2fcb62d5a9e3d9434f7bb16f757 Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sun, 1 Sep 2024 01:29:13 +0900 Subject: [PATCH 08/12] =?UTF-8?q?feat:=20Controller=20=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../identity/controller/IdentityController.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.kt diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.kt b/src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.kt new file mode 100644 index 0000000..1f5982e --- /dev/null +++ b/src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.kt @@ -0,0 +1,37 @@ +package uoslife.springaccount.app.identity.controller + +import org.springframework.http.ResponseEntity +import org.springframework.security.core.annotation.AuthenticationPrincipal +import org.springframework.security.core.userdetails.UserDetails +import org.springframework.web.bind.annotation.* +import uoslife.springaccount.app.identity.dto.response.IdentityDto +import uoslife.springaccount.app.identity.service.IdentityService + + +@RestController +@RequestMapping("/v2/identities") +class IdentityController(private val identityService: IdentityService) { + @GetMapping + fun getMyIdentities( + @AuthenticationPrincipal userDetails: UserDetails + ): ResponseEntity> { + val userId = userDetails.username.toLong(); + + return ResponseEntity.ok(identityService.getIdentityList(userId)) + } + + @PatchMapping("/{identityId}") + fun selectRepresentativeIdentity(@AuthenticationPrincipal userDetails: UserDetails, @PathVariable identityId: String + ) :ResponseEntity> { + val userId = userDetails.username.toLong(); + + val result = identityService.selectRepresentativeIdentityFromList(userId) + + //TODO: identityList가 1개인 경우, 응답값 반환에 대한 고민 필요. + return if (result == null) { + ResponseEntity.ok("수정할 필요가 없습니다."); + } else { + ResponseEntity.ok(result) + } + } +} \ No newline at end of file From 850a0415b53c8cc8af4b960d8e860568f62fd80b Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sat, 7 Sep 2024 12:49:52 +0900 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20=EB=A0=88=ED=8F=AC=EC=A7=80?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=EC=97=90=EC=84=9C=20=EC=9C=A0=EC=A0=80=20id?= =?UTF-8?q?=EB=A1=9C=20identity=20=EC=B0=BE=EB=8A=94=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../identity/domain/repository/jpa/IdentityRepository.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt b/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt index ea2f8da..2fd0390 100644 --- a/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt +++ b/src/main/kotlin/uoslife/springaccount/app/identity/domain/repository/jpa/IdentityRepository.kt @@ -8,8 +8,10 @@ import uoslife.springaccount.app.identity.domain.entity.Identity interface IdentityRepository : JpaRepository { fun findIdentitiesByUserId(userId: Long): List? + fun findByUserId(userId: Long): List? + // 추후 queryDsl로 변경 예정. @Modifying - @Query("UPDATE Identity i SET i.isActive = CASE WHEN i.id = :identityId THEN true ELSE false END WHERE i.userId = :userId") - fun updateActiveIdentityList(identityId:String) + @Query("UPDATE Identity i SET i.isActive = CASE WHEN i.id = :identityId THEN true ELSE false END WHERE i.user.id = :userId") + fun updateActiveIdentityList(identityId: String, userId: Long) } \ No newline at end of file From 18c920af818e0410fc5a70bc86475fe19a7583f1 Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sat, 7 Sep 2024 12:50:21 +0900 Subject: [PATCH 10/12] =?UTF-8?q?feat:=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EB=A0=88=EC=96=B4=EC=97=90=20updateActiveIdentityList=20?= =?UTF-8?q?=EC=9D=B8=EC=9E=90=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springaccount/app/identity/service/IdentityService.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt b/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt index b021def..c29c4de 100644 --- a/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt +++ b/src/main/kotlin/uoslife/springaccount/app/identity/service/IdentityService.kt @@ -1,11 +1,13 @@ package uoslife.springaccount.app.identity.service import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import uoslife.springaccount.app.identity.domain.entity.Identity import uoslife.springaccount.app.identity.domain.repository.jpa.IdentityRepository import uoslife.springaccount.app.identity.dto.response.IdentityDto @Service +@Transactional(readOnly = true) class IdentityService( private val identityRepository : IdentityRepository, ) { @@ -13,21 +15,21 @@ class IdentityService( // 유저의 신분 정보를 가져옵니다. // 리빌드 이전의 시대생 유저인 경우, 복수 신분이 존재할 수 있습니다. fun getIdentityList(userId: Long):List? { - val identityList = identityRepository.findIdentitiesByUserId(userId); + val identityList = identityRepository.findByUserId(userId); return IdentityDto.toResponseIdentityList(identityList); } // 여러 신분 중 대표 신분 설정합니다. fun selectRepresentativeIdentityFromList(userId: Long) :List?{ - val identityList = identityRepository.findIdentitiesByUserId(userId); + val identityList = identityRepository.findByUserId(userId); // 신분의 개수가 1개인 경우 업데이트 로직을 실행하지 않습니다. if (identityList?.size == 1) return null; // 여러 신분 중 대표 신분으로 설정하는 로직입니다. identityList?.forEach { identity: Identity -> - identityRepository.updateActiveIdentityList(identity.id) + identityRepository.updateActiveIdentityList(identity.id, userId) } return IdentityDto.toResponseIdentityList(identityList); From c9b3bc6bc5c59bd736bb77a0568b394a8dafce18 Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sat, 7 Sep 2024 12:50:42 +0900 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20selectRepresentativeIdentity=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=EA=B0=92=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/identity/controller/IdentityController.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.kt b/src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.kt index 1f5982e..6b1276f 100644 --- a/src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.kt +++ b/src/main/kotlin/uoslife/springaccount/app/identity/controller/IdentityController.kt @@ -27,11 +27,12 @@ class IdentityController(private val identityService: IdentityService) { val result = identityService.selectRepresentativeIdentityFromList(userId) + return ResponseEntity.ok(result) //TODO: identityList가 1개인 경우, 응답값 반환에 대한 고민 필요. - return if (result == null) { - ResponseEntity.ok("수정할 필요가 없습니다."); - } else { - ResponseEntity.ok(result) - } +// return if (result == null) { +// ResponseEntity.ok("수정할 필요가 없습니다."); +// } else { +// ResponseEntity.ok(result) +// } } } \ No newline at end of file From a8060c53f4c1c6daa2d58742a3aaa145cd031fa3 Mon Sep 17 00:00:00 2001 From: youngchan Kim Date: Sat, 7 Sep 2024 12:50:58 +0900 Subject: [PATCH 12/12] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/identity/common/IdentityTest.kt | 101 ++++++++++++++++++ .../identity/service/getIdentityListTest.kt | 29 +++++ 2 files changed, 130 insertions(+) create mode 100644 src/test/kotlin/uoslife/springaccount/app/identity/common/IdentityTest.kt create mode 100644 src/test/kotlin/uoslife/springaccount/app/identity/service/getIdentityListTest.kt diff --git a/src/test/kotlin/uoslife/springaccount/app/identity/common/IdentityTest.kt b/src/test/kotlin/uoslife/springaccount/app/identity/common/IdentityTest.kt new file mode 100644 index 0000000..4aa5a4a --- /dev/null +++ b/src/test/kotlin/uoslife/springaccount/app/identity/common/IdentityTest.kt @@ -0,0 +1,101 @@ +package uoslife.springaccount.app.identity.common + +import io.mockk.MockKAnnotations +import io.mockk.every +import io.mockk.impl.annotations.MockK +import io.mockk.mockk +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.redisson.api.RedissonClient +import org.springframework.boot.test.context.SpringBootTest +import uoslife.springaccount.app.identity.domain.entity.Identity +import uoslife.springaccount.app.identity.domain.repository.jpa.IdentityRepository +import uoslife.springaccount.app.identity.service.IdentityService +import uoslife.springaccount.app.user.domain.entity.User + +@SpringBootTest +abstract class IdentityTest { + + val identityService = mockk() + val identityRepository = mockk() + val redissonClient = mockk() +// @MockK +// protected lateinit var identityService: IdentityService +// +// @MockK +// protected lateinit var identityRepository: IdentityRepository + + protected val userDummyData1 = User( + name = "김영찬", + phoneNumber = "010-2064-6347", + email = "aacz1203@uos.ac.kr", + nickname = "kyc", + birthday = "1999-12-03", + avatarUrl = null, + ) + + protected val identityDummyData1 = Identity( + user = userDummyData1, + type = "Student", + status = "Active", + idNumber = "123456789", + university = "Seoul National University", + universityCode = "SNU", + department = "Computer Science", + departmentCode = "CS", + major = null, + majorCode = null, + isActive = false + ) + + protected val identityDummyData2 = Identity( + user = userDummyData1, + type = "Alumnus", + status = "Inactive", + idNumber = "987654321", + university = "Korea University", + universityCode = "KU", + department = "Business Administration", + departmentCode = "BA", + major = "Marketing", + majorCode = "MK", + isActive = false + ) + + protected val identityDummyData3 = Identity( + user = userDummyData1, + type = "Student", + status = "Active", + idNumber = "111223344", + university = "Yonsei University", + universityCode = "YU", + department = "Electrical Engineering", + departmentCode = "EE", + major = "Robotics", + majorCode = "RO", + isActive = false + ) + + companion object { + @BeforeAll + @JvmStatic + fun init() { + MockKAnnotations.init(this) + } + } + + @BeforeEach + fun setUp() { + // Mocking repository의 동작 정의 + every { userDummyData1.id?.let { identityRepository.findIdentitiesByUserId(it) } } returns listOf(identityDummyData1, identityDummyData2, identityDummyData3) + +// every { userService.findUser(any()) } answers { +// val userId = firstArg() +// if (userId == user1.id) { +// user1 +// } else { +// user2 +// } +// } + } +} \ No newline at end of file diff --git a/src/test/kotlin/uoslife/springaccount/app/identity/service/getIdentityListTest.kt b/src/test/kotlin/uoslife/springaccount/app/identity/service/getIdentityListTest.kt new file mode 100644 index 0000000..4d216b0 --- /dev/null +++ b/src/test/kotlin/uoslife/springaccount/app/identity/service/getIdentityListTest.kt @@ -0,0 +1,29 @@ +package uoslife.springaccount.app.identity.service + +import io.mockk.every +import io.mockk.verify +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import uoslife.springaccount.app.identity.common.IdentityTest + +class getIdentityListTest : IdentityTest() { + + @Test + fun `getIdentityList should return identity list for given userId`() { + // Given + init(); + val userId = userDummyData1.id ?: throw IllegalArgumentException("User ID cannot be null") + + // When + val result = identityService.getIdentityList(userId) + + // Then + assertEquals(3, result?.size) // 더미 데이터에서 3개의 신분 정보가 있어야 합니다. + assertEquals(identityDummyData1.type, result?.get(0)?.type) + assertEquals(identityDummyData2.type, result?.get(1)?.type) + assertEquals(identityDummyData3.type, result?.get(2)?.type) + + // identityRepository의 메서드가 호출되었는지 확인 + verify { identityRepository.findIdentitiesByUserId(userId) } + } +}