import { describe, expect, it } from 'vitest'; import { buildQuoteRolloverArchiveHeader } from '../src/services/quoteSheetService'; describe('quote sheet rollover history snapshot', () => { it('archives ended cycle as status=3 with parent pointing to live sheet', () => { const expiresAt = new Date('2026-08-01T00:00:00.000Z'); const effectiveAt = new Date('2026-07-01T00:00:00.000Z'); const header = buildQuoteRolloverArchiveHeader( { quote_sheet_code: 'QS_LIVE', title: '食堂月报价', quote_cycle: 'month', effective_at: effectiveAt, expires_at: expiresAt, approved_by: 'user-1', approved_at: effectiveAt, branch_code: 'BR01', created_by: 'user-1', rollover_count: 2, }, 'QS_ARCHIVE', 9 ); expect(header).toMatchObject({ quote_sheet_code: 'QS_ARCHIVE', title: '食堂月报价', version_no: 9, quote_cycle: 'month', status: 3, approval_status: 30, parent_sheet_code: 'QS_LIVE', branch_code: 'BR01', rollover_count: 2, }); expect(header.expires_at).toBe(expiresAt); expect(header.effective_at).toBe(effectiveAt); }); it('falls back title when live sheet title empty', () => { const header = buildQuoteRolloverArchiveHeader( { quote_sheet_code: 'QS_LIVE', title: ' ', quote_cycle: 'week', expires_at: '2026-08-10T00:00:00.000Z', branch_code: 'BR01', }, 'QS_ARCH2', 3 ); expect(header.title).toBe('报价单 V3'); expect(header.parent_sheet_code).toBe('QS_LIVE'); expect(header.status).toBe(3); }); });