fix(catalog): unbreak the catalog client (#3106)

This commit is contained in:
Fredrik Adelöw
2020-10-26 18:28:49 +01:00
committed by GitHub
parent 5d166212bf
commit d89401df3c
2 changed files with 6 additions and 12 deletions
@@ -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([]));
}),
);
+4 -8
View File
@@ -68,17 +68,13 @@ export class CatalogClient implements CatalogApi {
): Promise<Entity[]> {
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);