Files
sub2api-overdraft/frontend/src/utils/__tests__/formatDateLocalInput.spec.ts
T
yan9651688 3605a316af Keep usage ranges consistent across API and dashboards
Expose the active weekly subscription window through /v1/usage, calculate offsets with the same normalized page size used by queries, and keep user-facing date ranges on the browser's local calendar date.

Constraint: Preserve existing response fields and avoid new dependencies
Rejected: Keep duplicate inline date formatters | a shared local-date utility prevents the same UTC regression in both views
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep Offset and Limit based on the same normalized page size
Tested: go test ./internal/pkg/pagination ./internal/handler; go vet ./internal/pkg/pagination ./internal/handler; frontend 923 tests; pnpm typecheck; pnpm lint:check; pnpm build
Not-tested: Live API request against a deployed subscription
Related: #4121
2026-07-13 11:35:46 +08:00

19 lines
625 B
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { formatDateLocalInput } from '../format'
describe('formatDateLocalInput', () => {
it('formats the calendar date in local time', () => {
const localDate = new Date('2026-07-12T16:30:00Z')
vi.spyOn(localDate, 'getFullYear').mockReturnValue(2026)
vi.spyOn(localDate, 'getMonth').mockReturnValue(6)
vi.spyOn(localDate, 'getDate').mockReturnValue(13)
expect(formatDateLocalInput(localDate)).toBe('2026-07-13')
})
it('returns an empty string for an invalid date', () => {
expect(formatDateLocalInput(new Date('invalid'))).toBe('')
})
})