generated from pricelees/issue-pr-template
test: \@DataJpaTest 기반 MemberRepositoryTest 추가
This commit is contained in:
parent
4b568915ae
commit
c5664e8aef
@ -0,0 +1,63 @@
|
||||
package roomescape.member.infrastructure.persistence
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.nulls.shouldNotBeNull
|
||||
import io.kotest.matchers.shouldBe
|
||||
import jakarta.persistence.EntityManager
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||
import roomescape.util.MemberFixture
|
||||
|
||||
@DataJpaTest(showSql = true)
|
||||
class MemberRepositoryTest(
|
||||
val entityManager: EntityManager,
|
||||
val memberRepository: MemberRepository
|
||||
) : FunSpec({
|
||||
context("existsByEmail") {
|
||||
val account = "email"
|
||||
val email = "$account@email.com"
|
||||
|
||||
beforeTest {
|
||||
entityManager.persist(MemberFixture.create(account = account))
|
||||
entityManager.flush()
|
||||
entityManager.clear()
|
||||
}
|
||||
|
||||
test("동일한 이메일이 있으면 true 반환") {
|
||||
val result = memberRepository.existsByEmail(email)
|
||||
result shouldBe true
|
||||
}
|
||||
|
||||
test("동일한 이메일이 없으면 false 반환") {
|
||||
memberRepository.existsByEmail(email.substring(email.length - 1)) shouldBe false
|
||||
}
|
||||
}
|
||||
|
||||
context("findByEmailAndPassword") {
|
||||
val account = "email"
|
||||
val email = "$account@email.com"
|
||||
val password = "password123"
|
||||
|
||||
beforeTest {
|
||||
entityManager.persist(MemberFixture.create(account = account, password = password))
|
||||
entityManager.flush()
|
||||
entityManager.clear()
|
||||
}
|
||||
|
||||
test("둘다 일치하면 정상 반환") {
|
||||
memberRepository.findByEmailAndPassword(email, password) shouldNotBeNull {
|
||||
this.email shouldBe email
|
||||
this.password shouldBe password
|
||||
}
|
||||
}
|
||||
|
||||
test("이메일이 틀리면 null 반환") {
|
||||
val invalidMail = email.substring(email.length - 1)
|
||||
memberRepository.findByEmailAndPassword(invalidMail, password) shouldBe null
|
||||
}
|
||||
|
||||
test("비밀번호가 틀리면 null 반환") {
|
||||
val invalidPassword = password.substring(password.length - 1)
|
||||
memberRepository.findByEmailAndPassword(email, invalidPassword) shouldBe null
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user