import { describe, expect, it } from 'vitest'; import { resolveQuoteSheetUpdateDates } from '../src/services/quoteSheetService'; describe('quote sheet update date resolution', () => { const existing = { quote_cycle: 'month', effective_at: new Date('2026-07-11T00:00:00.000Z'), expires_at: new Date('2026-11-06T00:00:00.000Z'), }; it('表单回传旧生效日时保留已经顺延的有效期', () => { const result = resolveQuoteSheetUpdateDates(existing, { quoteCycle: 'month', effectiveAt: '2026-07-11', }); expect(result.effectiveAt).toBe(existing.effective_at); expect(result.expiresAt).toBe(existing.expires_at); }); it('实际修改生效日时重新计算过期时间', () => { const result = resolveQuoteSheetUpdateDates(existing, { effectiveAt: '2026-10-07' }); expect(result.effectiveAt.toISOString()).toBe('2026-10-07T00:00:00.000Z'); expect(result.expiresAt?.toISOString()).toBe('2026-11-06T00:00:00.000Z'); }); it('修改报价周期时重新计算过期时间', () => { const result = resolveQuoteSheetUpdateDates(existing, { quoteCycle: 'week' }); expect(result.expiresAt?.toISOString()).toBe('2026-07-18T00:00:00.000Z'); }); it('未变更且原过期时间为空时继续保持为空', () => { const result = resolveQuoteSheetUpdateDates( { ...existing, expires_at: null }, { effectiveAt: '2026-07-11', quoteCycle: 'month' } ); expect(result.expiresAt).toBeNull(); }); });