-
Notifications
You must be signed in to change notification settings - Fork 0
[25.04.21 / TASK-148] Feature - qrcode app & QRCode API #26
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 23 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
6d3b0ec
feat: qrcode app ์ปจํธ๋กค๋ฌ, ์๋น์ค, ๋ ํฌ์งํ ๋ฆฌ, ํ์
์ถ๊ฐ, ๊ด๋ จ API ๊ตฌํ
Jihyun3478 3b6adaa
hotfix: ์ฝ๋๋๋น ๋ฆฌ๋ทฐ ๋ฐ์
Jihyun3478 b70a582
modify: ์ฌ์ฉํ์ง ์๋ ํด๋์ค ์ญ์
Jihyun3478 56c2283
refactor: ๋ถํ์ํ ์์กด์ฑ ์ญ์
Jihyun3478 ac39619
refactor: ๊ณต๋ฐฑ ์ ๊ฑฐ
Jihyun3478 d118b16
refactor: ํ์ฉ๋ ๋ฎ์ ํ๋ ์์ ์ ๋ฆฌ
Jihyun3478 f6f3936
modify: token ๊ณ ์ ๊ธธ์ด ๊ฐ ๋ช
์ & exception ์ฌ์ฌ์ฉ
Jihyun3478 065879c
refactor: repository ํ
์คํธ ์ฝ๋ ๋ฉ์๋ ๋ถ๋ฆฌ
Jihyun3478 3faf173
hotfix: uuid ์ญ์
Jihyun3478 a007870
hotfix: ๋น์ฆ๋์ค ๋ก์ง ํ๋ฆ์ ๋ง๊ฒ ์์
Jihyun3478 a95635e
refactor: ์ฝ๋๋๋น ๋ฆฌ๋ทฐ ๋ฐ์
Jihyun3478 245a721
hotfix: token 36์๊ฐ ์๋ 10์๋ก ์์
Jihyun3478 4fd26ac
hotfix: ์ฟผ๋ฆฌ ์์ฑ ์ qr_login_tokens๊ฐ ์๋ users_qrlogintoken์ผ๋ก ์์
Jihyun3478 c7e9019
test: ๋ ํฌ์งํ ๋ฆฌ ํตํฉํ
์คํธ์ฝ๋ ๊ตฌํ
Jihyun3478 51a0162
Merge branch 'main' into feature/qrcode-app
Jihyun3478 5932dac
hotfix: ์ค๋ณต ํ ํฐ ํ
์คํธ ํ DB ์ฐ๊ฒฐ ์ข
๋ฃ
Jihyun3478 85b502c
hotfix: ์ค๋ณต ํ ํฐ ์ฝ์
ํ
์คํธ ์ญ์
Jihyun3478 37b9633
modify: QRLoginToken ๋ผ์ฐํฐ, ์๋น์ค, ๋ ํฌ User์ชฝ์ผ๋ก ํฉ์น๊ธฐ
Jihyun3478 3440fa2
modify: ์ฝ๋๋๋น ๋ฆฌ๋ทฐ 1์ฐจ ๋ฐ์
Jihyun3478 d2d127a
hotfix: process.env ๋์ ์์์ ๋์๋ฅผ ์ฌ์ฉํ๋๋ก ์์
Jihyun3478 fe68599
refactor: lint ์ ์ฉ
Jihyun3478 f8801e0
refactor: ๋ค์ฌ์ฐ๊ธฐ ์ ๋ฆฌ
Jihyun3478 5613dbb
hotfix: ์ฌ๋๋ mockingํ๋๋ก ์์
Jihyun3478 31b1a43
hotfix: ํน์ ํ
์คํธ ๋ฐ์ดํฐ ํ
์คํธ๊ฐ ์๋ฃ๋ ํ ์ง์ฐ๋๋ก ์์
Jihyun3478 6d6f918
docs: Swagger ์ฃผ์ ์์ ๋ฐ ์ถ๊ฐ
Jihyun3478 3ce8994
hotfix: ํ ํฐ ์์ฑ ๋ก์ง ์์
Jihyun3478 5c8f0a9
hotfix: ์ค์ ํด๋ผ์ด์ธํธ์ IP์ ์ ๊ทผํ๋๋ก ์์ & logger ๊ตฌ์ฒดํ
Jihyun3478 0769497
refactor: ์ฝ๋๋๋น ๋ฆฌ๋ทฐ ๋ฐ์
Jihyun3478 624be89
docs: swagger ๋ฌธ์ ์์
Jihyun3478 c20e48e
modify: service์ getByToken์ด ์๋ repo์ findQRLoginToken์ ์ฌ์ฉํ๋๋ก ์์
Jihyun3478 b08d834
refactor: findByVelogUUID & getDecryptedTokens ๋ฉ์๋ ๋ณํฉ
Jihyun3478 21764ee
refactor: ๋ ํฌ ๊ณ์ธต๊ณผ์ ์ค๋ณต ํ
์คํธ์ฝ๋ ์ ๊ฑฐ
Jihyun3478 c2dd34a
refactor: ์ฌ์ฉํ์ง ์๋ import & ์ฝ๋ ์ ๊ฑฐ
Jihyun3478 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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import dotenv from 'dotenv'; | ||
import { Pool } from 'pg'; | ||
import pg from 'pg'; | ||
import { UserRepository } from '@/repositories/user.repository'; | ||
import { generateRandomToken } from '@/utils/generateRandomToken.util'; | ||
import logger from '@/configs/logger.config'; | ||
|
||
dotenv.config(); | ||
jest.setTimeout(30000); | ||
Jihyun3478 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe('QRLoginTokenRepository ํตํฉ ํ ์คํธ', () => { | ||
let testPool: Pool; | ||
let repo: UserRepository; | ||
|
||
const TEST_DATA = { | ||
USER_ID: 1, | ||
}; | ||
Nuung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
beforeAll(async () => { | ||
const testPoolConfig: pg.PoolConfig = { | ||
database: process.env.DATABASE_NAME, | ||
user: process.env.POSTGRES_USER, | ||
host: process.env.POSTGRES_HOST, | ||
password: process.env.POSTGRES_PASSWORD, | ||
port: Number(process.env.POSTGRES_PORT), | ||
max: 1, | ||
idleTimeoutMillis: 30000, | ||
connectionTimeoutMillis: 5000, | ||
allowExitOnIdle: false, | ||
statement_timeout: 30000, | ||
}; | ||
|
||
if (process.env.POSTGRES_HOST !== 'localhost') { | ||
testPoolConfig.ssl = { rejectUnauthorized: false }; | ||
} | ||
|
||
testPool = new Pool(testPoolConfig); | ||
|
||
await testPool.query('SELECT 1'); | ||
logger.info('ํ ์คํธ DB ์ฐ๊ฒฐ ์ฑ๊ณต'); | ||
|
||
repo = new UserRepository(testPool); | ||
Nuung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
afterAll(async () => { | ||
try { | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
if (testPool) { | ||
await testPool.end(); | ||
} | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
logger.info('ํ ์คํธ DB ์ฐ๊ฒฐ ์ข ๋ฃ'); | ||
} catch (error) { | ||
logger.error('ํ ์คํธ ์ข ๋ฃ ์ค ์ค๋ฅ:', error); | ||
} | ||
}); | ||
|
||
describe('QR ํ ํฐ ์์ฑ ๋ฐ ์กฐํ', () => { | ||
it('QR ํ ํฐ์ ์์ฑํ๊ณ ์ ์ ์กฐํํ ์ ์์ด์ผ ํ๋ค', async () => { | ||
const token = generateRandomToken(); | ||
const ip = '127.0.0.1'; | ||
const userAgent = 'test-agent'; | ||
|
||
await repo.createQRLoginToken(token, TEST_DATA.USER_ID, ip, userAgent); | ||
const foundToken = await repo.findQRLoginToken(token); | ||
|
||
expect(foundToken).not.toBeNull(); | ||
expect(foundToken?.token).toBe(token); | ||
expect(foundToken?.is_used).toBe(false); | ||
expect(new Date(foundToken!.expires_at).getTime()).toBeGreaterThan(new Date(foundToken!.created_at).getTime()); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Jihyun3478 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('์กด์ฌํ์ง ์๋ ํ ํฐ ์กฐํ ์ null์ ๋ฐํํด์ผ ํ๋ค', async () => { | ||
const invalidToken = generateRandomToken(); | ||
const result = await repo.findQRLoginToken(invalidToken); | ||
|
||
expect(result).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('QR ํ ํฐ ์ฌ์ฉ ์ฒ๋ฆฌ', () => { | ||
it('QR ํ ํฐ์ ์ฌ์ฉ ์ฒ๋ฆฌํ ํ ์กฐํ๋์ง ์์์ผ ํ๋ค', async () => { | ||
const token = generateRandomToken(); | ||
const ip = '127.0.0.1'; | ||
const userAgent = 'test-agent'; | ||
|
||
await repo.createQRLoginToken(token, TEST_DATA.USER_ID, ip, userAgent); | ||
await repo.markTokenUsed(token); | ||
|
||
const found = await repo.findQRLoginToken(token); | ||
|
||
expect(found).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('QR ํ ํฐ ๋ง๋ฃ ์ฒ๋ฆฌ', () => { | ||
it('๋ง๋ฃ๋ ํ ํฐ์ ์กฐํ๋์ง ์์์ผ ํ๋ค', async () => { | ||
const token = generateRandomToken(); | ||
const ip = '127.0.0.1'; | ||
const userAgent = 'test-agent'; | ||
|
||
await testPool.query( | ||
` | ||
INSERT INTO users_qrlogintoken (token, user_id, created_at, expires_at, is_used, ip_address, user_agent) | ||
VALUES ($1, $2, NOW() - INTERVAL '10 minutes', NOW() - INTERVAL '5 minutes', false, $3, $4) | ||
`, | ||
[token, TEST_DATA.USER_ID, ip, userAgent] | ||
); | ||
|
||
const found = await repo.findQRLoginToken(token); | ||
|
||
expect(found).toBeNull(); | ||
}); | ||
|
||
it('๋ง๋ฃ๋๊ณ ์ฌ์ฉ๋ ํ ํฐ๋ ์กฐํ๋์ง ์์์ผ ํ๋ค', async () => { | ||
const token = generateRandomToken(); | ||
const ip = '127.0.0.1'; | ||
const userAgent = 'test-agent'; | ||
|
||
await testPool.query( | ||
` | ||
INSERT INTO users_qrlogintoken (token, user_id, created_at, expires_at, is_used, ip_address, user_agent) | ||
VALUES ($1, $2, NOW() - INTERVAL '10 minutes', NOW() - INTERVAL '5 minutes', true, $3, $4) | ||
`, | ||
[token, TEST_DATA.USER_ID, ip, userAgent] | ||
); | ||
|
||
const found = await repo.findQRLoginToken(token); | ||
|
||
expect(found).toBeNull(); | ||
}); | ||
}); | ||
}); |
Jihyun3478 marked this conversation as resolved.
Show resolved
Hide resolved
|
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,80 @@ | ||
import { UserRepository } from '@/repositories/user.repository'; | ||
import { DBError } from '@/exception'; | ||
import { Pool } from 'pg'; | ||
|
||
const mockPool: Partial<Pool> = { | ||
query: jest.fn(), | ||
}; | ||
|
||
describe('QRLoginTokenRepository', () => { | ||
let repo: UserRepository; | ||
|
||
beforeEach(() => { | ||
repo = new UserRepository(mockPool as Pool); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('createQRLoginToken', () => { | ||
it('QR ํ ํฐ์ ์ฑ๊ณต์ ์ผ๋ก ์ฝ์ ํด์ผ ํ๋ค', async () => { | ||
(mockPool.query as jest.Mock).mockResolvedValueOnce(undefined); | ||
|
||
await expect( | ||
repo.createQRLoginToken('token', 1, 'ip', 'agent') | ||
).resolves.not.toThrow(); | ||
|
||
expect(mockPool.query).toHaveBeenCalled(); | ||
}); | ||
|
||
it('์ฝ์ ์ค ์ค๋ฅ ๋ฐ์ ์ DBError๋ฅผ ๋์ ธ์ผ ํ๋ค', async () => { | ||
(mockPool.query as jest.Mock).mockRejectedValueOnce(new Error('fail')); | ||
|
||
await expect( | ||
repo.createQRLoginToken('token', 1, 'ip', 'agent') | ||
).rejects.toThrow(DBError); | ||
}); | ||
}); | ||
|
||
describe('findQRLoginToken', () => { | ||
it('ํ ํฐ์ด ์กด์ฌํ ๊ฒฝ์ฐ ๋ฐํํด์ผ ํ๋ค', async () => { | ||
const mockTokenData = { token: 'token', user: 1 }; | ||
(mockPool.query as jest.Mock).mockResolvedValueOnce({ rows: [mockTokenData] }); | ||
|
||
const result = await repo.findQRLoginToken('token'); | ||
expect(result).toEqual(mockTokenData); | ||
}); | ||
|
||
it('ํ ํฐ์ด ์กด์ฌํ์ง ์์ผ๋ฉด null์ ๋ฐํํด์ผ ํ๋ค', async () => { | ||
(mockPool.query as jest.Mock).mockResolvedValueOnce({ rows: [] }); | ||
|
||
const result = await repo.findQRLoginToken('token'); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('์กฐํ ์ค ์ค๋ฅ ๋ฐ์ ์ DBError๋ฅผ ๋์ ธ์ผ ํ๋ค', async () => { | ||
(mockPool.query as jest.Mock).mockRejectedValueOnce(new Error('fail')); | ||
|
||
await expect(repo.findQRLoginToken('token')).rejects.toThrow(DBError); | ||
}); | ||
}); | ||
|
||
describe('markTokenUsed', () => { | ||
it('ํ ํฐ์ ์ฌ์ฉ ์ฒ๋ฆฌํด์ผ ํ๋ค', async () => { | ||
(mockPool.query as jest.Mock).mockResolvedValueOnce(undefined); | ||
|
||
await expect(repo.markTokenUsed('token')).resolves.not.toThrow(); | ||
expect(mockPool.query).toHaveBeenCalledWith( | ||
expect.stringContaining('UPDATE users_qrlogintoken SET is_used = true'), | ||
['token'] | ||
); | ||
}); | ||
|
||
it('ํ ํฐ ์ฌ์ฉ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์ ์ DBError๋ฅผ ๋์ ธ์ผ ํ๋ค', async () => { | ||
(mockPool.query as jest.Mock).mockRejectedValueOnce(new Error('fail')); | ||
|
||
await expect(repo.markTokenUsed('token')).rejects.toThrow(DBError); | ||
}); | ||
}); | ||
}); |
Jihyun3478 marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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.