feat: CAPA effectiveness re-check cron — 30/60/90-day email + WhatsApp notifications
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FFDuBhMKvoWjrWT3ZnGmmr
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
getNextRecheckDate,
|
||||
shouldSendRecheck,
|
||||
getRoundLabel,
|
||||
} from '@/lib/notifications/effectiveness-recheck'
|
||||
|
||||
describe('getRoundLabel', () => {
|
||||
it('returns "30-day" for round 0', () => {
|
||||
expect(getRoundLabel(0)).toBe('30-day')
|
||||
})
|
||||
it('returns "60-day" for round 1', () => {
|
||||
expect(getRoundLabel(1)).toBe('60-day')
|
||||
})
|
||||
it('returns "90-day" for round 2', () => {
|
||||
expect(getRoundLabel(2)).toBe('90-day')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getNextRecheckDate', () => {
|
||||
// verifiedAt 2026-07-01. July has 31 days.
|
||||
// +60d → July 1 + 60 = Aug 30
|
||||
// +90d → July 1 + 90 = Sep 29
|
||||
it('returns 60d from verifiedAt when round 0 just sent', () => {
|
||||
expect(getNextRecheckDate('2026-07-01T00:00:00Z', 0)).toBe('2026-08-30')
|
||||
})
|
||||
it('returns 90d from verifiedAt when round 1 just sent', () => {
|
||||
expect(getNextRecheckDate('2026-07-01T00:00:00Z', 1)).toBe('2026-09-29')
|
||||
})
|
||||
it('returns null when round 2 just sent (all done)', () => {
|
||||
expect(getNextRecheckDate('2026-07-01T00:00:00Z', 2)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('shouldSendRecheck', () => {
|
||||
it('true when date equals today and round < 3', () => {
|
||||
expect(shouldSendRecheck('2026-07-11', 0, '2026-07-11')).toBe(true)
|
||||
})
|
||||
it('true when date is in the past and round < 3', () => {
|
||||
expect(shouldSendRecheck('2026-07-10', 2, '2026-07-11')).toBe(true)
|
||||
})
|
||||
it('false when round is 3 (all done)', () => {
|
||||
expect(shouldSendRecheck('2026-07-10', 3, '2026-07-11')).toBe(false)
|
||||
})
|
||||
it('false when recheckDate is null', () => {
|
||||
expect(shouldSendRecheck(null, 0, '2026-07-11')).toBe(false)
|
||||
})
|
||||
it('false when date is in the future', () => {
|
||||
expect(shouldSendRecheck('2026-07-20', 0, '2026-07-11')).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user