@@ -56,6 +56,28 @@ describe('PostRepository', () => {
5656 expect ( result . posts ) . toEqual ( mockPosts ) ;
5757 expect ( result . posts [ 0 ] . id ) . toBeGreaterThan ( result . posts [ 1 ] . id ) ;
5858 } ) ;
59+
60+ it ( '쿼리에 is_active = TRUE 조건이 포함되어야 한다' , async ( ) => {
61+ const mockPosts = [
62+ { id : 1 , post_released_at : '2025-03-01T00:00:00Z' , daily_view_count : 10 , daily_like_count : 5 } ,
63+ ] ;
64+
65+ mockPool . query . mockResolvedValue ( {
66+ rows : mockPosts ,
67+ rowCount : mockPosts . length ,
68+ command : '' ,
69+ oid : 0 ,
70+ fields : [ ] ,
71+ } as QueryResult ) ;
72+
73+ await repo . findPostsByUserId ( 1 ) ;
74+
75+ // 쿼리 호출 확인
76+ expect ( mockPool . query ) . toHaveBeenCalledWith (
77+ expect . stringContaining ( "p.is_active = TRUE" ) ,
78+ expect . anything ( )
79+ ) ;
80+ } ) ;
5981 } ) ;
6082
6183 describe ( 'findPostsByUserIdWithGrowthMetrics' , ( ) => {
@@ -157,6 +179,28 @@ describe('PostRepository', () => {
157179 mockPool . query . mockRejectedValue ( new Error ( 'DB connection failed' ) ) ;
158180 await expect ( repo . findPostsByUserIdWithGrowthMetrics ( 1 ) ) . rejects . toThrow ( DBError ) ;
159181 } ) ;
182+
183+ it ( '쿼리에 is_active = TRUE 조건이 포함되어야 한다' , async ( ) => {
184+ const mockPosts = [
185+ { id : 1 , view_growth : 20 , like_growth : 5 } ,
186+ ] ;
187+
188+ mockPool . query . mockResolvedValue ( {
189+ rows : mockPosts ,
190+ rowCount : mockPosts . length ,
191+ command : '' ,
192+ oid : 0 ,
193+ fields : [ ] ,
194+ } as QueryResult ) ;
195+
196+ await repo . findPostsByUserIdWithGrowthMetrics ( 1 ) ;
197+
198+ // 쿼리 호출 확인
199+ expect ( mockPool . query ) . toHaveBeenCalledWith (
200+ expect . stringContaining ( "p.is_active = TRUE" ) ,
201+ expect . anything ( )
202+ ) ;
203+ } ) ;
160204 } ) ;
161205
162206 describe ( 'getTotalPostCounts' , ( ) => {
@@ -172,6 +216,24 @@ describe('PostRepository', () => {
172216 const count = await repo . getTotalPostCounts ( 1 ) ;
173217 expect ( count ) . toBe ( 10 ) ;
174218 } ) ;
219+
220+ it ( 'is_active = TRUE인 게시물만 카운트해야 한다' , async ( ) => {
221+ mockPool . query . mockResolvedValue ( {
222+ rows : [ { count : '5' } ] ,
223+ rowCount : 1 ,
224+ command : '' ,
225+ oid : 0 ,
226+ fields : [ ] ,
227+ } as QueryResult ) ;
228+
229+ await repo . getTotalPostCounts ( 1 ) ;
230+
231+ // 쿼리 호출 확인
232+ expect ( mockPool . query ) . toHaveBeenCalledWith (
233+ expect . stringContaining ( "is_active = TRUE" ) ,
234+ expect . anything ( )
235+ ) ;
236+ } ) ;
175237 } ) ;
176238
177239 describe ( '에러 발생 시 처리' , ( ) => {
@@ -204,6 +266,24 @@ describe('PostRepository', () => {
204266 const result = await repo . getYesterdayAndTodayViewLikeStats ( 1 ) ;
205267 expect ( result ) . toEqual ( mockStats ) ;
206268 } ) ;
269+
270+ it ( 'is_active = TRUE인 게시물의 통계만 반환해야 한다' , async ( ) => {
271+ mockPool . query . mockResolvedValue ( {
272+ rows : [ { daily_view_count : 20 , daily_like_count : 15 } ] ,
273+ rowCount : 1 ,
274+ command : '' ,
275+ oid : 0 ,
276+ fields : [ ] ,
277+ } as QueryResult ) ;
278+
279+ await repo . getYesterdayAndTodayViewLikeStats ( 1 ) ;
280+
281+ // 쿼리 호출 확인
282+ expect ( mockPool . query ) . toHaveBeenCalledWith (
283+ expect . stringContaining ( "p.is_active = TRUE" ) ,
284+ expect . anything ( )
285+ ) ;
286+ } ) ;
207287 } ) ;
208288
209289 describe ( 'findPostByPostId' , ( ) => {
0 commit comments