fix: resolve all test failures after vitest 2.x upgrade
- Attach rejects handler before advancing timers (vitest 2.x strict mode) - Fix FK constraint cleanup order in test setup - Fix 7-char prefix matching test data - Add INSERT OR IGNORE for deposit concurrency safety - Add secondary ORDER BY for deterministic transaction ordering - Update summary-service test assertions to match current prompt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -438,16 +438,25 @@ export async function executeDepositFunction(
|
||||
): Promise<DepositFunctionResult> {
|
||||
const { userId, isAdmin, db } = context;
|
||||
|
||||
// 예치금 계정 조회 또는 생성
|
||||
// 예치금 계정 조회 또는 생성 (동시성 안전)
|
||||
let deposit = await db.prepare(
|
||||
'SELECT id, balance FROM user_deposits WHERE user_id = ?'
|
||||
).bind(userId).first<{ id: number; balance: number }>();
|
||||
|
||||
if (!deposit) {
|
||||
// INSERT OR IGNORE로 동시 요청 시 UNIQUE 제약 위반 방지
|
||||
await db.prepare(
|
||||
'INSERT INTO user_deposits (user_id, balance) VALUES (?, 0)'
|
||||
'INSERT OR IGNORE INTO user_deposits (user_id, balance) VALUES (?, 0)'
|
||||
).bind(userId).run();
|
||||
deposit = { id: 0, balance: 0 };
|
||||
|
||||
// 재조회 (다른 요청이 먼저 생성했을 수 있음)
|
||||
deposit = await db.prepare(
|
||||
'SELECT id, balance FROM user_deposits WHERE user_id = ?'
|
||||
).bind(userId).first<{ id: number; balance: number }>();
|
||||
|
||||
if (!deposit) {
|
||||
deposit = { id: 0, balance: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
switch (funcName) {
|
||||
@@ -595,7 +604,7 @@ export async function executeDepositFunction(
|
||||
`SELECT id, type, amount, status, depositor_name, description, created_at, confirmed_at
|
||||
FROM deposit_transactions
|
||||
WHERE user_id = ?
|
||||
ORDER BY created_at DESC
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT ?`
|
||||
).bind(userId, limit).all<{
|
||||
id: number;
|
||||
|
||||
Reference in New Issue
Block a user