From d89401df3c1f98a07a9896ab661d83ded1d054d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 26 Oct 2020 18:28:49 +0100 Subject: [PATCH] fix(catalog): unbreak the catalog client (#3106) --- plugins/catalog/src/api/CatalogClient.test.ts | 6 ++---- plugins/catalog/src/api/CatalogClient.ts | 12 ++++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/plugins/catalog/src/api/CatalogClient.test.ts b/plugins/catalog/src/api/CatalogClient.test.ts index 7c0123317d..927e8dd52c 100644 --- a/plugins/catalog/src/api/CatalogClient.test.ts +++ b/plugins/catalog/src/api/CatalogClient.test.ts @@ -34,7 +34,7 @@ describe('CatalogClient', () => { client = new CatalogClient({ discoveryApi }); }); - describe('getEntiies', () => { + describe('getEntities', () => { const defaultResponse: Entity[] = [ { apiVersion: '1', @@ -71,9 +71,7 @@ describe('CatalogClient', () => { expect.assertions(2); server.use( rest.get(`${mockBaseUrl}/entities`, (req, res, ctx) => { - expect(req.url.searchParams.toString()).toBe( - 'a=1&b=2&b=3&%C3%B6=%3D', - ); + expect(req.url.search).toBe('?filter=a=1,b=2,b=3,%C3%B6=%3D'); return res(ctx.json([])); }), ); diff --git a/plugins/catalog/src/api/CatalogClient.ts b/plugins/catalog/src/api/CatalogClient.ts index 6b10541107..642183f916 100644 --- a/plugins/catalog/src/api/CatalogClient.ts +++ b/plugins/catalog/src/api/CatalogClient.ts @@ -68,17 +68,13 @@ export class CatalogClient implements CatalogApi { ): Promise { let path = `/entities`; if (filter) { - const params = new URLSearchParams(); + const parts: string[] = []; for (const [key, value] of Object.entries(filter)) { - if (Array.isArray(value)) { - for (const v of value) { - params.append(key, v); - } - } else { - params.append(key, value); + for (const v of [value].flat()) { + parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(v)}`); } } - path += `?${params.toString()}`; + path += `?filter=${parts.join(',')}`; } return await this.getRequired(path);