Don't crash if the entities response doesn't include the entities name and kind

Signed-off-by: Dominik Henneke <dominik.henneke@sda-se.com>
This commit is contained in:
Dominik Henneke
2021-06-28 18:16:26 +02:00
parent 256c9c9b29
commit ca080cab8b
3 changed files with 35 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/catalog-client': patch
---
Don't crash if the entities response doesn't include the entities name and kind
@@ -151,6 +151,26 @@ describe('CatalogClient', () => {
expect(response.items).toEqual([]);
});
it('handles field filtered entities', async () => {
server.use(
rest.get(`${mockBaseUrl}/entities`, (_req, res, ctx) => {
return res(ctx.json([{ apiVersion: '1' }, { apiVersion: '2' }]));
}),
);
const response = await client.getEntities(
{
fields: ['apiVersion'],
},
{ token },
);
expect(response.items).toEqual([
{ apiVersion: '1' },
{ apiVersion: '2' },
]);
});
});
describe('getLocationById', () => {
@@ -92,6 +92,16 @@ export class CatalogClient implements CatalogApi {
);
const refCompare = (a: Entity, b: Entity) => {
// in case field filtering is used, these fields might not be part of the response
if (
a.metadata?.name === undefined ||
a.metadata?.kind === undefined ||
b.metadata?.name === undefined ||
b.metadata?.kind === undefined
) {
return 0;
}
const aRef = stringifyEntityRef(a);
const bRef = stringifyEntityRef(b);
if (aRef < bRef) {