@@ -91,14 +91,28 @@ void createPost_success_withCategoriesAndImages() {
9191 // when
9292 PostResponse response = postService .createPost (request , user .getId ());
9393
94- // then
94+ // then — DTO 검증
9595 assertThat (response .title ()).isEqualTo ("제목" );
9696 assertThat (response .content ()).isEqualTo ("내용" );
9797 assertThat (response .author ().nickname ()).isEqualTo ("작성자" );
9898 assertThat (response .categories ()).hasSize (1 );
9999 assertThat (response .categories ().getFirst ().name ()).isEqualTo ("공지" );
100100 assertThat (response .images ()).hasSize (2 );
101101 assertThat (response .images ().getFirst ().id ()).isEqualTo (img1 .getId ());
102+
103+ // then — DB 매핑 검증
104+ List <AttachmentMapping > mappings = attachmentMappingRepository
105+ .findAllByEntityTypeAndEntityId (EntityType .POST , response .postId ());
106+
107+ assertThat (mappings ).hasSize (2 ); // 이미지 2개 → 매핑 2개
108+ assertThat (mappings )
109+ .allSatisfy (mapping -> {
110+ assertThat (mapping .getEntityType ()).isEqualTo (EntityType .POST );
111+ assertThat (mapping .getEntityId ()).isEqualTo (response .postId ());
112+ assertThat (mapping .getFileAttachment ()).isNotNull ();
113+ assertThat (mapping .getFileAttachment ().getId ())
114+ .isIn (img1 .getId (), img2 .getId ());
115+ });
102116 }
103117
104118 @ Test
@@ -199,11 +213,25 @@ void getPost_success() {
199213 PostCategory category = new PostCategory ("공지" , CategoryType .SUBJECT );
200214 postCategoryRepository .save (category );
201215
216+ // 게시글 생성
202217 Post post = new Post (user , "조회용 제목" , "조회용 내용" , null );
203218 post .updateCategories (List .of (category ));
204219 postRepository .save (post );
205220
206- // when
221+ // 첨부 이미지 추가
222+ MockMultipartFile file1 = new MockMultipartFile ("file" , "img1.png" , "image/png" , "dummy" .getBytes ());
223+ FileAttachment attachment1 = new FileAttachment ("stored_img1.png" , file1 , user , "https://cdn.example.com/img1.png" );
224+ fileAttachmentRepository .save (attachment1 );
225+
226+ MockMultipartFile file2 = new MockMultipartFile ("file" , "img2.png" , "image/png" , "dummy" .getBytes ());
227+ FileAttachment attachment2 = new FileAttachment ("stored_img2.png" , file2 , user , "https://cdn.example.com/img2.png" );
228+ fileAttachmentRepository .save (attachment2 );
229+
230+ // 매핑 저장 (EntityType.POST)
231+ attachmentMappingRepository .save (new AttachmentMapping (attachment1 , EntityType .POST , post .getId ()));
232+ attachmentMappingRepository .save (new AttachmentMapping (attachment2 , EntityType .POST , post .getId ()));
233+
234+ // when: 비로그인 상태에서 조회
207235 PostDetailResponse response = postService .getPost (post .getId (), null );
208236
209237 // then
@@ -212,9 +240,19 @@ void getPost_success() {
212240 assertThat (response .content ()).isEqualTo ("조회용 내용" );
213241 assertThat (response .author ().nickname ()).isEqualTo ("독자" );
214242 assertThat (response .categories ()).extracting ("name" ).containsExactly ("공지" );
243+
244+ // 첨부 이미지 검증
245+ assertThat (response .images ()).hasSize (2 );
246+ assertThat (response .images ())
247+ .extracting ("url" )
248+ .containsExactlyInAnyOrder ("https://cdn.example.com/img1.png" , "https://cdn.example.com/img2.png" );
249+
250+ // 기본 상호작용 상태 검증
215251 assertThat (response .likeCount ()).isZero ();
216252 assertThat (response .bookmarkCount ()).isZero ();
217253 assertThat (response .commentCount ()).isZero ();
254+ assertThat (response .likedByMe ()).isFalse ();
255+ assertThat (response .bookmarkedByMe ()).isFalse ();
218256 }
219257
220258 @ Test
0 commit comments