gongxiangp2/lib/__tests__/performance-survey-period.test.ts
2026-07-10 17:15:54 +08:00

50 lines
1.5 KiB
TypeScript

/** @jest-environment node */
import {
PerformanceSurveyApiError,
resolvePerformanceSurveyPeriodInput,
} from '@/lib/performance-survey-service'
describe('performance survey period', () => {
const now = new Date('2026-07-10T08:00:00.000Z')
test('考核月份不会再自动变成截止时间', () => {
const result = resolvePerformanceSurveyPeriodInput({
assessmentMonth: '2026-03',
dueAt: null,
openNow: true,
}, now)
expect(result).toEqual({
assessmentMonth: '2026-03',
dueAt: null,
})
})
test('独立设置的未来截止时间会被保留', () => {
const result = resolvePerformanceSurveyPeriodInput({
assessmentMonth: '2026-07',
dueAt: '2026-07-20T10:00:00.000Z',
openNow: true,
}, now)
expect(result.assessmentMonth).toBe('2026-07')
expect(result.dueAt?.toISOString()).toBe('2026-07-20T10:00:00.000Z')
})
test('发布时不允许使用已经过去的截止时间', () => {
expect(() => resolvePerformanceSurveyPeriodInput({
assessmentMonth: '2026-07',
dueAt: '2026-07-01T00:00:00.000Z',
openNow: true,
}, now)).toThrow(new PerformanceSurveyApiError('截止时间必须晚于当前时间'))
})
test('显式传入无效月份时不会静默改成当前月', () => {
expect(() => resolvePerformanceSurveyPeriodInput({
assessmentMonth: '2026-13',
dueAt: null,
}, now)).toThrow(new PerformanceSurveyApiError('考核月份格式无效'))
})
})