From 65b3d7ff2f47f66e1b4a06f701a0e96d11875513 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 28 Jul 2023 01:53:23 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=A0=84=EC=B2=B4=20=ED=83=9C=EA=B7=B8?= =?UTF-8?q?=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B8=EC=88=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acceptance/tag/TagAcceptanceTest.java | 55 +++++++++++++++++++ .../com/funeat/acceptance/tag/TagSteps.java | 18 ++++++ 2 files changed, 73 insertions(+) create mode 100644 backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java create mode 100644 backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java diff --git a/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java new file mode 100644 index 000000000..18e3d8228 --- /dev/null +++ b/backend/src/test/java/com/funeat/acceptance/tag/TagAcceptanceTest.java @@ -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, final List 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)); + } + } +} diff --git a/backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java b/backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java new file mode 100644 index 000000000..53dae95a1 --- /dev/null +++ b/backend/src/test/java/com/funeat/acceptance/tag/TagSteps.java @@ -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 전체_태그_목록_조회_요청() { + return given() + .when() + .get("/api/tags") + .then() + .extract(); + } +}