Skip to content

Commit 07eaadc

Browse files
committed
refactor: 정렬 테스트 케이스들을 each로 묶어 수행하도록 수정
1 parent 75c184b commit 07eaadc

File tree

1 file changed

+26
-41
lines changed

1 file changed

+26
-41
lines changed

src/repositories/__test__/leaderboard.repo.test.ts

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Pool, QueryResult } from 'pg';
22
import { DBError } from '@/exception';
33
import { LeaderboardRepository } from '@/repositories/leaderboard.repository';
4+
import { UserLeaderboardSortType, PostLeaderboardSortType } from '@/types';
45

56
jest.mock('pg');
67

@@ -60,31 +61,19 @@ describe('LeaderboardRepository', () => {
6061
expect(result).toEqual(mockResult);
6162
});
6263

63-
it('sort가 viewCount인 경우 view_diff 필드를 기준으로 내림차순 정렬해야 한다', async () => {
64-
await repo.getUserLeaderboard('viewCount', 30, 10);
65-
66-
expect(mockPool.query).toHaveBeenCalledWith(
67-
expect.stringContaining('ORDER BY view_diff DESC'),
68-
expect.anything(),
69-
);
70-
});
71-
72-
it('sort가 likeCount인 경우 like_diff 필드를 기준으로 내림차순 정렬해야 한다', async () => {
73-
await repo.getUserLeaderboard('likeCount', 30, 10);
74-
75-
expect(mockPool.query).toHaveBeenCalledWith(
76-
expect.stringContaining('ORDER BY like_diff DESC'),
77-
expect.anything(),
78-
);
79-
});
80-
81-
it('sort가 postCount인 경우 post_diff 필드를 기준으로 내림차순 정렬해야 한다', async () => {
82-
await repo.getUserLeaderboard('postCount', 30, 10);
83-
84-
expect(mockPool.query).toHaveBeenCalledWith(
85-
expect.stringContaining('ORDER BY post_diff DESC'),
86-
expect.anything(),
87-
);
64+
describe.each([
65+
{ sort: 'viewCount', field: 'view_diff' },
66+
{ sort: 'likeCount', field: 'like_diff' },
67+
{ sort: 'postCount', field: 'post_diff' },
68+
])('sort 파라미터에 따라 내림차순 정렬되어야 한다', ({ sort, field }) => {
69+
it(`sort가 ${sort}인 경우 ${field} 필드를 기준으로 정렬해야 한다`, async () => {
70+
await repo.getUserLeaderboard(sort as UserLeaderboardSortType, 30, 10);
71+
72+
expect(mockPool.query).toHaveBeenCalledWith(
73+
expect.stringContaining(`ORDER BY ${field} DESC`),
74+
expect.anything(),
75+
);
76+
});
8877
});
8978

9079
it('limit 파라미터가 쿼리에 올바르게 적용되어야 한다', async () => {
@@ -148,22 +137,18 @@ describe('LeaderboardRepository', () => {
148137
expect(mockPool.query).toHaveBeenCalledWith(expect.stringContaining('FROM posts_post p'), expect.anything());
149138
});
150139

151-
it('sort가 viewCount인 경우 view_diff 필드를 기준으로 내림차순 정렬해야 한다', async () => {
152-
await repo.getPostLeaderboard('viewCount', 30, 10);
153-
154-
expect(mockPool.query).toHaveBeenCalledWith(
155-
expect.stringContaining('ORDER BY view_diff DESC'),
156-
expect.anything(),
157-
);
158-
});
159-
160-
it('sort가 likeCount인 경우 like_diff 필드를 기준으로 내림차순 정렬해야 한다', async () => {
161-
await repo.getPostLeaderboard('likeCount', 30, 10);
162-
163-
expect(mockPool.query).toHaveBeenCalledWith(
164-
expect.stringContaining('ORDER BY like_diff DESC'),
165-
expect.anything(),
166-
);
140+
describe.each([
141+
{ sort: 'viewCount', field: 'view_diff' },
142+
{ sort: 'likeCount', field: 'like_diff' },
143+
])('sort 파라미터에 따라 내림차순 정렬되어야 한다', ({ sort, field }) => {
144+
it(`sort가 ${sort}인 경우 ${field} 필드를 기준으로 정렬해야 한다`, async () => {
145+
await repo.getPostLeaderboard(sort as PostLeaderboardSortType, 30, 10);
146+
147+
expect(mockPool.query).toHaveBeenCalledWith(
148+
expect.stringContaining(`ORDER BY ${field} DESC`),
149+
expect.anything(),
150+
);
151+
});
167152
});
168153

169154
it('limit 파라미터가 쿼리에 올바르게 적용되어야 한다', async () => {

0 commit comments

Comments
 (0)