Skip to content

Commit

Permalink
feat: ๐ŸŽธ ๊ทธ๋ฃน ์ƒ์„ธ ์กฐํšŒ ๋ชฉ์—… API ๋ฐ ๋ฌธ์„œ ์ž‘์„ฑ
Browse files Browse the repository at this point in the history
โœ… Closes: #216
  • Loading branch information
Dae-Hwa committed Nov 21, 2021
1 parent ccba919 commit 3627e66
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/docs/asciidoc/group/group-read-one.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
== ๊ทธ๋ฃน ์ƒ์„ธ ์กฐํšŒ

=== `GET /groups/{groupId}`

=== `200 Ok`

operation::group_acceptance_test/read_one[snippets='path-parameters,response-fields,http-request,http-response']
3 changes: 3 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ include::user/email-validation.adoc[]
// ๋‹‰๋„ค์ž„ ์ค‘๋ณตํ™•์ธ
include::user/nickname-validation.adoc[]

// ๊ทธ๋ฃน ์ƒ์„ธ ์กฐํšŒ
include::group/group-read-one.adoc[]

// ๊ทธ๋ฃน ์ƒ์„ฑ
include::group/group-creation.adoc[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.postsquad.scoup.web.error.controller.response.ErrorResponse;
import com.postsquad.scoup.web.group.controller.request.GroupCreationRequest;
import com.postsquad.scoup.web.group.controller.request.GroupModificationRequest;
import com.postsquad.scoup.web.group.controller.response.GroupReadOneResponse;
import com.postsquad.scoup.web.group.exception.GroupCreationFailedException;
import com.postsquad.scoup.web.group.service.GroupService;
import com.postsquad.scoup.web.user.LoggedInUser;
Expand All @@ -21,6 +22,18 @@ public class GroupController {

private final GroupService groupService;

@GetMapping("/{groupId}")
public GroupReadOneResponse readOne(@PathVariable long groupId) {
// TODO: GroupService.readOne
return GroupReadOneResponse.builder()
.id(1L)
.image("image")
.name("name")
.description("description")
.build();
}


@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public DefaultPostResponse create(@RequestBody @Valid GroupCreationRequest groupCreationRequest, @LoggedInUser User user) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.postsquad.scoup.web.group.controller.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
// TODO: ์ „์ฒด์กฐํšŒ ๋จธ์ง€๋˜๋ฉด BaseResponse์™€ ํ•ฉ์น˜๊ธฐ
public class GroupReadOneResponse {

private long id;

private String name;

private String description;

private String image;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.postsquad.scoup.web.error.controller.response.ErrorResponse;
import com.postsquad.scoup.web.group.controller.request.GroupCreationRequest;
import com.postsquad.scoup.web.group.controller.request.GroupModificationRequest;
import com.postsquad.scoup.web.group.controller.response.GroupReadOneResponse;
import com.postsquad.scoup.web.group.domain.Group;
import com.postsquad.scoup.web.group.provider.*;
import io.restassured.RestAssured;
Expand All @@ -14,6 +15,7 @@
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -24,13 +26,33 @@
import java.util.ArrayList;

import static org.assertj.core.api.BDDAssertions.then;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.document;

public class GroupAcceptanceTest extends AcceptanceTestBase {

private static final Snippet GROUP_READ_ONE_PATH_PARAMETERS = pathParameters(
parameterWithName("groupId")
.description("๊ทธ๋ฃน ID")
);

private static final Snippet GROUP_READ_ONE_RESPONSE_FIELDS = responseFields(
fieldWithPath("id")
.type(JsonFieldType.NUMBER)
.description("id"),
fieldWithPath("name")
.type(JsonFieldType.STRING)
.description("์ด๋ฆ„"),
fieldWithPath("description")
.type(JsonFieldType.STRING)
.description("์„ค๋ช…"),
fieldWithPath("image")
.type(JsonFieldType.STRING)
.description("์ด๋ฏธ์ง€")
);

private static final Snippet GROUP_CREATION_REQUEST_FIELDS = requestFields(
fieldWithPathAndConstraints("name", GroupCreationRequest.class)
.type(JsonFieldType.STRING)
Expand Down Expand Up @@ -69,6 +91,53 @@ void setUp() {
testEntityManager.persist(testUser);
}

@Test
@DisplayName("์„ ํƒํ•œ ๊ทธ๋ฃน ์ •๋ณด๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.(์ด๋ฏธ ์ง€๋‚˜๊ฐ„ ์ผ์ •์€ ๋ณด์ด๋ฉด ์•ˆ ๋จ)")
void readOne() {
// given
Group givenGroup = Group.builder()
.name("name")
.description("description")
// TODO: .image("image")
.build();
testEntityManager.persist(givenGroup);
GroupReadOneResponse expectedGroupReadOneResponse = GroupReadOneResponse.builder()
.id(1L)
.image("image")
.name("name")
.description("description")
.build();
String path = "/groups/{groupId}";
RequestSpecification givenRequest = RestAssured.given(this.spec)
.baseUri(BASE_URL)
.port(port)
.basePath("/api")
.contentType(ContentType.JSON)
.header("Accept-Language", "en-US")
.header("Authorization", TEST_TOKEN)
.pathParam("groupId", givenGroup.getId());

//when
Response actualResponse = givenRequest.when()
.filter(document(
DEFAULT_RESTDOCS_PATH,
GROUP_READ_ONE_PATH_PARAMETERS,
GROUP_READ_ONE_RESPONSE_FIELDS
))
.log().all()
.get(path);

//then
actualResponse.then()
.log().all()
.statusCode(HttpStatus.OK.value());
then(actualResponse.as(GroupReadOneResponse.class))
// TODO: Add description
.usingRecursiveComparison()
.ignoringFields(ignoringFieldsForResponseWithId)
.isEqualTo(expectedGroupReadOneResponse);
}

@ParameterizedTest
@ArgumentsSource(CreateGroupProvider.class)
@DisplayName("์‚ฌ์šฉ์ž๊ฐ€ ์ƒˆ๋กœ์šด ๊ทธ๋ฃน์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค")
Expand Down

0 comments on commit 3627e66

Please sign in to comment.