Merge pull request #6246 from SDA-SE/feat/catalog-client-crash

Don't crash if the entities response doesn't include the entities name and kind
This commit is contained in:
Fredrik Adelöw
2021-06-28 19:57:53 +02:00
committed by GitHub
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.kind === undefined ||
b.metadata?.name === undefined ||
b.kind === undefined
) {
return 0;
}
const aRef = stringifyEntityRef(a);
const bRef = stringifyEntityRef(b);
if (aRef < bRef) {