Skip to content

Commit

Permalink
[#54] test: Article 저장 인수 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
kwj1270 committed Nov 24, 2021
1 parent 3a612f4 commit 6f00710
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.study.realworld.domain.article.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;

import java.util.List;

public class ArticleSave {

@Builder
public static class Request {

@JsonProperty("title")
private String title;

@JsonProperty("description")
private String description;

@JsonProperty("body")
private String body;

@JsonProperty("tagList")
private List<String> tags;

@Builder
public Request(final String title, final String description, final String body, final List<String> tags) {
this.title = title;
this.description = description;
this.body = body;
this.tags = tags;
}
}

public static class Response {
public String slug() {
return "how-to-train-your-dragon";
}

public String title() {
return "how to train your dragon";
}

public String description() {
return "Ever wonder how?";
}

public String body() {
return "It takes a Jacobian";
}

public List<String> tags() {
return List.of("dragons", "training");
}

public String createdAt() {
return "2016-02-18T03:22:56.637Z";
}

public String updatedAt() {
return "2016-02-18T03:48:35.824Z";
}

public boolean favorited() {
return false;
}

public int favoritesCount() {
return 0;
}

public AuthDto author() {
return new AuthDto();
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/study/realworld/domain/article/dto/AuthDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.study.realworld.domain.article.dto;

import com.study.realworld.domain.user.domain.vo.UserBio;
import com.study.realworld.domain.user.domain.vo.UserImage;
import com.study.realworld.domain.user.domain.vo.UserName;

public class AuthDto {

private UserName userName;
private UserBio userBio;
private UserImage userImage;
private boolean following;

public UserName userName() {
return userName;
}

public UserBio userBio() {
return userBio;
}

public UserName userImage() {
return userName;
}

public boolean following() {
return following;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.study.realworld.acceptance;

import com.study.realworld.domain.article.dto.ArticleSave;
import com.study.realworld.domain.auth.dto.Login;
import com.study.realworld.domain.user.dto.UserJoin;
import com.study.realworld.global.common.AccessToken;
import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

public class ArticleAcceptanceTest extends AcceptanceTest {

private UserJoin.Response user1;
private UserJoin.Response user2;

@Override
@BeforeEach
public void setUp() {
super.setUp();

final String user1String = "woozi@naver.com";
user1 = 회원_가입_되어있음(user1String);

final String user2String = "ori@naver.com";
user2 = 회원_가입_되어있음(user2String);
}

@Test
void 게시글을_등록한다() {
final Login.Response loginResponse = 로그인_되어있음(user1.userEmail().value());
final ExtractableResponse<Response> response = 정상적인_게시글_등록_요청(loginResponse.accessToken());
final ArticleSave.Response articleResponse = response.as(ArticleSave.Response.class);

assertAll(
() -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()),
() -> assertThat(articleResponse.slug()).isEqualTo("how-to-train-your-dragon"),
() -> assertThat(articleResponse.title()).isEqualTo("how to train your dragon"),
() -> assertThat(articleResponse.description()).isEqualTo("Ever wonder how?"),
() -> assertThat(articleResponse.body()).isEqualTo("It takes a Jacobian"),
() -> assertThat(articleResponse.tags()).isEqualTo(List.of("dragons", "training")),
() -> assertThat(articleResponse.createdAt()).isEqualTo("2016-02-18T03:22:56.637Z"),
() -> assertThat(articleResponse.updatedAt()).isEqualTo("2016-02-18T03:48:35.824Z"),
() -> assertThat(articleResponse.favorited()).isEqualTo(false),
() -> assertThat(articleResponse.favoritesCount()).isEqualTo(0),
() -> assertThat(articleResponse.author().userName()).isEqualTo("jake"),
() -> assertThat(articleResponse.author().userBio()).isEqualTo("I work at statefarm"),
() -> assertThat(articleResponse.author().userImage()).isEqualTo("https://i.stack.imgur.com/xHWG8.jpg"),
() -> assertThat(articleResponse.author().following()).isEqualTo(false)
);
}

protected ExtractableResponse<Response> 정상적인_게시글_등록_요청(final AccessToken accessToken) {
final ArticleSave.Request request = 정상적인_게시글_정보();
return RestAssured.given()
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(request)
.when()
.post("/api/articles")
.then()
.extract();
}

protected ArticleSave.Request 정상적인_게시글_정보() {
return ArticleSave.Request.builder()
.title("How to train your dragon")
.description("Ever wonder how?")
.body("You have to believe")
.tags(List.of("reactjs", "angularjs", "dragons"))
.build();
}
}

0 comments on commit 6f00710

Please sign in to comment.