1
+ package com .tune_fun .v1 .vote .adapter .input .rest ;
2
+
3
+ import com .tune_fun .v1 .base .ControllerBaseTest ;
4
+ import com .tune_fun .v1 .common .config .Uris ;
5
+ import com .tune_fun .v1 .common .response .MessageCode ;
6
+ import com .tune_fun .v1 .dummy .DummyService ;
7
+ import com .tune_fun .v1 .vote .application .port .input .command .VotePaperCommands ;
8
+ import org .junit .jupiter .api .DisplayName ;
9
+ import org .junit .jupiter .api .Order ;
10
+ import org .junit .jupiter .api .Test ;
11
+ import org .springframework .beans .factory .annotation .Autowired ;
12
+ import org .springframework .restdocs .payload .FieldDescriptor ;
13
+
14
+ import java .util .List ;
15
+ import java .util .Set ;
16
+
17
+ import static com .epages .restdocs .apispec .ResourceDocumentation .resource ;
18
+ import static com .epages .restdocs .apispec .ResourceSnippetParameters .builder ;
19
+ import static com .tune_fun .v1 .base .doc .RestDocsConfig .constraint ;
20
+ import static java .time .LocalDateTime .now ;
21
+ import static org .springframework .http .HttpHeaders .AUTHORIZATION ;
22
+ import static org .springframework .http .MediaType .APPLICATION_JSON_VALUE ;
23
+ import static org .springframework .restdocs .headers .HeaderDocumentation .requestHeaders ;
24
+ import static org .springframework .restdocs .mockmvc .RestDocumentationRequestBuilders .post ;
25
+ import static org .springframework .restdocs .payload .PayloadDocumentation .fieldWithPath ;
26
+ import static org .springframework .restdocs .payload .PayloadDocumentation .requestFields ;
27
+
28
+ class VotePaperControllerIT extends ControllerBaseTest {
29
+
30
+ @ Autowired
31
+ private DummyService dummyService ;
32
+
33
+ @ Test
34
+ @ Order (1 )
35
+ @ DisplayName ("투표 게시물 등록, 성공" )
36
+ void registerVotePaperSuccess () throws Exception {
37
+ dummyService .initArtistAccount ();
38
+
39
+ dummyService .login (dummyService .getDefaultAccount ());
40
+ String accessToken = dummyService .getDefaultAccessToken ();
41
+
42
+ Set <VotePaperCommands .Offer > offers = Set .of (
43
+ new VotePaperCommands .Offer ("Love Lee" , "AKMU" , List .of ("R&B" , "Soul" ),
44
+ 300000 , "2024-04-28" ),
45
+ new VotePaperCommands .Offer ("Dolphin" , "오마이걸" , List .of ("Dance" , "Pop" ),
46
+ 200000 , "2020-04-27" )
47
+ );
48
+ VotePaperCommands .Register command = new VotePaperCommands .Register ("First Vote Paper" , "test" ,
49
+ "deny-add-choices" , now ().plusDays (1 ), now ().plusDays (2 ), offers );
50
+
51
+ FieldDescriptor [] requestDescriptors = {
52
+ fieldWithPath ("title" ).description ("투표 게시물 제목" ).attributes (constraint ("NOT BLANK" )),
53
+ fieldWithPath ("content" ).description ("투표 게시물 내용" ).attributes (constraint ("NOT BLANK" )),
54
+ fieldWithPath ("option" ).description ("투표 종류" ).attributes (constraint ("NOT BLANK" )),
55
+ fieldWithPath ("startAt" ).description ("투표 시작 시간" ).attributes (constraint ("NOT NULL & FUTURE & BEFORE(endAt)" )),
56
+ fieldWithPath ("endAt" ).description ("투표 종료 시간" ).attributes (constraint ("NOT NULL & FUTURE & AFTER(startAt)" )),
57
+ fieldWithPath ("offers" ).description ("투표 선택지 목록" ).attributes (constraint ("NOT EMPTY" )),
58
+ fieldWithPath ("offers[].name" ).description ("노래명" ).attributes (constraint ("NOT BLANK" )),
59
+ fieldWithPath ("offers[].artistName" ).description ("가수명" ).attributes (constraint ("NOT BLANK" )),
60
+ fieldWithPath ("offers[].genres" ).description ("장르" ).attributes (constraint ("NOT EMPTY" )),
61
+ fieldWithPath ("offers[].durationMs" ).description ("재생 시간(ms)" ).attributes (constraint ("NOT NULL & POSITIVE" )),
62
+ fieldWithPath ("offers[].releaseDate" ).description ("발매일" ).attributes (constraint ("NOT BLANK" ))
63
+ };
64
+
65
+ mockMvc .perform (
66
+ post (Uris .REGISTER_VOTE_PAPER )
67
+ .header (AUTHORIZATION , bearerToken (accessToken ))
68
+ .content (toJson (command ))
69
+ .contentType (APPLICATION_JSON_VALUE )
70
+ )
71
+ .andExpectAll (baseAssertion (MessageCode .SUCCESS ))
72
+ .andDo (
73
+ restDocs .document (
74
+ requestHeaders (authorizationHeader ),
75
+ requestFields (requestDescriptors ),
76
+ resource (
77
+ builder ().
78
+ description ("투표 게시물 등록" ).
79
+ requestFields (requestDescriptors )
80
+ .build ()
81
+ )
82
+ )
83
+ );
84
+ }
85
+
86
+ }
0 commit comments