Skip to content

Commit

Permalink
test: 카카오, 일반 회원가입 에러처리 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
axhtl committed Sep 6, 2024
1 parent 827de73 commit ef3f930
Showing 1 changed file with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ package org.store.clothstar.member.authentication.controller
import com.fasterxml.jackson.databind.ObjectMapper
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.MediaType
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.*
import org.springframework.transaction.annotation.Transactional
import org.store.clothstar.common.config.redis.RedisUtil
import org.store.clothstar.common.error.ErrorCode
import org.store.clothstar.common.error.exception.InvalidSignupMemberRequest
import org.store.clothstar.common.error.exception.order.OrderNotFoundException
import org.store.clothstar.kakaoLogin.service.KakaoLoginService
import org.store.clothstar.member.authentication.domain.SignUpType
import org.store.clothstar.member.dto.request.KakaoMemberRequest
Expand Down Expand Up @@ -145,4 +150,58 @@ class AuthenticationControllerTest(

mockWebServer.shutdown()
}

@DisplayName("멤버 카카오 회원가입에서 요청DTO가 NULL일 경우 에러처리 테스트")
@Test
fun normalSignUpExceptionTest() {
//kakaoMemberRequest 요청 DTO 생성
val kakaoMemberRequest = KakaoMemberRequest(
name = "Test User",
telNo = "010-1234-5678",
email = null,
code = "test_code"
)

// kakaoMemberRequest를 null로 맞춤
val signUpRequest = SignUpRequest(null, kakaoMemberRequest)
val requestBody = objectMapper.writeValueAsString(signUpRequest)

//when & then
mockMvc.perform(
post(MEMBER_URL)
.param("signUpType", SignUpType.NORMAL.toString())
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody)
)
.andExpect(status().isBadRequest)
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.errorCode").value(400))
.andExpect(jsonPath("$.message").value("회원가입 시 회원 정보가 필요합니다."))
}

@DisplayName("멤버 카카오 회원가입에서 요청DTO가 NULL일 경우 에러처리 테스트")
@Test
fun kakaoSignUpExceptionTest() {
// createMemberRequest 생성을 위한 이메일과 인증번호로 redis 데이터 생성
val email = "[email protected]"
val certifyNum = redisUtil.createdCertifyNum()
redisUtil.createRedisData(email, certifyNum)

// kakaoMemberRequest를 null로 맞춤
val createMemberRequest = CreateObject.getCreateMemberRequest(email, certifyNum)
val signUpRequest = SignUpRequest(createMemberRequest, null)
val requestBody = objectMapper.writeValueAsString(signUpRequest)

//when & then
mockMvc.perform(
post(MEMBER_URL)
.param("signUpType", SignUpType.KAKAO.toString())
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody)
)
.andExpect(status().isBadRequest)
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.errorCode").value(400))
.andExpect(jsonPath("$.message").value("회원가입 시 회원 정보가 필요합니다."))
}
}

0 comments on commit ef3f930

Please sign in to comment.