-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test codes for GetResearcherInfoUseCaseTest
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/test/kotlin/com/dobby/backend/application/usecase/member/GetResearcherInfoUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.dobby.backend.application.usecase.member | ||
|
||
import com.dobby.backend.domain.exception.ResearcherNotFoundException | ||
import com.dobby.backend.domain.gateway.member.ResearcherGateway | ||
import com.dobby.backend.domain.model.member.Member | ||
import com.dobby.backend.domain.model.member.Researcher | ||
import com.dobby.backend.infrastructure.database.entity.enums.MemberStatus | ||
import com.dobby.backend.infrastructure.database.entity.enums.ProviderType | ||
import com.dobby.backend.infrastructure.database.entity.enums.RoleType | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import java.time.LocalDateTime | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
|
||
class GetResearcherInfoUseCaseTest : BehaviorSpec({ | ||
Given("Gateway에 유효한 memberId와 researcherId가 있다면") { | ||
val researcherGateway = mockk<ResearcherGateway>() | ||
val useCase = GetResearcherInfoUseCase(researcherGateway) | ||
|
||
val input = GetResearcherInfoUseCase.Input(memberId = 1L) | ||
val mockMember = Member( | ||
id = 1L, | ||
name = "신수정", | ||
oauthEmail = "[email protected]", | ||
contactEmail = "[email protected]", | ||
provider = ProviderType.GOOGLE, | ||
role = RoleType.RESEARCHER, | ||
status = MemberStatus.ACTIVE, | ||
createdAt = LocalDateTime.now(), | ||
updatedAt = LocalDateTime.now() | ||
) | ||
val mockResearcher = Researcher( | ||
member = mockMember, | ||
id = 1L, | ||
univEmail = "[email protected]", | ||
univName = "이화여자대학교", | ||
major = "컴퓨터공학과", | ||
labInfo = "야뿌 서버 연구실", | ||
emailVerified = true, | ||
) | ||
|
||
every { researcherGateway.findByMemberId(input.memberId) } returns mockResearcher | ||
|
||
`when`("GetResearcherInfoUseCase가 실행되면") { | ||
val result = useCase.execute(input) | ||
|
||
then("올바른 연구자 정보를 반환한다") { | ||
assertEquals(mockResearcher.member, result.member) | ||
assertEquals(mockResearcher.univEmail, result.univEmail) | ||
assertEquals(mockResearcher.univName, result.univName) | ||
assertEquals(mockResearcher.major, result.major) | ||
assertEquals(mockResearcher.labInfo, result.labInfo) | ||
assertEquals( | ||
"이화여자대학교 컴퓨터공학과 야뿌 서버 연구실 신수정", | ||
result.leadResearcher | ||
) | ||
} | ||
} | ||
} | ||
|
||
given("gateway에 해당 member 정보가 없으면") { | ||
val researcherGateway = mockk<ResearcherGateway>() | ||
val useCase = GetResearcherInfoUseCase(researcherGateway) | ||
|
||
val input = GetResearcherInfoUseCase.Input(memberId = 2L) | ||
|
||
every { researcherGateway.findByMemberId(input.memberId) } returns null | ||
|
||
`when`("GetResearcherInfoUseCase가 실행됐을때") { | ||
then("ResearcherNotFoundException 예외가 반환된다.") { | ||
assertFailsWith<ResearcherNotFoundException> { | ||
useCase.execute(input) | ||
} | ||
} | ||
} | ||
} | ||
}) |