Skip to content

Commit

Permalink
Test | #88 | @YongsHub | 케이크 수정 및 삭제를 위한 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
YongsHub committed Jun 17, 2024
1 parent d498d0c commit e97c796
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static org.junit.Assert.*;
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.*;

import java.util.List;

import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
Expand All @@ -16,6 +18,7 @@

import com.cakk.api.common.base.IntegrationTest;
import com.cakk.api.common.annotation.TestWithDisplayName;
import com.cakk.api.dto.request.cake.CakeUpdateRequest;
import com.cakk.api.dto.response.cake.CakeImageListResponse;
import com.cakk.common.enums.CakeDesignCategory;
import com.cakk.common.enums.ReturnCode;
Expand Down Expand Up @@ -417,4 +420,59 @@ void heartCancelCake() {
assertEquals(ReturnCode.SUCCESS.getMessage(), response.getReturnMessage());
assertNull(response.getData());
}

@TestWithDisplayName("케이크 정보 업데이트에 성공한다")
void updateCake() {
// given
final Long cakeId = 1L;
final String url = "%s%d%s/{cakeId}".formatted(BASE_URL, port, API_URL);
final UriComponents uriComponents = UriComponentsBuilder
.fromUriString(url)
.buildAndExpand(cakeId);
final CakeUpdateRequest request = getConstructorMonkey().giveMeBuilder(CakeUpdateRequest.class)
.set("tagNames", List.of("tag_name1", "new_tag"))
.sample();


// when
final ResponseEntity<ApiResponse> responseEntity = restTemplate.exchange(
uriComponents.toUriString(),
HttpMethod.PUT,
new HttpEntity<>(request, getAuthHeader()),
ApiResponse.class);

// then
final ApiResponse response = objectMapper.convertValue(responseEntity.getBody(), ApiResponse.class);

assertEquals(HttpStatusCode.valueOf(200), responseEntity.getStatusCode());
assertEquals(ReturnCode.SUCCESS.getCode(), response.getReturnCode());
assertEquals(ReturnCode.SUCCESS.getMessage(), response.getReturnMessage());
assertNull(response.getData());
}

@TestWithDisplayName("케이크 삭제에 성공한다")
void deleteCake() {
// given
final Long cakeId = 1L;
final String url = "%s%d%s/{cakeId}".formatted(BASE_URL, port, API_URL);
final UriComponents uriComponents = UriComponentsBuilder
.fromUriString(url)
.buildAndExpand(cakeId);


// when
final ResponseEntity<ApiResponse> responseEntity = restTemplate.exchange(
uriComponents.toUriString(),
HttpMethod.DELETE,
new HttpEntity<>(getAuthHeader()),
ApiResponse.class);

// then
final ApiResponse response = objectMapper.convertValue(responseEntity.getBody(), ApiResponse.class);

assertEquals(HttpStatusCode.valueOf(200), responseEntity.getStatusCode());
assertEquals(ReturnCode.SUCCESS.getCode(), response.getReturnCode());
assertEquals(ReturnCode.SUCCESS.getMessage(), response.getReturnMessage());
assertNull(response.getData());
}
}
4 changes: 4 additions & 0 deletions cakk-api/src/test/resources/sql/insert-cake.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ values (1, 1, 'cake_image_url1', 0, now(), now()),
(17, 9, 'cake_image_url12', 0, now(), now()),
(18, 10, 'cake_image_url12', 0, now(), now());

insert into business_information(business_number, shop_id, user_id)
values ('010-3375-5555', 1, 1),
('010-3375-5555', 2, 2),
('010-3375-5555', 3, 3);

insert into tag(tag_id, tag_name, created_at)
values (1, 'tag_name1', now()),
Expand Down

0 comments on commit e97c796

Please sign in to comment.