Files
web-core/tests/api/query.test.ts
Beatrice Dellacà d7e144620e
All checks were successful
continuous-integration/drone/push Build is passing
add unit tests
2026-02-24 11:14:24 +01:00

26 lines
758 B
TypeScript

import { describe, expect, it } from 'vitest';
import { buildListQuery } from '../../src/api/query';
describe('buildListQuery', () => {
it('builds query with trimmed search and explicit sort', () => {
const result = buildListQuery({
q: ' jane ',
page: 3,
pageSize: 20,
sort: ' createdAt ',
defaultSort: '-createdAt',
});
expect(result).toBe('q=jane&page=3&pageSize=20&sort=createdAt');
});
it('falls back to defaults when query is blank and sort missing', () => {
const result = buildListQuery({
q: ' ',
defaultSort: '-createdAt',
});
expect(result).toBe('page=1&pageSize=10&sort=-createdAt');
});
});