From ac6cff672e9dd1e8194a342610e77f4a2d3eeec1 Mon Sep 17 00:00:00 2001 From: NIKUNJ LALITKUMAR HUDKA Date: Mon, 22 Apr 2024 22:23:01 -0300 Subject: [PATCH] testcase updated for new promise getter in api Signed-off-by: NIKUNJ LALITKUMAR HUDKA --- .../DefaultEntityPresentationApi.test.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.test.ts b/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.test.ts index 42ff777cbd..475bfe1660 100644 --- a/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.test.ts +++ b/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.test.ts @@ -35,6 +35,7 @@ describe('DefaultEntityPresentationApi', () => { Icon: expect.anything(), }, update$: undefined, + promise: new Promise((resolve, reject) => resolve({})), }); expect( @@ -48,6 +49,7 @@ describe('DefaultEntityPresentationApi', () => { Icon: expect.anything(), }, update$: undefined, + promise: new Promise((resolve, reject) => resolve({})), }); expect( @@ -63,6 +65,7 @@ describe('DefaultEntityPresentationApi', () => { Icon: expect.anything(), }, update$: undefined, + promise: new Promise((resolve, reject) => resolve({})), }); const entity: Entity = { @@ -85,6 +88,7 @@ describe('DefaultEntityPresentationApi', () => { Icon: expect.anything(), }, update$: undefined, + promise: new Promise((resolve, reject) => resolve({})), }); }); @@ -150,6 +154,47 @@ describe('DefaultEntityPresentationApi', () => { }), ); }); + + it('returns the correct snapshots via promise', async () => { + const catalogApi = { + getEntitiesByRefs: jest.fn(), + }; + const api = DefaultEntityPresentationApi.create({ + catalogApi: catalogApi as Partial as any, + }); + + catalogApi.getEntitiesByRefs.mockResolvedValueOnce({ + items: [ + { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { + name: 'test', + namespace: 'default', + etag: 'something', + }, + spec: { + type: 'service', + }, + }, + ], + }); + + const entityRef = 'component:default/test'; + const entitySnapshot = { + entityRef: entityRef, + primaryTitle: 'test', + secondaryTitle: 'component:default/test | service', + Icon: expect.anything(), + }; + + const promise = api.forEntity(entityRef).promise; + + const snapshots = await promise; + + expect(snapshots.length).toEqual(1); // Only one snapshot expected + expect(snapshots[0]).toEqual(entitySnapshot); // Snapshot should match the simulated one + }); }); async function consumePresentation(