2026-09-11 11:41:52 +02:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2026-09-11 13:52:13 +02:00
|
|
|
import { PAGE_SIZE, langParam, pageParam, pagination, quote } from '../../frontend/server/utils/queries'
|
2026-09-11 11:41:52 +02:00
|
|
|
|
|
|
|
|
describe('pagination', () => {
|
|
|
|
|
it('defaults to PAGE_SIZE', () => {
|
|
|
|
|
expect(pagination(2)).toBe(`page=2&perPage=${PAGE_SIZE}`)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('accepts a custom page size', () => {
|
|
|
|
|
expect(pagination(1, 5)).toBe('page=1&perPage=5')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('pageParam', () => {
|
|
|
|
|
it('accepts a positive integer', () => {
|
|
|
|
|
expect(pageParam('3')).toBe(3)
|
|
|
|
|
expect(pageParam(3)).toBe(3)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it.each([undefined, null, '', 'abc', '0', '-1', '1.5', NaN])(
|
|
|
|
|
'falls back to 1 for invalid input %p',
|
|
|
|
|
(value) => {
|
|
|
|
|
expect(pageParam(value)).toBe(1)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2026-09-11 13:52:13 +02:00
|
|
|
describe('langParam', () => {
|
|
|
|
|
it('accepts "en"', () => {
|
|
|
|
|
expect(langParam('en')).toBe('en')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it.each([undefined, null, '', 'it', 'fr', 123])('falls back to "it" for %p', (value) => {
|
|
|
|
|
expect(langParam(value)).toBe('it')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-09-11 11:41:52 +02:00
|
|
|
describe('quote', () => {
|
|
|
|
|
it('wraps a plain value in double quotes', () => {
|
|
|
|
|
expect(quote('economia')).toBe('"economia"')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('escapes embedded double quotes', () => {
|
|
|
|
|
expect(quote('la "crisi"')).toBe('"la \\"crisi\\""')
|
|
|
|
|
})
|
|
|
|
|
})
|