mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
* Adding a maximum for query limit * fixed bad env check * using the getEnv function to make it better testable * updated sanitize-query tests * added tests for the validate query function * Added DEFAULT_QUERY_LIMIT as fallback instead * make the linter happy * accept infinity as max_query_limit * fixed merge conflicts * added missing import * moved docs PR into main repo * added missing import * renamed vars * basic page size limiting * Update app/src/layouts/cards/cards.vue * Update app/src/layouts/map/map.vue * Update app/src/layouts/tabular/tabular.vue * Update app/src/layouts/tabular/tabular.vue * Create paginate util * extracted page size logic to composable and implemented default usage in app * updated paginate utility * using the new fetch-all utility * removed limit: -1 for api calls that do not support it * fix linter * removed console log * making the linter happy * Create loud-flowers-yawn.md * Add tests for no / unlimited limit * Cover all cases for max limit in sanitizeQuery * Get rid of non-null assertion * added test for composable * Update var names in documentation * replace hardcoded limit default with env var * update default page size behavior * fixed test * update server info api reference * include queryLimit in graphql server info * use configured max limit in calendar layout * use configured max limit in kanban layout * account for max query limit in use-revisions --------- Co-authored-by: ian <licitdev@gmail.com> Co-authored-by: rijkvanzanten <rijkvanzanten@me.com> Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
import env from '../env.js';
|
|
|
|
const getValidateQuery = async (mockedEnv?: { [k: string]: any }) => {
|
|
vi.doMock('../env', async () => {
|
|
return {
|
|
default: {
|
|
...env,
|
|
...mockedEnv,
|
|
},
|
|
};
|
|
});
|
|
|
|
return (await import('./validate-query.js')).validateQuery;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
});
|
|
|
|
describe('max limit', () => {
|
|
describe('max limit of 100', async () => {
|
|
const validateQuery = await getValidateQuery({ QUERY_LIMIT_MAX: 100 });
|
|
|
|
test.each([-1, 1, 25])('should accept number %i', (limit) => {
|
|
expect(() => validateQuery({ limit })).not.toThrowError('limit');
|
|
});
|
|
|
|
test('should error with 101', () => {
|
|
expect(() => validateQuery({ limit: 101 })).toThrowError('limit');
|
|
});
|
|
});
|
|
|
|
test('should accept 101 when no limit defined', async () => {
|
|
const validateQuery = await getValidateQuery();
|
|
|
|
expect(() => validateQuery({ limit: 101 })).not.toThrowError('limit');
|
|
});
|
|
|
|
test('should accept 101 when unlimited', async () => {
|
|
const validateQuery = await getValidateQuery({ QUERY_LIMIT_MAX: -1 });
|
|
|
|
expect(() => validateQuery({ limit: 101 })).not.toThrowError('limit');
|
|
});
|
|
});
|
|
|
|
describe('export', async () => {
|
|
const validateQuery = await getValidateQuery();
|
|
|
|
test.each(['csv', 'json', 'xml', 'yaml'])('should accept format %i', (format) => {
|
|
expect(() => validateQuery({ export: format } as any)).not.toThrowError();
|
|
});
|
|
|
|
test('should error with invalid-format', () => {
|
|
expect(() => validateQuery({ export: 'invalid-format' } as any)).toThrowError('"export" must be one of');
|
|
});
|
|
});
|