final touches for beta skymoney (at least i think)
This commit is contained in:
32
web/tests/funding.test.ts
Normal file
32
web/tests/funding.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { computeFixedFundingStatus } from '../src/utils/funding';
|
||||
|
||||
describe('computeFixedFundingStatus', () => {
|
||||
it('weekly pay, 3-week window, after 1 week funded one-third -> no funding needed', () => {
|
||||
const cycleStart = new Date('2025-11-01T00:00:00.000Z');
|
||||
const now = new Date('2025-11-08T00:00:00.000Z'); // 7 days later => 1 paycheck elapsed
|
||||
const due = new Date(cycleStart.getTime() + 21 * 24 * 60 * 60 * 1000); // 21 days after start
|
||||
const total = 30000; // $300.00
|
||||
const funded = Math.round(total / 3); // after 1 paycheck
|
||||
|
||||
const plans = [{ id: 'p1', name: 'Rent', totalCents: total, fundedCents: funded, dueOn: due.toISOString(), cycleStart: cycleStart.toISOString() }];
|
||||
|
||||
const res = computeFixedFundingStatus('regular', 'weekly', plans, now, false, 100);
|
||||
expect(res.needsFunding).toBe(false);
|
||||
expect(res.plans[0].needsFunding).toBe(false);
|
||||
});
|
||||
|
||||
it('weekly pay, 3-week window, after 1 week underfunded -> needs funding', () => {
|
||||
const cycleStart = new Date('2025-11-01T00:00:00.000Z');
|
||||
const now = new Date('2025-11-08T00:00:00.000Z'); // 7 days later
|
||||
const due = new Date(cycleStart.getTime() + 21 * 24 * 60 * 60 * 1000);
|
||||
const total = 30000; // $300.00
|
||||
const funded = Math.round(total / 3) - 500; // under by $5
|
||||
|
||||
const plans = [{ id: 'p1', name: 'Rent', totalCents: total, fundedCents: funded, dueOn: due.toISOString(), cycleStart: cycleStart.toISOString() }];
|
||||
|
||||
const res = computeFixedFundingStatus('regular', 'weekly', plans, now, false, 100);
|
||||
expect(res.needsFunding).toBe(true);
|
||||
expect(res.plans[0].needsFunding).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user