@@ -3,6 +3,7 @@ import { Pool } from 'pg';
33import pg from 'pg' ;
44import { PostRepository } from '../post.repository' ;
55import logger from '@/configs/logger.config' ;
6+ import { getCurrentKSTDateString , getKSTDateStringWithOffset } from '@/utils/date.util' ;
67
78
89dotenv . config ( ) ;
@@ -407,7 +408,9 @@ describe('PostRepository 통합 테스트', () => {
407408 */
408409 describe ( 'findPostByPostId' , ( ) => {
409410 it ( '게시물 ID로 통계 데이터를 조회할 수 있어야 한다' , async ( ) => {
410- const result = await repo . findPostByPostId ( TEST_DATA . POST_ID ) ;
411+ const sevenDayAgoKST = getKSTDateStringWithOffset ( - 24 * 60 * 7 ) ;
412+ const endKST = getCurrentKSTDateString ( ) ;
413+ const result = await repo . findPostByPostId ( TEST_DATA . POST_ID , sevenDayAgoKST , endKST ) ;
411414
412415 expect ( result ) . toBeDefined ( ) ;
413416 expect ( Array . isArray ( result ) ) . toBe ( true ) ;
@@ -437,7 +440,9 @@ describe('PostRepository 통합 테스트', () => {
437440 } ) ;
438441
439442 it ( '날짜 오름차순으로 정렬된 결과를 반환해야 한다' , async ( ) => {
440- const result = await repo . findPostByPostId ( TEST_DATA . POST_ID ) ;
443+ const sevenDayAgoKST = getKSTDateStringWithOffset ( - 24 * 60 * 7 ) ;
444+ const endKST = getCurrentKSTDateString ( ) ;
445+ const result = await repo . findPostByPostId ( TEST_DATA . POST_ID , sevenDayAgoKST , endKST ) ;
441446
442447 // 2개 이상의 결과가 있는 경우에만 정렬 검증
443448 if ( result . length >= 2 ) {
@@ -459,16 +464,20 @@ describe('PostRepository 통합 테스트', () => {
459464 } ) ;
460465
461466 it ( '존재하지 않는 게시물 ID에 대해 빈 배열을 반환해야 한다' , async ( ) => {
467+ const sevenDayAgoKST = getKSTDateStringWithOffset ( - 24 * 60 * 7 ) ;
468+ const endKST = getCurrentKSTDateString ( ) ;
462469 const nonExistentPostId = 9999999 ;
463- const result = await repo . findPostByPostId ( nonExistentPostId ) ;
470+ const result = await repo . findPostByPostId ( nonExistentPostId , sevenDayAgoKST , endKST ) ;
464471
465472 expect ( result ) . toBeDefined ( ) ;
466473 expect ( Array . isArray ( result ) ) . toBe ( true ) ;
467474 expect ( result . length ) . toBe ( 0 ) ;
468475 } ) ;
469476
470477 it ( '날짜 형식이 올바르게 변환되어야 한다' , async ( ) => {
471- const result = await repo . findPostByPostId ( TEST_DATA . POST_ID ) ;
478+ const sevenDayAgoKST = getKSTDateStringWithOffset ( - 24 * 60 * 7 ) ;
479+ const endKST = getCurrentKSTDateString ( ) ;
480+ const result = await repo . findPostByPostId ( TEST_DATA . POST_ID , sevenDayAgoKST , endKST ) ;
472481
473482 if ( result . length <= 0 ) {
474483 logger . info ( '존재하지 않는 게시물 ID에 대해 빈 배열을 테스트를 위한 충분한 데이터가 없습니다.' ) ;
@@ -490,7 +499,9 @@ describe('PostRepository 통합 테스트', () => {
490499 } ) ;
491500
492501 it ( '일일 조회수와 좋아요 수가 숫자 타입이어야 한다' , async ( ) => {
493- const result = await repo . findPostByPostId ( TEST_DATA . POST_ID ) ;
502+ const sevenDayAgoKST = getKSTDateStringWithOffset ( - 24 * 60 * 7 ) ;
503+ const endKST = getCurrentKSTDateString ( ) ;
504+ const result = await repo . findPostByPostId ( TEST_DATA . POST_ID , sevenDayAgoKST , endKST ) ;
494505
495506 if ( result . length <= 0 ) {
496507 logger . info ( '일일 조회수와 좋아요 수가 숫자 타입인지 테스트를 위한 충분한 데이터가 없습니다.' ) ;
0 commit comments