add post body fields too

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-12-21 15:10:31 +01:00
parent 7307d4db39
commit e23f13a573
9 changed files with 79 additions and 47 deletions
@@ -232,9 +232,9 @@ describe('CatalogClient', () => {
};
server.use(
rest.post(`${mockBaseUrl}/entities/by-refs`, async (req, res, ctx) => {
expect(req.url.searchParams.get('fields')).toBe('a,b');
await expect(req.json()).resolves.toEqual({
entityRefs: ['k:n/a', 'k:n/b'],
fields: ['a', 'b'],
});
return res(ctx.json({ items: [entity, null] }));
}),
+4 -5
View File
@@ -197,14 +197,13 @@ export class CatalogClient implements CatalogApi {
request: GetEntitiesByRefsRequest,
options?: CatalogRequestOptions,
): Promise<GetEntitiesByRefsResponse> {
const params: string[] = [];
const body: any = { entityRefs: request.entityRefs };
if (request.fields?.length) {
params.push(`fields=${request.fields.map(encodeURIComponent).join(',')}`);
body.fields = request.fields;
}
const baseUrl = await this.discoveryApi.getBaseUrl('catalog');
const query = params.length ? `?${params.join('&')}` : '';
const url = `${baseUrl}/entities/by-refs${query}`;
const url = `${baseUrl}/entities/by-refs`;
const response = await this.fetchApi.fetch(url, {
headers: {
@@ -212,7 +211,7 @@ export class CatalogClient implements CatalogApi {
...(options?.token && { Authorization: `Bearer ${options?.token}` }),
},
method: 'POST',
body: JSON.stringify({ entityRefs: request.entityRefs }),
body: JSON.stringify(body),
});
if (!response.ok) {