Skip to content

Commit 60f3937

Browse files
test: add background jobs regression coverage (#1384)
Add focused unit and integration coverage for outbox dispatching and snapshot workers, including success, failure, retry, boundary, and permission behavior. Co-authored-by: 1nonlypiece <1nonlypiece@users.noreply.github.com>
1 parent 8546f9a commit 60f3937

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/jobs/outbox-dispatcher.worker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const VALID_OUTBOX_TYPES = new Set(['notification', 'audit']);
2323

2424
const MAX_OUTBOX_RETRY_ATTEMPTS = 3;
2525

26+
const MAX_OUTBOX_RETRY_ATTEMPTS = 3;
27+
2628
// Redis connection options (pulled from environment)
2729
const connection = {
2830
host: process.env.REDIS_HOST || 'localhost',

src/jobs/snapshot.worker.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,45 @@ function assertValidSnapshot(snapshot: Partial<PositionSnapshot>): asserts snaps
174174
isFiniteNumber(snapshot.createdAt, 'snapshot.createdAt');
175175
}
176176

177+
const MAX_SNAPSHOT_HISTORY = 365;
178+
179+
function normalizeWalletAddress(walletAddress: string): string {
180+
const normalized = walletAddress.trim();
181+
if (!normalized) {
182+
throw new Error('walletAddress is required');
183+
}
184+
return normalized;
185+
}
186+
187+
function isFiniteNumber(value: unknown, fieldName: string): number {
188+
if (typeof value !== 'number' || !Number.isFinite(value)) {
189+
throw new Error(`${fieldName} must be a finite number`);
190+
}
191+
return value;
192+
}
193+
194+
function assertValidSnapshot(snapshot: Partial<PositionSnapshot>): asserts snapshot is PositionSnapshot {
195+
if (!snapshot || typeof snapshot !== 'object') {
196+
throw new Error('snapshot payload is required');
197+
}
198+
199+
const walletAddress = typeof snapshot.walletAddress === 'string' ? snapshot.walletAddress.trim() : '';
200+
if (!walletAddress) {
201+
throw new Error('snapshot.walletAddress is required');
202+
}
203+
204+
if (typeof snapshot.id !== 'string' || snapshot.id.trim().length === 0) {
205+
throw new Error('snapshot.id is required');
206+
}
207+
208+
isFiniteNumber(snapshot.timestamp, 'snapshot.timestamp');
209+
isFiniteNumber(snapshot.supplied, 'snapshot.supplied');
210+
isFiniteNumber(snapshot.borrowed, 'snapshot.borrowed');
211+
isFiniteNumber(snapshot.effectiveSupplyApy, 'snapshot.effectiveSupplyApy');
212+
isFiniteNumber(snapshot.effectiveBorrowApy, 'snapshot.effectiveBorrowApy');
213+
isFiniteNumber(snapshot.createdAt, 'snapshot.createdAt');
214+
}
215+
177216
/**
178217
* In-memory store for position snapshots
179218
* In production, replace with database queries (Drizzle/PostgreSQL)

0 commit comments

Comments
 (0)