Skip to content

Commit

Permalink
Move tests to actual function implementing the parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
hanneskuettner committed Apr 30, 2024
1 parent 57e7dba commit 745c735
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
24 changes: 0 additions & 24 deletions api/src/utils/sanitize-query.test.ts
Expand Up @@ -210,30 +210,6 @@ describe('filter', () => {
expect(sanitizedQuery.filter).toEqual({ field_a: { _eq: 'test' } });
});

test('should accept empty filter object', () => {
const filter = {};

const sanitizedQuery = sanitizeQuery({ filter });

expect(sanitizedQuery.filter).toEqual({});
});

test('should accept empty object for key', () => {
const filter = { field_a: {} };

const sanitizedQuery = sanitizeQuery({ filter });

expect(sanitizedQuery.filter).toEqual({ field_a: {} });
});

test('should accept empty array for key', () => {
const filter = { field_a: [] };

const sanitizedQuery = sanitizeQuery({ filter });

expect(sanitizedQuery.filter).toEqual({ field_a: [] });
});

test('should throw error on invalid filter', () => {
const filter = { field_a: null };

Expand Down
16 changes: 16 additions & 0 deletions packages/utils/shared/parse-filter.test.ts
Expand Up @@ -12,6 +12,22 @@ describe('#parseFilter', () => {
vi.useRealTimers();
});

it('should accept empty filter object', () => {
const filter = {};

const parsedFilter = parseFilter(filter, null);

expect(parsedFilter).toEqual({});
});

it('should accept empty object for key', () => {
const filter = { field_a: {} };

const parsedFilter = parseFilter(filter, null);

expect(parsedFilter).toEqual({ field_a: {} });
});

it('returns the filter when passed accountability with only a role', () => {
const mockFilter = { _and: [{ field: { _eq: 'field' } }] } as Filter;
const mockAccountability = { role: 'admin' };
Expand Down

0 comments on commit 745c735

Please sign in to comment.