Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2608,12 +2608,28 @@ model RecurringWithdrawalPlan {
updatedAt DateTime @updatedAt

user User @relation(fields: [userId], references: [id], onDelete: Cascade)
executions RecurringWithdrawalExecution[]

@@index([userId])
@@index([status, nextRunAt])
@@map("recurring_withdrawal_plans")
}

model RecurringWithdrawalExecution {
id String @id @default(uuid())
planId String
scheduledFor DateTime
status String @default("EXECUTING")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

plan RecurringWithdrawalPlan @relation(fields: [planId], references: [id], onDelete: Cascade)

@@unique([planId, scheduledFor])
@@index([status, updatedAt])
@@map("recurring_withdrawal_executions")
}

// ─────────────────────────────────────────────────────────────────────────────
// Support Ticket System (#552)
// ─────────────────────────────────────────────────────────────────────────────
Expand Down
9 changes: 0 additions & 9 deletions src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,13 +994,4 @@ export const config = {
process.env.NLP_CONFIDENCE_THRESHOLD || '0.6'
),
},
featureFlags: {
redisSyncIntervalMs: parseInt(
process.env.FEATURE_FLAGS_REDIS_SYNC_INTERVAL_MS || '10000'
),
emergencyMaintenance:
(
process.env.FEATURE_FLAG_EMERGENCY_MAINTENANCE_MODE ?? 'false'
).toLowerCase() === 'true',
},
}
44 changes: 33 additions & 11 deletions tests/unit/jobs/recurringWithdrawals.execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,31 @@ jest.mock('../../../src/events/publisher', () => ({
}))
jest.mock('../../../src/db', () => ({
__esModule: true,
default: {
user: { findUnique: jest.fn() },
recurringWithdrawalPlan: {
default: (() => {
const recurringWithdrawalPlan = {
findMany: jest.fn(),
findUnique: jest.fn(),
updateMany: jest.fn(),
update: jest.fn(),
},
position: { findMany: jest.fn() },
outboxOp: { findFirst: jest.fn() },
linkedExternalWallet: { findFirst: jest.fn() },
complianceCase: { findFirst: jest.fn() },
savingsGoal: { findMany: jest.fn() },
},
}
const recurringWithdrawalExecution = {
create: jest.fn(async () => ({ id: 'execution' })),
updateMany: jest.fn(async () => ({ count: 1 })),
}
return {
user: { findUnique: jest.fn() },
recurringWithdrawalPlan,
recurringWithdrawalExecution,
position: { findMany: jest.fn() },
outboxOp: { findFirst: jest.fn() },
linkedExternalWallet: { findFirst: jest.fn() },
complianceCase: { findFirst: jest.fn() },
savingsGoal: { findMany: jest.fn() },
$transaction: jest.fn(async (fn: (tx: any) => unknown) =>
fn({ recurringWithdrawalPlan, recurringWithdrawalExecution })
),
}
})(),
}))

import db from '../../../src/db'
Expand Down Expand Up @@ -94,8 +105,19 @@ describe('recurring withdrawal occurrences', () => {
])
expect(executeWithdraw).toHaveBeenCalledTimes(1)
expect(executeWithdraw).toHaveBeenCalledWith(
expect.objectContaining({ walletAddress: 'GDEST', amount: 10 })
expect.objectContaining({
walletAddress: 'GDEST',
amount: 10,
idempotencyKey: `recurring-withdrawal:plan:${plan.nextRunAt.toISOString()}`,
})
)
expect(db.recurringWithdrawalExecution.create).toHaveBeenCalledWith({
data: {
planId: 'plan',
scheduledFor: expect.any(Date),
status: 'EXECUTING',
},
})
expect(plan.nextRunAt.getTime()).toBeGreaterThan(Date.now())
})
it('skips insufficient funds without a money movement attempt', async () => {
Expand Down