Skip to content

Commit

Permalink
test: 구현된 Auth 헤더 사용 하도록 CartProduct API 테스트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
TaeyeonRoyce committed Jan 29, 2024
1 parent d942e40 commit 82b7dec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.petqua.presentation.cart

import com.petqua.application.cart.CartProductService
import com.petqua.application.product.dto.ProductDetailResponse
import com.petqua.domain.auth.Accessor
import com.petqua.domain.auth.Auth
import com.petqua.presentation.cart.dto.SaveCartProductRequest
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.support.ServletUriComponentsBuilder
Expand All @@ -19,11 +20,10 @@ class CartProductController(

@PostMapping
fun save(
// @AuthMember member: Long, TODO: AuthMember
@RequestHeader("X-MEMBER-ID") memberId: Long,
@Auth accessor: Accessor,
@RequestBody request: SaveCartProductRequest
): ResponseEntity<ProductDetailResponse> {
val command = request.toCommand(memberId)
val command = request.toCommand(accessor.memberId)
val cartProductId = cartProductService.save(command)
val location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/items/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import io.restassured.module.kotlin.extensions.Then
import io.restassured.module.kotlin.extensions.When
import org.assertj.core.api.SoftAssertions.assertSoftly
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpHeaders.AUTHORIZATION
import org.springframework.http.HttpStatus

private const val AUTHORIZATION_HEADER = "X-MEMBER-ID" // FIXME: 인가 구현 완료 후 변경 예정

class CartProductControllerTest(
private val productRepository: ProductRepository
) : ApiTestConfig() {
init {
val memberAuthResponse = signInAsMember()
val savedProduct = productRepository.save(product(id = 1L))
Given("봉달에 상품 저장을") {
val request = SaveCartProductRequest(
Expand All @@ -33,7 +33,7 @@ class CartProductControllerTest(
val response = Given {
log().all()
.body(request)
.header(AUTHORIZATION_HEADER, 1L)
.header(AUTHORIZATION, memberAuthResponse.accessToken)
.contentType("application/json")
} When {
post("/carts")
Expand Down Expand Up @@ -63,7 +63,7 @@ class CartProductControllerTest(
val response = Given {
log().all()
.body(request)
.header(AUTHORIZATION_HEADER, 1L)
.header(AUTHORIZATION, memberAuthResponse.accessToken)
.contentType("application/json")
} When {
post("/carts")
Expand Down Expand Up @@ -92,7 +92,7 @@ class CartProductControllerTest(
val response = Given {
log().all()
.body(request)
.header(AUTHORIZATION_HEADER, 1L)
.header(AUTHORIZATION, memberAuthResponse.accessToken)
.contentType("application/json")
} When {
post("/carts")
Expand Down

0 comments on commit 82b7dec

Please sign in to comment.