Skip to content

Commit

Permalink
[BE] feat: Cucumber 테스트 수정(#487) (#489)
Browse files Browse the repository at this point in the history
* test: 학교 생성 스텝 추가 및 반영

* test: log all 삭제

* test: 축제 생성 테스트에 학교 생성 과정 포함
  • Loading branch information
BGuga committed Oct 17, 2023
1 parent b1303f4 commit ed2d792
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.festago.festival.dto.FestivalDetailResponse;
import com.festago.festival.dto.FestivalResponse;
import com.festago.festival.dto.FestivalsResponse;
import com.festago.school.dto.SchoolCreateRequest;
import com.festago.school.dto.SchoolResponse;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.restassured.RestAssured;
Expand All @@ -30,38 +32,51 @@ public void login() {
.contentType(ContentType.JSON)
.body(new RootAdminInitializeRequest(password))
.post("admin/initialize")
.then().log().all()
.then()
.statusCode(200);

ExtractableResponse<Response> response = RestAssured.given()
.contentType(ContentType.JSON)
.body(new AdminLoginRequest("admin", password))
.post("admin/login")
.then().log().all()
.then()
.extract();

String token = "token";
cucumberClient.addAuthToken(response.cookie(token));
cucumberClient.addAuthToken(response.cookie("token"));
}

@Given("축제를 생성하고")
public void given() {

SchoolResponse schoolResponse = (SchoolResponse) cucumberClient.getData("schoolResponse");
FestivalCreateRequest request = new FestivalCreateRequest("푸우 축제", LocalDate.now(),
LocalDate.now().plusDays(1), "thumnail");
LocalDate.now().plusDays(1), "thumnail", schoolResponse.id());
FestivalResponse response = RestAssured.given()
.contentType(ContentType.JSON)
.cookie("token", cucumberClient.getToken())
.body(request)
.post("admin/festivals")
.then()
.log().all()
.extract()
.body()
.as(FestivalResponse.class);
cucumberClient.addData("festivalData", response);
}

@Given("{string}를 생성하고")
public void makeSchool(String schoolName) {
SchoolCreateRequest request = new SchoolCreateRequest(schoolName, "domain.com");
SchoolResponse response = RestAssured.given()
.contentType(ContentType.JSON)
.cookie("token", cucumberClient.getToken())
.body(request)
.post("admin/schools")
.then()
.extract()
.body()
.as(SchoolResponse.class);
cucumberClient.addData("schoolResponse", response);
}

@Then("축제가 있다")
public void then() {
FestivalDetailResponse response = (FestivalDetailResponse) cucumberClient.getData("searchResult");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void given() {
FestivalDetailResponse festivalInfo = RestAssured.given()
.when()
.get("festivals/{festivalId}", response.id())
.then().log().all()
.then()
.extract()
.as(FestivalDetailResponse.class);
cucumberClient.addData("searchResult", festivalInfo);
Expand Down
1 change: 1 addition & 0 deletions backend/src/test/resources/features/example.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Feature: 축제 생성

Scenario: 성공
Given 로그인을 한 상태에서
Given "테코대학교"를 생성하고
Given 축제를 생성하고
When 축제를 검색하면
Then 축제가 있다
Expand Down

0 comments on commit ed2d792

Please sign in to comment.