admin/lib/reviewWindow.test.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

40 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { isWithinHostReplyWindow, isWithinReviewWindow } from '@/lib/reviewWindow'
describe('isWithinReviewWindow', () => {
it('is open within 1 month of endsAt', () => {
const endsAt = new Date('2026-06-01T12:00:00.000Z')
const now = new Date('2026-06-20T12:00:00.000Z')
expect(isWithinReviewWindow(endsAt, now)).toBe(true)
})
it('is closed after 1 month', () => {
const endsAt = new Date('2026-06-01T12:00:00.000Z')
const now = new Date('2026-07-02T12:00:00.000Z')
expect(isWithinReviewWindow(endsAt, now)).toBe(false)
})
it('rejects invalid dates', () => {
expect(isWithinReviewWindow('not-a-date')).toBe(false)
})
})
describe('isWithinHostReplyWindow', () => {
it('is open within 2 months of endsAt', () => {
const endsAt = new Date('2026-06-01T12:00:00.000Z')
const now = new Date('2026-07-15T12:00:00.000Z')
expect(isWithinHostReplyWindow(endsAt, now)).toBe(true)
})
it('is closed after 2 months', () => {
const endsAt = new Date('2026-06-01T12:00:00.000Z')
const now = new Date('2026-08-02T12:00:00.000Z')
expect(isWithinHostReplyWindow(endsAt, now)).toBe(false)
})
})