Skip to content

Commit 864d9fe

Browse files
committed
test: 이단계 테스트
1 parent fa4b93d commit 864d9fe

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

Diff for: src/test/java/roomescape/MissionStepTest.java

+49-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.HashMap;
1212
import java.util.Map;
13+
import roomescape.reservation.ReservationResponse;
1314

1415
import static org.assertj.core.api.Assertions.assertThat;
1516

@@ -19,9 +20,24 @@ public class MissionStepTest {
1920

2021
@Test
2122
void 일단계() {
23+
String token = createToken("[email protected]", "password");
24+
assertThat(token).isNotBlank();
25+
26+
ExtractableResponse<Response> checkResponse = RestAssured.given().log().all()
27+
.contentType(ContentType.JSON)
28+
.cookie("token", token)
29+
.when().get("/login/check")
30+
.then().log().all()
31+
.statusCode(200)
32+
.extract();
33+
34+
assertThat(checkResponse.body().jsonPath().getString("name")).isEqualTo("어드민");
35+
}
36+
37+
private static String createToken(final String mail, final String password) {
2238
Map<String, String> params = new HashMap<>();
23-
params.put("email", "[email protected]");
24-
params.put("password", "password");
39+
params.put("email", mail);
40+
params.put("password", password);
2541

2642
ExtractableResponse<Response> response = RestAssured.given().log().all()
2743
.contentType(ContentType.JSON)
@@ -31,17 +47,42 @@ public class MissionStepTest {
3147
.statusCode(200)
3248
.extract();
3349

34-
String token = response.headers().get("Set-Cookie").getValue().split(";")[0].split("=")[1];
35-
assertThat(token).isNotBlank();
50+
return response.headers().get("Set-Cookie").getValue().split(";")[0].split("=")[1];
51+
}
3652

37-
ExtractableResponse<Response> checkResponse = RestAssured.given().log().all()
53+
@Test
54+
void 이단계() {
55+
String token = createToken("[email protected]", "password"); // 일단계에서 토큰을 추출하는 로직을 메서드로 따로 만들어서 활용하세요.
56+
57+
Map<String, String> params = new HashMap<>();
58+
params.put("date", "2024-03-01");
59+
params.put("time", "1");
60+
params.put("theme", "1");
61+
62+
ExtractableResponse<Response> response = RestAssured.given().log().all()
63+
.body(params)
64+
.cookie("token", token)
3865
.contentType(ContentType.JSON)
66+
.post("/reservations")
67+
.then().log().all()
68+
.extract();
69+
70+
assertThat(response.statusCode()).isEqualTo(201);
71+
assertThat(response.as(ReservationResponse.class).getName()).isEqualTo("어드민");
72+
73+
params.put("name", "브라운");
74+
75+
ExtractableResponse<Response> adminResponse = RestAssured.given().log().all()
76+
.body(params)
3977
.cookie("token", token)
40-
.when().get("/login/check")
78+
.contentType(ContentType.JSON)
79+
.post("/reservations")
4180
.then().log().all()
42-
.statusCode(200)
4381
.extract();
4482

45-
assertThat(checkResponse.body().jsonPath().getString("name")).isEqualTo("어드민");
83+
assertThat(adminResponse.statusCode()).isEqualTo(201);
84+
assertThat(adminResponse.as(ReservationResponse.class).getName()).isEqualTo("브라운");
4685
}
86+
87+
4788
}

0 commit comments

Comments
 (0)