-
Notifications
You must be signed in to change notification settings - Fork 0
[25.06.07 / TASK-206] Feature - 사용자 모델 (유저네임, 썸네일) 추가, 대응 개발 #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { Request, Response } from 'express'; | ||
| import { authMiddleware } from '@/middlewares/auth.middleware'; | ||
| import pool from '@/configs/db.config'; | ||
| import { mockUser } from '@/utils/fixtures'; | ||
|
|
||
| // pool.query 모킹 | ||
| jest.mock('@/configs/db.config', () => ({ | ||
|
|
@@ -184,14 +185,6 @@ describe('인증 미들웨어', () => { | |
| refreshToken: 'refresh-token' | ||
| }; | ||
|
|
||
| // 사용자 정보 mock | ||
| const mockUser = { | ||
| id: 1, | ||
| username: 'testuser', | ||
| email: '[email protected]', | ||
| velog_uuid: 'c7507240-093b-11ea-9aae-a58a86bb0520' | ||
| }; | ||
|
|
||
| // DB 쿼리 결과 모킹 | ||
| (pool.query as jest.Mock).mockResolvedValueOnce({ | ||
| rows: [mockUser] | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import { Pool } from 'pg'; | ||
| import { DBError } from '@/exception'; | ||
| import { UserService } from '@/services/user.service'; | ||
| import { UserRepository } from '@/repositories/user.repository'; | ||
| import { DBError } from '@/exception'; | ||
| import { QRLoginToken } from '@/types/models/QRLoginToken.type'; | ||
| import { User } from '@/types'; | ||
| import { Pool } from 'pg'; | ||
| import { mockUser } from '@/utils/fixtures'; | ||
|
|
||
| // AESEncryption 클래스 모킹 | ||
| jest.mock('@/modules/token_encryption/aes_encryption', () => { | ||
|
|
@@ -68,18 +68,6 @@ describe('UserService의 QR 로그인 기능', () => { | |
| }); | ||
|
|
||
| describe('useToken', () => { | ||
| const mockUser: User = { | ||
| id: 1, | ||
| velog_uuid: 'uuid-1', | ||
| access_token: 'encrypted-access-token', | ||
| refresh_token: 'encrypted-refresh-token', | ||
| email: '[email protected]', | ||
| group_id: 1, | ||
| is_active: true, | ||
| created_at: new Date(), | ||
| updated_at: new Date() | ||
| }; | ||
|
|
||
| const mockQRToken: QRLoginToken = { | ||
| id: 1, | ||
| token: 'token', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { QueryResult } from 'pg'; | ||
| import { User } from '@/types'; | ||
|
|
||
| /** | ||
| * PostgreSQL 쿼리를 모킹하기 위한 mock Pool 객체 | ||
| * | ||
| * @description Jest 테스트에서 pg.Pool의 query 메서드를 모킹하는 데 사용됩니다. | ||
| * @example | ||
| * ```typescript | ||
| * // 성공적인 쿼리 결과 모킹 | ||
| * mockPool.query.mockResolvedValue(createMockQueryResult([{ id: 1, name: 'test' }])); | ||
| * | ||
| * // 에러 발생 모킹 | ||
| * mockPool.query.mockRejectedValue(new Error('Database error')); | ||
| * ``` | ||
| */ | ||
| export const mockPool: { | ||
| query: jest.Mock<Promise<QueryResult<Record<string, unknown>>>, unknown[]>; | ||
| } = { | ||
| query: jest.fn(), | ||
| }; | ||
|
|
||
| /** | ||
| * 테스트용 모의 사용자 데이터, User 객체 | ||
| * | ||
| * @description 인증 관련 (미들웨어, QR 로그인 등) 유닛 테스트에서 공통적으로 사용되는 mock User 객체입니다. | ||
| */ | ||
| export const mockUser: User = { | ||
| id: 1, | ||
| velog_uuid: 'uuid-1', | ||
| access_token: 'encrypted-access-token', | ||
| refresh_token: 'encrypted-refresh-token', | ||
| email: '[email protected]', | ||
| username: 'nuung', | ||
| thumbnail: 'https://nuung.com/test.jpg', | ||
| group_id: 1, | ||
| is_active: true, | ||
| created_at: new Date('2024-01-01T00:00:00Z'), | ||
| updated_at: new Date('2024-01-01T00:00:00Z'), | ||
| }; | ||
|
|
||
| /** | ||
| * pg의 QueryResult 타입을 만족하는 mock 객체를 생성하기 위한 헬퍼 함수 | ||
| * | ||
| * @template T - 쿼리 결과 row의 타입 (Record<string, unknown>를 확장해야 함) | ||
| * @param rows - 모킹할 데이터베이스 행들의 배열 | ||
| * @returns PostgreSQL QueryResult 형태의 mock 객체 | ||
| * | ||
| * @description | ||
| * PostgreSQL의 실제 쿼리 결과와 동일한 구조를 가진 mock 객체를 생성합니다. | ||
| * Jest 테스트에서 데이터베이스 쿼리 결과를 모킹할 때 사용됩니다. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // 사용자 데이터 모킹 | ||
| * const mockUsers = [ | ||
| * { id: 1, name: 'John', email: '[email protected]' }, | ||
| * { id: 2, name: 'Jane', email: '[email protected]' } | ||
| * ]; | ||
| * const result = createMockQueryResult(mockUsers); | ||
| * | ||
| * // 빈 결과 모킹 | ||
| * const emptyResult = createMockQueryResult([]); | ||
| * | ||
| * // Jest mock에서 사용 | ||
| * mockPool.query.mockResolvedValue(createMockQueryResult(mockUsers)); | ||
| * ``` | ||
| */ | ||
| export function createMockQueryResult<T extends Record<string, unknown>>(rows: T[]): QueryResult<T> { | ||
| return { | ||
| rows, | ||
| rowCount: rows.length, | ||
| command: '', | ||
| oid: 0, | ||
| fields: [], | ||
| } satisfies QueryResult<T>; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.