@@ -214,95 +214,85 @@ void evaluateLetter_Success() throws Exception {
214214 );
215215 }
216216 @ Test
217- @ DisplayName ("POST /api/letters/{letterId}/ temporary-save - 편지 임시 저장 성공 테스트" )
217+ @ DisplayName ("POST /api/letters/temporary-save - 편지 임시 저장 성공 테스트" )
218218 void temporarySaveLetter_success () throws Exception {
219219 // given
220- Long letterId = 1L ;
220+ Long writerId = 2L ;
221+
222+ Long receiverId = 1L ;
223+ Long matchingId = 1L ;
224+ Long parentLetterId = 1L ;
225+ String title = "임시 저장 제목(처음)" ;
226+ String content = "임시 저장 내용(처음)" ;
227+ Category category = Category .CONSULT ;
228+ PaperType paperType = PaperType .BASIC ;
229+ FontType fontType = FontType .DEFAULT ;
230+
231+ TemporarySaveLetterRequest request = new TemporarySaveLetterRequest (
232+ null , receiverId , matchingId , parentLetterId , title , content , category , paperType , fontType
233+ );
221234
222- TemporarySaveLetterRequest request = new TemporarySaveLetterRequest ();
223- request .setTitle ("임시 저장 제목" );
224- request .setContent ("임시 저장할 내용입니다." );
225- request .setCategory (Category .ETC );
226- request .setPaperType (PaperType .PAPER );
227- request .setFontType (FontType .GYEONGGI );
235+ Long letterId = 10L ;
236+ String zipCode = "11111" ;
228237
229238 LetterResponse expectedResponse = LetterResponse .builder ()
230239 .letterId (letterId )
231- .writerId (1L )
232- .title ("임시 저장 제목" )
233- .content ("임시 저장할 내용입니다." )
234- .category (Category .ETC )
235- .paperType (PaperType .PAPER )
236- .fontType (FontType .GYEONGGI )
240+ .writerId (writerId )
241+ .receiverId (receiverId )
242+ .parentLetterId (parentLetterId )
243+ .zipCode (zipCode )
244+ .title (title )
245+ .content (content )
246+ .category (category )
247+ .paperType (paperType )
248+ .fontType (fontType )
249+ .status (Status .SAVED )
250+ .matchingId (matchingId )
237251 .build ();
238252
239- when (letterService .temporarySaveLetter (eq ( letterId ), any (TemporarySaveLetterRequest .class )))
253+ when (letterService .temporarySaveLetter (any (TemporarySaveLetterRequest .class )))
240254 .thenReturn (expectedResponse );
241255
242256 // when & then
243- mockMvc .perform (post ("/api/letters/{letterId}/ temporary-save" , letterId )
257+ mockMvc .perform (post ("/api/letters/temporary-save" )
244258 .contentType (MediaType .APPLICATION_JSON )
245259 .content (objectMapper .writeValueAsString (request )))
246260 .andExpect (status ().isOk ())
247261 .andExpect (jsonPath ("$.message" ).value ("임시 저장 완료 " ))
248- .andExpect (jsonPath ("$.data.letterId" ).value (letterId ))
249- .andExpect (jsonPath ("$.data.title" ).value ("임시 저장 제목" ))
250- .andExpect (jsonPath ("$.data.content" ).value ("임시 저장할 내용입니다." ))
251- .andExpect (jsonPath ("$.data.category" ).value ("ETC" ))
252- .andExpect (jsonPath ("$.data.paperType" ).value ("PAPER" ))
253- .andExpect (jsonPath ("$.data.fontType" ).value ("GYEONGGI" ))
254- .andDo (print ());
255-
256- verify (letterService ).temporarySaveLetter (eq (letterId ), any (TemporarySaveLetterRequest .class ));
257- }
258-
259-
260-
261- @ Test
262- @ DisplayName ("POST /api/letters/{letterId}/temporary-save - 존재하지 않는 편지 임시 저장 실패 테스트" )
263- void temporarySaveLetter_fail_letterNotFound () throws Exception {
264- // given
265- Long nonExistentLetterId = 999L ;
266-
267- TemporarySaveLetterRequest request = new TemporarySaveLetterRequest ();
268- request .setTitle ("임시 저장 제목" );
269- request .setContent ("임시 저장할 내용입니다." );
270-
271- doThrow (new LetterNotFoundException ())
272- .when (letterService )
273- .temporarySaveLetter (eq (nonExistentLetterId ), any (TemporarySaveLetterRequest .class ));
274-
275- // when & then
276- mockMvc .perform (post ("/api/letters/{letterId}/temporary-save" , nonExistentLetterId )
277- .contentType (MediaType .APPLICATION_JSON )
278- .content (objectMapper .writeValueAsString (request )))
279- .andExpect (status ().isNotFound ())
280- .andExpect (jsonPath ("$.code" ).value ("LET-001" ))
281- .andExpect (jsonPath ("$.message" ).value ("해당 편지를 찾을 수 없습니다." ))
262+ .andExpect (jsonPath ("$.data.title" ).value (expectedResponse .getTitle ()))
263+ .andExpect (jsonPath ("$.data.content" ).value (expectedResponse .getContent ()))
264+ .andExpect (jsonPath ("$.data.category" ).value (expectedResponse .getCategory ().toString ()))
265+ .andExpect (jsonPath ("$.data.paperType" ).value (expectedResponse .getPaperType ().toString ()))
266+ .andExpect (jsonPath ("$.data.fontType" ).value (expectedResponse .getFontType ().toString ()))
282267 .andDo (print ());
283268
284- verify (letterService ).temporarySaveLetter (
285- eq (nonExistentLetterId ),
286- any (TemporarySaveLetterRequest .class )
287- );
269+ verify (letterService ).temporarySaveLetter (any (TemporarySaveLetterRequest .class ));
288270 }
289271
290272 @ Test
291- @ DisplayName ("POST /api/letters/{letterId}/ temporary-save - 권한 없는 편지 임시 저장 실패 테스트" )
273+ @ DisplayName ("POST /api/letters/temporary-save - 권한 없는 편지 임시 저장 실패 테스트" )
292274 void temporarySaveLetter_fail_notBelongLetter () throws Exception {
293275 // given
294- Long unauthorizedLetterId = 888L ;
295-
296- TemporarySaveLetterRequest request = new TemporarySaveLetterRequest ();
297- request .setTitle ("임시 저장 제목" );
298- request .setContent ("임시 저장할 내용입니다." );
276+ Long invalidLetterId = 999L ;
277+ Long receiverId = 1L ;
278+ Long matchingId = 1L ;
279+ Long parentLetterId = 1L ;
280+ String title = "임시 저장 제목(처음)" ;
281+ String content = "임시 저장 내용(처음)" ;
282+ Category category = Category .CONSULT ;
283+ PaperType paperType = PaperType .BASIC ;
284+ FontType fontType = FontType .DEFAULT ;
285+
286+ TemporarySaveLetterRequest request = new TemporarySaveLetterRequest (
287+ invalidLetterId , receiverId , matchingId , parentLetterId , title , content , category , paperType , fontType
288+ );
299289
300290 doThrow (new LetterNotBelongException ())
301291 .when (letterService )
302- .temporarySaveLetter (eq ( unauthorizedLetterId ), any (TemporarySaveLetterRequest .class ));
292+ .temporarySaveLetter (any (TemporarySaveLetterRequest .class ));
303293
304294 // when & then
305- mockMvc .perform (post ("/api/letters/{letterId}/ temporary-save" , unauthorizedLetterId )
295+ mockMvc .perform (post ("/api/letters/temporary-save" )
306296 .contentType (MediaType .APPLICATION_JSON )
307297 .content (objectMapper .writeValueAsString (request )))
308298 .andExpect (status ().isForbidden ())
@@ -311,7 +301,6 @@ void temporarySaveLetter_fail_notBelongLetter() throws Exception {
311301 .andDo (print ());
312302
313303 verify (letterService ).temporarySaveLetter (
314- eq (unauthorizedLetterId ),
315304 any (TemporarySaveLetterRequest .class )
316305 );
317306 }
0 commit comments