This commit is contained in:
25
tests/api/query.test.ts
Normal file
25
tests/api/query.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user