Set filter to undefined when it's empty on findExceptionLists method (#128455)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
David Sánchez 2022-03-29 12:44:31 +02:00 committed by GitHub
parent bf2769d7ee
commit a07c47c652
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -231,7 +231,7 @@ const fetchExceptionLists = async ({
signal,
}: ApiCallFetchExceptionListsProps): Promise<FoundExceptionListSchema> => {
const query = {
filter: filters,
filter: filters || undefined,
namespace_type: namespaceTypes,
page: pagination.page ? `${pagination.page}` : '1',
per_page: pagination.perPage ? `${pagination.perPage}` : '20',

View file

@ -278,6 +278,31 @@ describe('Exceptions Lists API', () => {
expect(exceptionResponse.data).toEqual([getExceptionListSchemaMock()]);
});
test('it returns expected exception lists when empty filter', async () => {
const exceptionResponse = await fetchExceptionLists({
filters: '',
http: httpMock,
namespaceTypes: 'single,agnostic',
pagination: {
page: 1,
perPage: 20,
},
signal: abortCtrl.signal,
});
expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/_find', {
method: 'GET',
query: {
namespace_type: 'single,agnostic',
page: '1',
per_page: '20',
sort_field: 'exception-list.created_at',
sort_order: 'desc',
},
signal: abortCtrl.signal,
});
expect(exceptionResponse.data).toEqual([getExceptionListSchemaMock()]);
});
test('it returns error if response payload fails decode', async () => {
const badPayload = getExceptionListSchemaMock();
// @ts-expect-error