From 9612a70c7708b7e8c7edc455d2fddab4aa883f74 Mon Sep 17 00:00:00 2001 From: "chihao.ou" Date: Fri, 18 Sep 2026 16:38:29 +0800 Subject: [PATCH] fix(proxies): label newly expired proxies correctly --- .../__tests__/proxyExpiry.boundary.spec.ts | 31 +++++++++++++++++++ frontend/src/utils/proxyExpiry.ts | 1 + 2 files changed, 32 insertions(+) create mode 100644 frontend/src/utils/__tests__/proxyExpiry.boundary.spec.ts diff --git a/frontend/src/utils/__tests__/proxyExpiry.boundary.spec.ts b/frontend/src/utils/__tests__/proxyExpiry.boundary.spec.ts new file mode 100644 index 0000000000..aa9db9ffcb --- /dev/null +++ b/frontend/src/utils/__tests__/proxyExpiry.boundary.spec.ts @@ -0,0 +1,31 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { proxyExpiryLabelKey } from '../proxyExpiry' + +const now = new Date('2026-09-18T12:00:00Z') +const atOffset = (ms: number) => new Date(now.getTime() + ms).toISOString() + +beforeEach(() => { + vi.useFakeTimers() + vi.setSystemTime(now) +}) +afterEach(() => vi.useRealTimers()) + +describe('proxy expiry at the deadline', () => { + it.each([0, -1, -60 * 60 * 1000, -24 * 60 * 60 * 1000 + 1])( + 'shows expired at offset %i before the backend status changes', offset => { + expect(proxyExpiryLabelKey(atOffset(offset), 'active')).toEqual({ key: 'admin.proxies.expired' }) + } + ) + + it('keeps a future deadline in the expiring state', () => { + expect(proxyExpiryLabelKey(atOffset(1), 'active')).toEqual({ + key: 'admin.proxies.expiringInDays', params: { days: 1 } + }) + }) + + it('preserves the overdue-day count after a full day', () => { + expect(proxyExpiryLabelKey(atOffset(-24 * 60 * 60 * 1000), 'active')).toEqual({ + key: 'admin.proxies.overdueDays', params: { days: 1 } + }) + }) +}) diff --git a/frontend/src/utils/proxyExpiry.ts b/frontend/src/utils/proxyExpiry.ts index 610c4cbeac..527d6e7ac0 100644 --- a/frontend/src/utils/proxyExpiry.ts +++ b/frontend/src/utils/proxyExpiry.ts @@ -23,6 +23,7 @@ export function proxyExpiryLabelKey( ): { key: string; params?: { days: number } } { if (status === 'expired') return { key: 'admin.proxies.expired' } const d = expiresAt ? daysUntil(expiresAt) : Infinity + if (d === 0) return { key: 'admin.proxies.expired' } if (d < 0) return { key: 'admin.proxies.overdueDays', params: { days: Math.abs(d) } } if (d <= EXPIRY_WARN_DAYS) return { key: 'admin.proxies.expiringInDays', params: { days: d } } return { key: 'admin.proxies.remainingDays', params: { days: d } }