-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a0b305
commit c46fc3d
Showing
7 changed files
with
610 additions
and
11 deletions.
There are no files selected for viewing
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
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
98 changes: 98 additions & 0 deletions
98
...test/kotlin/com/restaurant/be/user/presentation/controller/CheckNicknameControllerTest.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,98 @@ | ||
package com.restaurant.be.user.presentation.controller | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.module.SimpleModule | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import com.restaurant.be.common.CustomDescribeSpec | ||
import com.restaurant.be.common.IntegrationTest | ||
import com.restaurant.be.common.PageDeserializer | ||
import com.restaurant.be.common.response.CommonResponse | ||
import com.restaurant.be.common.util.setUpUser | ||
import com.restaurant.be.restaurant.presentation.controller.dto.common.RestaurantDto | ||
import com.restaurant.be.user.presentation.dto.CheckNicknameResponse | ||
import com.restaurant.be.user.repository.UserRepository | ||
import io.kotest.matchers.shouldBe | ||
import org.springframework.data.domain.Page | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.nio.charset.Charset | ||
|
||
@IntegrationTest | ||
@Transactional | ||
class CheckNicknameControllerTest( | ||
private val mockMvc: MockMvc, | ||
private val userRepository: UserRepository | ||
) : CustomDescribeSpec() { | ||
private val baseUrl = "/v1/users" | ||
private val objectMapper: ObjectMapper = ObjectMapper().registerModule(KotlinModule()).apply { | ||
val module = SimpleModule() | ||
module.addDeserializer(Page::class.java, PageDeserializer(RestaurantDto::class.java)) | ||
this.registerModule(module) | ||
} | ||
|
||
init { | ||
beforeEach { | ||
setUpUser("[email protected]", userRepository) | ||
} | ||
|
||
describe("#checkNickname basic test") { | ||
it("when nickname is not used should return isDuplicate false") { | ||
// given | ||
val nickname = "test" | ||
|
||
// when | ||
val result = mockMvc.perform( | ||
get("$baseUrl/check-nickname") | ||
.param("nickname", nickname) | ||
).also { | ||
println(it.andReturn().response.contentAsString) | ||
} | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.result").value("SUCCESS")) | ||
.andReturn() | ||
|
||
val responseContent = result.response.getContentAsString(Charset.forName("UTF-8")) | ||
val responseType = | ||
object : TypeReference<CommonResponse<CheckNicknameResponse>>() {} | ||
val actualResult: CommonResponse<CheckNicknameResponse> = objectMapper.readValue( | ||
responseContent, | ||
responseType | ||
) | ||
|
||
// then | ||
actualResult.data!!.isDuplicate shouldBe false | ||
} | ||
|
||
it("when nickname is used should throw DuplicateUserNicknameException") { | ||
// given | ||
val existedUserNickname = userRepository.findByEmail("[email protected]")?.nickname ?: "" | ||
|
||
// when | ||
val result = mockMvc.perform( | ||
get("$baseUrl/check-nickname") | ||
.param("nickname", existedUserNickname) | ||
).also { | ||
println(it.andReturn().response.contentAsString) | ||
} | ||
.andExpect(status().isBadRequest) | ||
.andExpect(jsonPath("$.result").value("FAIL")) | ||
.andReturn() | ||
|
||
val responseContent = result.response.getContentAsString(Charset.forName("UTF-8")) | ||
val responseType = | ||
object : TypeReference<CommonResponse<CheckNicknameResponse>>() {} | ||
val actualResult: CommonResponse<CheckNicknameResponse> = objectMapper.readValue( | ||
responseContent, | ||
responseType | ||
) | ||
|
||
// then | ||
actualResult.message shouldBe "이미 존재 하는 닉네임 입니다." | ||
} | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/test/kotlin/com/restaurant/be/user/presentation/controller/DeleteUserControllerTest.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,93 @@ | ||
package com.restaurant.be.user.presentation.controller | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.module.SimpleModule | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import com.restaurant.be.common.CustomDescribeSpec | ||
import com.restaurant.be.common.IntegrationTest | ||
import com.restaurant.be.common.PageDeserializer | ||
import com.restaurant.be.common.response.CommonResponse | ||
import com.restaurant.be.common.util.setUpUser | ||
import com.restaurant.be.restaurant.presentation.controller.dto.common.RestaurantDto | ||
import com.restaurant.be.user.repository.UserRepository | ||
import io.kotest.matchers.shouldBe | ||
import org.springframework.data.domain.Page | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.nio.charset.Charset | ||
|
||
@IntegrationTest | ||
@Transactional | ||
class DeleteUserControllerTest( | ||
private val mockMvc: MockMvc, | ||
private val userRepository: UserRepository | ||
) : CustomDescribeSpec() { | ||
private val baseUrl = "/v1/users" | ||
private val objectMapper: ObjectMapper = ObjectMapper().registerModule(KotlinModule()).apply { | ||
val module = SimpleModule() | ||
module.addDeserializer(Page::class.java, PageDeserializer(RestaurantDto::class.java)) | ||
this.registerModule(module) | ||
} | ||
|
||
init { | ||
beforeEach { | ||
setUpUser("[email protected]", userRepository) | ||
} | ||
|
||
describe("#deleteUser basic test") { | ||
it("when user delete should return success") { | ||
// given | ||
// when | ||
val result = mockMvc.perform( | ||
delete("$baseUrl") | ||
).also { | ||
println(it.andReturn().response.contentAsString) | ||
} | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.result").value("SUCCESS")) | ||
.andReturn() | ||
|
||
val responseContent = result.response.getContentAsString(Charset.forName("UTF-8")) | ||
val responseType = | ||
object : TypeReference<CommonResponse<Void>>() {} | ||
val actualResult: CommonResponse<Void> = objectMapper.readValue( | ||
responseContent, | ||
responseType | ||
) | ||
|
||
// then | ||
actualResult.result shouldBe CommonResponse.Result.SUCCESS | ||
} | ||
|
||
it("when not exists user delete should return fail") { | ||
// given | ||
userRepository.deleteAll() | ||
|
||
// when | ||
val result = mockMvc.perform( | ||
delete("$baseUrl") | ||
).also { | ||
println(it.andReturn().response.contentAsString) | ||
} | ||
.andExpect(status().isBadRequest) | ||
.andExpect(jsonPath("$.result").value("FAIL")) | ||
.andReturn() | ||
|
||
val responseContent = result.response.getContentAsString(Charset.forName("UTF-8")) | ||
val responseType = | ||
object : TypeReference<CommonResponse<Void>>() {} | ||
val actualResult: CommonResponse<Void> = objectMapper.readValue( | ||
responseContent, | ||
responseType | ||
) | ||
|
||
// then | ||
actualResult.message shouldBe "존재 하지 않는 유저 입니다." | ||
} | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/test/kotlin/com/restaurant/be/user/presentation/controller/GetUserControllerTest.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,97 @@ | ||
package com.restaurant.be.user.presentation.controller | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.module.SimpleModule | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import com.restaurant.be.common.CustomDescribeSpec | ||
import com.restaurant.be.common.IntegrationTest | ||
import com.restaurant.be.common.PageDeserializer | ||
import com.restaurant.be.common.response.CommonResponse | ||
import com.restaurant.be.common.util.setUpUser | ||
import com.restaurant.be.restaurant.presentation.controller.dto.common.RestaurantDto | ||
import com.restaurant.be.user.presentation.dto.GetUserResponse | ||
import com.restaurant.be.user.repository.UserRepository | ||
import io.kotest.matchers.shouldBe | ||
import org.springframework.data.domain.Page | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.nio.charset.Charset | ||
|
||
@IntegrationTest | ||
@Transactional | ||
class GetUserControllerTest( | ||
private val mockMvc: MockMvc, | ||
private val userRepository: UserRepository | ||
) : CustomDescribeSpec() { | ||
private val baseUrl = "/v1/users" | ||
private val objectMapper: ObjectMapper = ObjectMapper().registerModule(KotlinModule()).apply { | ||
val module = SimpleModule() | ||
module.addDeserializer(Page::class.java, PageDeserializer(RestaurantDto::class.java)) | ||
this.registerModule(module) | ||
} | ||
|
||
init { | ||
beforeEach { | ||
setUpUser("[email protected]", userRepository) | ||
} | ||
|
||
describe("#getUser basic test") { | ||
it("when existed user should return user info") { | ||
// given | ||
val user = userRepository.findByEmail("[email protected]") ?: throw Exception("User not found") | ||
|
||
// when | ||
val result = mockMvc.perform( | ||
get("$baseUrl/${user.id}") | ||
).also { | ||
println(it.andReturn().response.contentAsString) | ||
} | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.result").value("SUCCESS")) | ||
.andReturn() | ||
|
||
val responseContent = result.response.getContentAsString(Charset.forName("UTF-8")) | ||
val responseType = | ||
object : TypeReference<CommonResponse<GetUserResponse>>() {} | ||
val actualResult: CommonResponse<GetUserResponse> = objectMapper.readValue( | ||
responseContent, | ||
responseType | ||
) | ||
|
||
// then | ||
actualResult.data!!.userDto.id shouldBe user.id | ||
actualResult.data!!.userDto.email shouldBe user.email | ||
actualResult.data!!.userDto.nickname shouldBe user.nickname | ||
actualResult.data!!.userDto.profileImageUrl shouldBe user.profileImageUrl | ||
} | ||
|
||
it("when not existed user should fail") { | ||
// given | ||
// when | ||
val result = mockMvc.perform( | ||
get("$baseUrl/12345") | ||
).also { | ||
println(it.andReturn().response.contentAsString) | ||
} | ||
.andExpect(status().isBadRequest) | ||
.andExpect(jsonPath("$.result").value("FAIL")) | ||
.andReturn() | ||
|
||
val responseContent = result.response.getContentAsString(Charset.forName("UTF-8")) | ||
val responseType = | ||
object : TypeReference<CommonResponse<GetUserResponse>>() {} | ||
val actualResult: CommonResponse<GetUserResponse> = objectMapper.readValue( | ||
responseContent, | ||
responseType | ||
) | ||
|
||
// then | ||
actualResult.message shouldBe "존재 하지 않는 유저 입니다." | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.