* feat(voucher): add create voucher and correct entry previews; update commit methods * feat: add support for pending operations in API key scopes and OAuth client management - Introduced new API key scopes for reading and approving pending operations. - Updated the scope groups to include pending operations. - Added new tools for listing and managing pending operations. - Implemented OAuth client registration and revocation endpoints. - Created a UI panel for managing OAuth clients, including registration and revocation. - Added tests for pending operations tools and OAuth allowlist functionality. - Implemented a database migration for OAuth client registrations with appropriate policies and constraints. * feat: Implement OAuth client registration rate limiting and enhance security measures - Added IP-based rate limiting to the OAuth client registration endpoint to prevent enumeration attacks. - Introduced a service-role client for allowlist lookups, ensuring trust boundaries are maintained. - Updated error responses to be uniform across different types of redirect URI validation failures. - Enhanced tests to reflect changes in OAuth scope handling, ensuring fallback to read-only scopes when no scopes are provided. - Improved handling of high-risk pending operations, requiring explicit confirmation for approvals. - Added audit logging for OAuth client revocations and pending operation approvals/rejections to maintain a security audit trail. - Refactored API key scope management to include default read-only scopes for OAuth-issued keys and added segregation-of-duties checks. * feat: add recurring invoice scheduling functionality - Implemented recurring invoice schedules with a new database schema. - Created API routes for managing recurring invoices (GET and POST). - Added cron job to automatically generate invoices based on schedules. - Developed service functions for computing next run dates and executing schedules. - Added tests for the new functionality, including validation and success cases. - Introduced error handling for various scenarios in the invoice creation process. * feat: refine VAT rate validation and enhance recurring invoice handling
66 lines
2.3 KiB
TypeScript
66 lines
2.3 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
computeNextRunDate,
|
|
computeInitialRunDate,
|
|
} from '@/lib/invoices/recurring-schedule-service'
|
|
|
|
describe('computeNextRunDate', () => {
|
|
it('advances day 15 from January to February', () => {
|
|
const result = computeNextRunDate(new Date(Date.UTC(2026, 0, 15)), 15)
|
|
expect(result).toBe('2026-02-15')
|
|
})
|
|
|
|
it('clamps day 31 to last day of February (non-leap)', () => {
|
|
// 2027 February has 28 days.
|
|
const result = computeNextRunDate(new Date(Date.UTC(2027, 0, 31)), 31)
|
|
expect(result).toBe('2027-02-28')
|
|
})
|
|
|
|
it('clamps day 31 to last day of February in a leap year', () => {
|
|
const result = computeNextRunDate(new Date(Date.UTC(2028, 0, 31)), 31)
|
|
expect(result).toBe('2028-02-29')
|
|
})
|
|
|
|
it('rolls into the next year correctly', () => {
|
|
const result = computeNextRunDate(new Date(Date.UTC(2026, 11, 15)), 15)
|
|
expect(result).toBe('2027-01-15')
|
|
})
|
|
|
|
it('clamps day 31 to 30 in 30-day months (April)', () => {
|
|
const result = computeNextRunDate(new Date(Date.UTC(2026, 2, 31)), 31)
|
|
expect(result).toBe('2026-04-30')
|
|
})
|
|
|
|
it('rejects invalid day_of_month', () => {
|
|
expect(() => computeNextRunDate(new Date(), 0)).toThrow()
|
|
expect(() => computeNextRunDate(new Date(), 32)).toThrow()
|
|
})
|
|
})
|
|
|
|
describe('computeInitialRunDate', () => {
|
|
it('picks this month when day_of_month is in the future', () => {
|
|
const today = new Date(Date.UTC(2026, 4, 5)) // 2026-05-05
|
|
expect(computeInitialRunDate(today, 15)).toBe('2026-05-15')
|
|
})
|
|
|
|
it('picks today when day_of_month === today', () => {
|
|
const today = new Date(Date.UTC(2026, 4, 15))
|
|
expect(computeInitialRunDate(today, 15)).toBe('2026-05-15')
|
|
})
|
|
|
|
it('picks next month when day_of_month is in the past', () => {
|
|
const today = new Date(Date.UTC(2026, 4, 20))
|
|
expect(computeInitialRunDate(today, 15)).toBe('2026-06-15')
|
|
})
|
|
|
|
it('honours start_date override', () => {
|
|
const today = new Date(Date.UTC(2026, 4, 20))
|
|
expect(computeInitialRunDate(today, 15, '2027-01-01')).toBe('2027-01-01')
|
|
})
|
|
|
|
it('clamps day 31 in February when picking this-month', () => {
|
|
const today = new Date(Date.UTC(2027, 1, 10)) // 2027-02-10, Feb has 28 days
|
|
expect(computeInitialRunDate(today, 31)).toBe('2027-02-28')
|
|
})
|
|
})
|