Skip to content

Commit f139b91

Browse files
authored
[25.06.07 / TASK-206] Feature - 사용자 모델 (유저네임, 썸네일) 추가, 대응 개발 (#34)
* feature: user model 업데이트 됨에 따라 type 들 업데이트, 특히 me api 리뉴얼 * feature: fixture 를 utils 로 독립, import 수정 * modify: 오탈자 수정
1 parent 4fff733 commit f139b91

File tree

11 files changed

+99
-94
lines changed

11 files changed

+99
-94
lines changed

src/controllers/user.controller.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ export class UserController {
2424

2525
if (isProd) {
2626
baseOptions.sameSite = 'lax';
27-
baseOptions.domain = "velog-dashboard.kro.kr";
27+
baseOptions.domain = 'velog-dashboard.kro.kr';
2828
baseOptions.maxAge = THREE_WEEKS_IN_MS; // 3주
29-
3029
} else {
3130
baseOptions.domain = 'localhost';
3231
}
@@ -108,14 +107,16 @@ export class UserController {
108107
};
109108

110109
fetchCurrentUser: RequestHandler = async (req: Request, res: Response<LoginResponseDto>) => {
111-
// 외부 API (velog) 호출로 username 을 가져와야 함, 게시글 바로가기 때문에 (username)
112-
const { accessToken, refreshToken } = req.tokens;
113-
const velogUser = await fetchVelogApi(accessToken, refreshToken);
110+
const currentUser = req.user;
111+
112+
// 인가 middle 에서 만든 객체 그대로 재활용
113+
const username = currentUser.username || '';
114+
const profile = { thumbnail: currentUser.thumbnail || '' };
114115

115116
const response = new LoginResponseDto(
116117
true,
117118
'유저 정보 조회에 성공하였습니다.',
118-
{ id: req.user.id, username: velogUser.username, profile: velogUser.profile },
119+
{ id: currentUser.id, username: username, profile: profile },
119120
null,
120121
);
121122

src/middlewares/__test__/auth.middleware.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Request, Response } from 'express';
22
import { authMiddleware } from '@/middlewares/auth.middleware';
33
import pool from '@/configs/db.config';
4+
import { mockUser } from '@/utils/fixtures';
45

56
// pool.query 모킹
67
jest.mock('@/configs/db.config', () => ({
@@ -184,14 +185,6 @@ describe('인증 미들웨어', () => {
184185
refreshToken: 'refresh-token'
185186
};
186187

187-
// 사용자 정보 mock
188-
const mockUser = {
189-
id: 1,
190-
username: 'testuser',
191-
email: 'test@example.com',
192-
velog_uuid: 'c7507240-093b-11ea-9aae-a58a86bb0520'
193-
};
194-
195188
// DB 쿼리 결과 모킹
196189
(pool.query as jest.Mock).mockResolvedValueOnce({
197190
rows: [mockUser]

src/repositories/__test__/fixtures.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Pool } from 'pg';
22
import { DBError } from '@/exception';
3-
import { LeaderboardRepository } from '@/repositories/leaderboard.repository';
43
import { UserLeaderboardSortType, PostLeaderboardSortType } from '@/types';
5-
import { mockPool, createMockQueryResult } from './fixtures';
4+
import { LeaderboardRepository } from '@/repositories/leaderboard.repository';
5+
import { mockPool, createMockQueryResult } from '@/utils/fixtures';
66

77
jest.mock('pg');
88

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Pool } from 'pg';
22
import { PostRepository } from '@/repositories/post.repository';
33
import { DBError } from '@/exception';
4-
import { mockPool, createMockQueryResult } from './fixtures';
4+
import { mockPool, createMockQueryResult } from '@/utils/fixtures';
55

66
jest.mock('pg');
77

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { UserRepository } from '@/repositories/user.repository';
22
import { DBError } from '@/exception';
33
import { Pool } from 'pg';
44
import { QRLoginToken } from "@/types/models/QRLoginToken.type";
5-
import { mockPool } from './fixtures';
5+
import { mockPool } from '@/utils/fixtures';
66

77
jest.mock('pg');
88

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Pool } from 'pg';
2-
import { TotalStatsRepository } from '@/repositories/totalStats.repository';
32
import { DBError } from '@/exception';
4-
import { getKSTDateStringWithOffset } from '@/utils/date.util';
5-
import { mockPool, createMockQueryResult } from './fixtures';
63
import { TotalStatsType } from '@/types';
4+
import { TotalStatsRepository } from '@/repositories/totalStats.repository';
5+
import { getKSTDateStringWithOffset } from '@/utils/date.util';
6+
import { mockPool, createMockQueryResult } from '@/utils/fixtures';
77

88
// Mock dependencies
99
jest.mock('@/configs/logger.config', () => ({

src/routes/user.router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ router.post('/logout', authMiddleware.verify, userController.logout);
103103
* get:
104104
* tags:
105105
* - User
106-
* summary: 사용자 정보 조회
106+
* summary: 사용자 정보 조회, auth 미들웨어 객체 그대로 사용
107107
* responses:
108108
* '200':
109109
* description: 성공

src/services/__test__/qr.service.test.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { Pool } from 'pg';
2+
import { DBError } from '@/exception';
13
import { UserService } from '@/services/user.service';
24
import { UserRepository } from '@/repositories/user.repository';
3-
import { DBError } from '@/exception';
45
import { QRLoginToken } from '@/types/models/QRLoginToken.type';
5-
import { User } from '@/types';
6-
import { Pool } from 'pg';
6+
import { mockUser } from '@/utils/fixtures';
77

88
// AESEncryption 클래스 모킹
99
jest.mock('@/modules/token_encryption/aes_encryption', () => {
@@ -68,18 +68,6 @@ describe('UserService의 QR 로그인 기능', () => {
6868
});
6969

7070
describe('useToken', () => {
71-
const mockUser: User = {
72-
id: 1,
73-
velog_uuid: 'uuid-1',
74-
access_token: 'encrypted-access-token',
75-
refresh_token: 'encrypted-refresh-token',
76-
email: 'test@example.com',
77-
group_id: 1,
78-
is_active: true,
79-
created_at: new Date(),
80-
updated_at: new Date()
81-
};
82-
8371
const mockQRToken: QRLoginToken = {
8472
id: 1,
8573
token: 'token',

src/types/models/User.type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export interface User {
88
is_active: boolean;
99
created_at: Date;
1010
updated_at: Date;
11+
// 250607 추가
12+
username: string | null;
13+
thumbnail: string | null;
1114
}
1215

1316

0 commit comments

Comments
 (0)