generated from pricelees/issue-pr-template
[#34] 회원 / 인증 도메인 재정의 #43
@ -26,6 +26,9 @@ class DatabaseCleaner(
|
|||||||
|
|
||||||
jdbcTemplate.execute("SET REFERENTIAL_INTEGRITY FALSE")
|
jdbcTemplate.execute("SET REFERENTIAL_INTEGRITY FALSE")
|
||||||
tables.forEach {
|
tables.forEach {
|
||||||
|
if (it == "region") {
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
jdbcTemplate.execute("TRUNCATE TABLE $it RESTART IDENTITY")
|
jdbcTemplate.execute("TRUNCATE TABLE $it RESTART IDENTITY")
|
||||||
}
|
}
|
||||||
jdbcTemplate.execute("SET REFERENTIAL_INTEGRITY TRUE")
|
jdbcTemplate.execute("SET REFERENTIAL_INTEGRITY TRUE")
|
||||||
|
|||||||
@ -8,14 +8,18 @@ import io.restassured.response.Response
|
|||||||
import io.restassured.response.ValidatableResponse
|
import io.restassured.response.ValidatableResponse
|
||||||
import io.restassured.specification.RequestSpecification
|
import io.restassured.specification.RequestSpecification
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
|
import roomescape.admin.infrastructure.persistence.AdminEntity
|
||||||
|
import roomescape.admin.infrastructure.persistence.AdminRepository
|
||||||
import roomescape.auth.web.LoginRequest
|
import roomescape.auth.web.LoginRequest
|
||||||
|
import roomescape.auth.web.LoginRequestV2
|
||||||
import roomescape.common.config.next
|
import roomescape.common.config.next
|
||||||
import roomescape.member.infrastructure.persistence.MemberEntity
|
import roomescape.common.dto.PrincipalType
|
||||||
import roomescape.member.infrastructure.persistence.MemberRepository
|
import roomescape.member.infrastructure.persistence.*
|
||||||
import roomescape.member.infrastructure.persistence.Role
|
|
||||||
|
|
||||||
class AuthUtil(
|
class AuthUtil(
|
||||||
private val memberRepository: MemberRepository
|
private val memberRepository: MemberRepository,
|
||||||
|
private val userRepository: UserRepository,
|
||||||
|
private val adminRepository: AdminRepository
|
||||||
) {
|
) {
|
||||||
fun login(email: String, password: String, role: Role = Role.MEMBER): String {
|
fun login(email: String, password: String, role: Role = Role.MEMBER): String {
|
||||||
if (!memberRepository.existsByEmail(email)) {
|
if (!memberRepository.existsByEmail(email)) {
|
||||||
@ -54,6 +58,46 @@ class AuthUtil(
|
|||||||
MemberFixture.user.email,
|
MemberFixture.user.email,
|
||||||
MemberFixture.user.password
|
MemberFixture.user.password
|
||||||
) ?: throw AssertionError("Unexpected Exception Occurred.")
|
) ?: throw AssertionError("Unexpected Exception Occurred.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun adminLogin(admin: AdminEntity): String {
|
||||||
|
if (adminRepository.findByAccount(admin.account) == null) {
|
||||||
|
adminRepository.save(admin)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Given {
|
||||||
|
contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
body(LoginRequestV2(account = admin.account, password = admin.password, principalType = PrincipalType.ADMIN))
|
||||||
|
} When {
|
||||||
|
post("/auth/login")
|
||||||
|
} Then {
|
||||||
|
statusCode(200)
|
||||||
|
} Extract {
|
||||||
|
path("data.accessToken")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun defaultAdminLogin(): String = adminLogin(AdminFixture.default)
|
||||||
|
|
||||||
|
fun userLogin(user: UserEntity): String {
|
||||||
|
if (userRepository.findByEmail(user.email) == null) {
|
||||||
|
userRepository.save(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Given {
|
||||||
|
contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
body(LoginRequestV2(account = user.email, password = user.password, principalType = PrincipalType.USER))
|
||||||
|
} When {
|
||||||
|
post("/auth/login")
|
||||||
|
} Then {
|
||||||
|
statusCode(200)
|
||||||
|
} Extract {
|
||||||
|
path("data.accessToken")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun defaultUserLogin(): String = userLogin(UserFixture.default)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun runTest(
|
fun runTest(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user