Skip to content

Commit b25705c

Browse files
committed
feature: fixture jsdocs 추가
1 parent a56ce92 commit b25705c

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

src/repositories/__test__/fixture.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,51 @@
11
import { QueryResult } from "pg";
22

3+
/**
4+
* PostgreSQL 쿼리를 모킹하기 위한 mock Pool 객체
5+
*
6+
* @description Jest 테스트에서 pg.Pool의 query 메서드를 모킹하는 데 사용됩니다.
7+
* @example
8+
* ```typescript
9+
* // 성공적인 쿼리 결과 모킹
10+
* mockPool.query.mockResolvedValue(createMockQueryResult([{ id: 1, name: 'test' }]));
11+
*
12+
* // 에러 발생 모킹
13+
* mockPool.query.mockRejectedValue(new Error('Database error'));
14+
* ```
15+
*/
316
export const mockPool: {
417
query: jest.Mock<Promise<QueryResult<Record<string, unknown>>>, unknown[]>;
518
} = {
619
query: jest.fn(),
720
};
821

922
/**
10-
* pg의 QueryResult 타입을 만족하는 mock 객체를 생성하기 위한 헬퍼 함수
11-
* @param rows
12-
* @returns
13-
*/
23+
* pg의 QueryResult 타입을 만족하는 mock 객체를 생성하기 위한 헬퍼 함수
24+
*
25+
* @template T - 쿼리 결과 row의 타입 (Record<string, unknown>를 확장해야 함)
26+
* @param rows - 모킹할 데이터베이스 행들의 배열
27+
* @returns PostgreSQL QueryResult 형태의 mock 객체
28+
*
29+
* @description
30+
* PostgreSQL의 실제 쿼리 결과와 동일한 구조를 가진 mock 객체를 생성합니다.
31+
* Jest 테스트에서 데이터베이스 쿼리 결과를 모킹할 때 사용됩니다.
32+
*
33+
* @example
34+
* ```typescript
35+
* // 사용자 데이터 모킹
36+
* const mockUsers = [
37+
* { id: 1, name: 'John', email: 'john@example.com' },
38+
* { id: 2, name: 'Jane', email: 'jane@example.com' }
39+
* ];
40+
* const result = createMockQueryResult(mockUsers);
41+
*
42+
* // 빈 결과 모킹
43+
* const emptyResult = createMockQueryResult([]);
44+
*
45+
* // Jest mock에서 사용
46+
* mockPool.query.mockResolvedValue(createMockQueryResult(mockUsers));
47+
* ```
48+
*/
1449
export function createMockQueryResult<T extends Record<string, unknown>>(rows: T[]): QueryResult<T> {
1550
return {
1651
rows,

0 commit comments

Comments
 (0)