11package org .clokey .domain .member .controller ;
22
3+ import static org .hamcrest .Matchers .containsString ;
34import static org .mockito .ArgumentMatchers .any ;
45import static org .mockito .BDDMockito .given ;
56import static org .mockito .BDDMockito .willDoNothing ;
910
1011import com .fasterxml .jackson .databind .ObjectMapper ;
1112import java .util .List ;
12- import org .clokey .domain .member .dto .request .DuplicatedIdCheckRequest ;
13+ import org .clokey .domain .member .dto .request .DuplicatedNicknameCheckRequest ;
1314import org .clokey .domain .member .dto .request .ProfileUpdateRequest ;
1415import org .clokey .domain .member .dto .response .*;
1516import org .clokey .domain .member .service .MemberService ;
@@ -94,7 +95,9 @@ class 프로필_수정_요청_시 {
9495 .andExpect (jsonPath ("$.isSuccess" ).value (false ))
9596 .andExpect (jsonPath ("$.code" ).value ("COMMON400" ))
9697 .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ))
97- .andExpect (jsonPath ("$.result.nickname" ).value ("닉네임은 비워둘 수 없습니다." ));
98+ .andExpect (
99+ jsonPath ("$.result.nickname" )
100+ .value (containsString ("닉네임은 비워둘 수 없습니다." )));
98101 }
99102
100103 @ ParameterizedTest
@@ -121,7 +124,9 @@ class 프로필_수정_요청_시 {
121124 .andExpect (jsonPath ("$.isSuccess" ).value (false ))
122125 .andExpect (jsonPath ("$.code" ).value ("COMMON400" ))
123126 .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ))
124- .andExpect (jsonPath ("$.result.nickname" ).value ("닉네임은 비워둘 수 없습니다." ));
127+ .andExpect (
128+ jsonPath ("$.result.nickname" )
129+ .value (containsString ("닉네임은 비워둘 수 없습니다." )));
125130 }
126131
127132 @ Test
@@ -157,7 +162,8 @@ class 아이디_중복확인_요청_시 {
157162 @ Test
158163 void 유효한_요청이면_중복_여부를_반환한다 () throws Exception {
159164 // given
160- DuplicatedIdCheckRequest request = new DuplicatedIdCheckRequest ("test_clokey_id" );
165+ DuplicatedNicknameCheckRequest request =
166+ new DuplicatedNicknameCheckRequest ("clokey.홍길동" );
161167 DuplicatedIdCheckResponse response = new DuplicatedIdCheckResponse (true );
162168
163169 given (memberService .checkDuplicateNickname (request )).willReturn (response );
@@ -180,7 +186,7 @@ class 아이디_중복확인_요청_시 {
180186 @ Test
181187 void 닉네임이_null이면_예외가_발생한다 () throws Exception {
182188 // given
183- DuplicatedIdCheckRequest request = new DuplicatedIdCheckRequest (null );
189+ DuplicatedNicknameCheckRequest request = new DuplicatedNicknameCheckRequest (null );
184190
185191 // when
186192 ResultActions perform =
@@ -197,12 +203,37 @@ class 아이디_중복확인_요청_시 {
197203 .andExpect (jsonPath ("$.result.nickname" ).value ("닉네임은 비워둘 수 없습니다." ));
198204 }
199205
200- // 허용 종류 : 영문(소문자) , 숫자, 언더바(_), 점(.)
201206 @ ParameterizedTest
202- @ ValueSource (strings = {"clokey clokey" , "CLOKEY" , "클로키" , "clokey-user" , "clokey,,user^^" })
207+ @ NullAndEmptySource
208+ @ ValueSource (strings = {" " })
209+ void 닉네임이_비어있으면_예외가_발생한다 (String nickname ) throws Exception {
210+ // given
211+ DuplicatedNicknameCheckRequest request = new DuplicatedNicknameCheckRequest (nickname );
212+
213+ // when
214+ ResultActions perform =
215+ mockMvc .perform (
216+ post ("/users/check-duplicate-nickname" )
217+ .contentType (MediaType .APPLICATION_JSON )
218+ .content (objectMapper .writeValueAsString (request )));
219+
220+ // then
221+ perform .andExpect (status ().isBadRequest ())
222+ .andExpect (jsonPath ("$.isSuccess" ).value (false ))
223+ .andExpect (jsonPath ("$.code" ).value ("COMMON400" ))
224+ .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ))
225+ .andExpect (
226+ jsonPath ("$.result.nickname" )
227+ .value (containsString ("닉네임은 비워둘 수 없습니다." )));
228+ }
229+
230+ // 허용 종류 : 영어 소문자, 한글, 언더바(_), 점(.)
231+ @ ParameterizedTest
232+ @ ValueSource (
233+ strings = {"clokey clokey" , "CLOKEY" , "clokey-user" , "clokey,,user^^" , "clokey1" })
203234 void 닉네임_제약조건을_위배하면_예외가_발생한다 (String nickname ) throws Exception {
204235 // given
205- DuplicatedIdCheckRequest request = new DuplicatedIdCheckRequest (nickname );
236+ DuplicatedNicknameCheckRequest request = new DuplicatedNicknameCheckRequest (nickname );
206237
207238 // when
208239 ResultActions perform =
@@ -218,7 +249,51 @@ class 아이디_중복확인_요청_시 {
218249 .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ))
219250 .andExpect (
220251 jsonPath ("$.result.nickname" )
221- .value ("닉네임은 영어 소문자, 숫자, 언더바(_), 점(.)만 허용됩니다." ));
252+ .value ("닉네임은 영어 소문자, 한글, 언더바(_), 점(.)만 허용됩니다." ));
253+ }
254+
255+ @ Test
256+ void 닉네임이_20자를_초과하면_예외가_발생한다 () throws Exception {
257+ // given
258+ DuplicatedNicknameCheckRequest request =
259+ new DuplicatedNicknameCheckRequest ("abcdefghijklmnopqrstu" );
260+
261+ // when
262+ ResultActions perform =
263+ mockMvc .perform (
264+ post ("/users/check-duplicate-nickname" )
265+ .contentType (MediaType .APPLICATION_JSON )
266+ .content (objectMapper .writeValueAsString (request )));
267+
268+ // then
269+ perform .andExpect (status ().isBadRequest ())
270+ .andExpect (jsonPath ("$.isSuccess" ).value (false ))
271+ .andExpect (jsonPath ("$.code" ).value ("COMMON400" ))
272+ .andExpect (jsonPath ("$.message" ).value ("잘못된 요청입니다." ))
273+ .andExpect (jsonPath ("$.result.nickname" ).value ("닉네임은 20자 이하여야 합니다." ));
274+ }
275+
276+ @ ParameterizedTest
277+ @ ValueSource (strings = {"clokey" , "홍길동" , "clokey.홍길동" , "abc_def" })
278+ void 닉네임_제약조건을_만족하면_중복_여부를_반환한다 (String nickname ) throws Exception {
279+ // given
280+ DuplicatedNicknameCheckRequest request = new DuplicatedNicknameCheckRequest (nickname );
281+ DuplicatedIdCheckResponse response = new DuplicatedIdCheckResponse (false );
282+ given (memberService .checkDuplicateNickname (request )).willReturn (response );
283+
284+ // when
285+ ResultActions perform =
286+ mockMvc .perform (
287+ post ("/users/check-duplicate-nickname" )
288+ .contentType (MediaType .APPLICATION_JSON )
289+ .content (objectMapper .writeValueAsString (request )));
290+
291+ // then
292+ perform .andExpect (status ().isOk ())
293+ .andExpect (jsonPath ("$.isSuccess" ).value (true ))
294+ .andExpect (jsonPath ("$.code" ).value ("COMMON200" ))
295+ .andExpect (jsonPath ("$.message" ).value ("성공입니다." ))
296+ .andExpect (jsonPath ("$.result.duplicated" ).value (false ));
222297 }
223298 }
224299
0 commit comments