Skip to content

Commit

Permalink
test: 전체 태그 목록을 조회하는 인수 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Go-Jaecheol committed Jul 27, 2023
1 parent 18a5e1c commit 65b3d7f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.funeat.acceptance.tag;

import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE_검증한다;
import static com.funeat.acceptance.common.CommonSteps.정상_처리;
import static com.funeat.acceptance.tag.TagSteps.전체_태그_목록_조회_요청;
import static com.funeat.tag.domain.TagType.ETC;
import static com.funeat.tag.domain.TagType.PRICE;
import static com.funeat.tag.domain.TagType.TASTE;
import static org.assertj.core.api.Assertions.assertThat;

import com.funeat.acceptance.common.AcceptanceTest;
import com.funeat.tag.domain.Tag;
import com.funeat.tag.domain.TagType;
import com.funeat.tag.dto.TagsResponse;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;

@SuppressWarnings("NonAsciiCharacters")
public class TagAcceptanceTest extends AcceptanceTest {

@Test
void 전체_태그_목록을_조회할__있다() {
// given
final var tag1 = 태그_가_요청(new Tag("단짠단짠", TASTE));
final var tag2 = 태그_가_요청(new Tag("매콤해요", TASTE));
final var tag3 = 태그_가_요청(new Tag("갓성비", PRICE));
final var tag4 = 태그_가_요청(new Tag("바삭바삭", ETC));

// when
final var response = 전체_태그_목록_조회_요청();

// then
STATUS_CODE_검증한다(response, 정상_처리);
전체_태그_목록_조회_결과를_검증한다(response, List.of(tag1, tag2, tag3, tag4));
}

private Tag 태그_가_요청(final Tag tag) {
return tagRepository.save(tag);
}

private void 전체_태그_목록_조회_결과를_검증한다(final ExtractableResponse<Response> response, final List<Tag> tags) {
final var expectedByType = tags.stream().collect(Collectors.groupingBy(Tag::getTagType));
final var actual = response.jsonPath().getList("", TagsResponse.class);

for (final TagsResponse tagsResponse : actual) {
final TagType tagType = TagType.valueOf(tagsResponse.getTagType());
assertThat(tagType).isIn(expectedByType.keySet());
assertThat(tagsResponse.getTags()).usingRecursiveComparison()
.isEqualTo(expectedByType.get(tagType));
}
}
}
18 changes: 18 additions & 0 deletions backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.funeat.acceptance.tag;

import static io.restassured.RestAssured.given;

import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;

@SuppressWarnings("NonAsciiCharacters")
public class TagSteps {

public static ExtractableResponse<Response> 전체_태그_목록_조회_요청() {
return given()
.when()
.get("/api/tags")
.then()
.extract();
}
}

0 comments on commit 65b3d7f

Please sign in to comment.