fix credits package bug and improve stale payment logic

This commit is contained in:
jwinterm
2026-02-19 07:05:15 -05:00
parent bc55f0355e
commit 5776c58357
6 changed files with 102 additions and 24 deletions
+12 -10
View File
@@ -432,18 +432,19 @@ describe('Payment & Payout Comprehensive Tests', () => {
test('creates single_game payment request correctly', async () => {
const user = { id: 1, credits: 0 };
gmm.singleGamePrice = 100000000000;
mockDb.query.mockResolvedValueOnce({ rows: [user] }); // getOrCreateUser
mockDb.query.mockResolvedValueOnce({ rows: [] }); // update last_active
mockDb.query.mockResolvedValueOnce({ rows: [] }); // no existing payment
mockDb.query.mockResolvedValueOnce({ rows: [] }); // expire stale payments
mockWalletService.createPaymentRequest.mockResolvedValueOnce({
address: 'wow1paymentaddr',
expiresAt: new Date()
});
mockDb.query.mockResolvedValueOnce({
rows: [{ id: 999, expires_at: new Date() }]
mockDb.query.mockResolvedValueOnce({
rows: [{ id: 999, expires_at: new Date() }]
}); // INSERT payment
const result = await gmm.createPaymentRequest('socket1', 'single_game');
@@ -462,18 +463,19 @@ describe('Payment & Payout Comprehensive Tests', () => {
test('creates credits_package payment request correctly', async () => {
const user = { id: 1, credits: 0 };
gmm.creditsPackagePrice = 500000000000;
mockDb.query.mockResolvedValueOnce({ rows: [user] }); // getOrCreateUser
mockDb.query.mockResolvedValueOnce({ rows: [] }); // update last_active
mockDb.query.mockResolvedValueOnce({ rows: [] }); // no existing payment
mockDb.query.mockResolvedValueOnce({ rows: [] }); // expire stale payments
mockWalletService.createPaymentRequest.mockResolvedValueOnce({
address: 'wow1creditspayment',
expiresAt: new Date()
});
mockDb.query.mockResolvedValueOnce({
rows: [{ id: 1000, expires_at: new Date() }]
mockDb.query.mockResolvedValueOnce({
rows: [{ id: 1000, expires_at: new Date() }]
}); // INSERT payment
const result = await gmm.createPaymentRequest('socket1', 'credits_package');