mirror of
https://github.com/gramps-project/gramps-web.git
synced 2026-10-17 05:10:56 +08:00
5bf7ce9455
When generating a media archive hits the per-user rate limit, show a translated message including the configured limit from the metadata endpoint.
29 lines
882 B
JavaScript
29 lines
882 B
JavaScript
import {describe, it, expect} from 'vitest'
|
|
import {formatRateLimit} from '../../src/util.js'
|
|
|
|
describe('formatRateLimit', () => {
|
|
it('formats a single unit window without a count', () => {
|
|
expect(formatRateLimit([{amount: 1, window_seconds: 86400}])).toBe('1/day')
|
|
})
|
|
|
|
it('formats multi-unit windows in the largest whole unit', () => {
|
|
expect(
|
|
formatRateLimit([
|
|
{amount: 100, window_seconds: 7200},
|
|
{amount: 5, window_seconds: 90},
|
|
])
|
|
).toBe('100/2 hours, 5/90 seconds')
|
|
})
|
|
|
|
it('localizes with an underscore locale', () => {
|
|
expect(formatRateLimit([{amount: 1, window_seconds: 3600}], 'de_DE')).toBe(
|
|
'1/Stunde'
|
|
)
|
|
})
|
|
|
|
it('returns an empty string for missing or invalid limits', () => {
|
|
expect(formatRateLimit(undefined)).toBe('')
|
|
expect(formatRateLimit([{amount: 1, window_seconds: 0}])).toBe('')
|
|
})
|
|
})
|