10
10
11
11
import java .util .HashMap ;
12
12
import java .util .Map ;
13
+ import roomescape .reservation .ReservationResponse ;
13
14
14
15
import static org .assertj .core .api .Assertions .assertThat ;
15
16
@@ -19,9 +20,24 @@ public class MissionStepTest {
19
20
20
21
@ Test
21
22
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 ) {
22
38
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 );
25
41
26
42
ExtractableResponse <Response > response = RestAssured .given ().log ().all ()
27
43
.contentType (ContentType .JSON )
@@ -31,17 +47,42 @@ public class MissionStepTest {
31
47
.statusCode (200 )
32
48
.extract ();
33
49
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
+ }
36
52
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 )
38
65
.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 )
39
77
.cookie ("token" , token )
40
- .when ().get ("/login/check" )
78
+ .contentType (ContentType .JSON )
79
+ .post ("/reservations" )
41
80
.then ().log ().all ()
42
- .statusCode (200 )
43
81
.extract ();
44
82
45
- assertThat (checkResponse .body ().jsonPath ().getString ("name" )).isEqualTo ("어드민" );
83
+ assertThat (adminResponse .statusCode ()).isEqualTo (201 );
84
+ assertThat (adminResponse .as (ReservationResponse .class ).getName ()).isEqualTo ("브라운" );
46
85
}
86
+
87
+
47
88
}
0 commit comments