mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 16:04:24 +00:00
fix(proxies): label newly expired proxies correctly
This commit is contained in:
1 parent
efe9aab1e4
commit
9612a70c77
2 files changed
+32
No files matched your search
@@ -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 }
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -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 } }
|
||||
|
||||
Reference in new issue
Block a user