From 6af18f7e2756fa53fdf51e6a203c2d62a95b4b4a Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 11 Jun 2020 23:23:52 +0200 Subject: [PATCH] feat(catalog/msw): fixed merge conflicts and fixed some comments --- plugins/catalog/src/api/CatalogClient.test.ts | 67 +++++++++++++++---- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/plugins/catalog/src/api/CatalogClient.test.ts b/plugins/catalog/src/api/CatalogClient.test.ts index b8ba76b95e..719513529c 100644 --- a/plugins/catalog/src/api/CatalogClient.test.ts +++ b/plugins/catalog/src/api/CatalogClient.test.ts @@ -17,6 +17,7 @@ import { rest } from 'msw'; import { setupServer } from 'msw/node'; import { CatalogClient } from './CatalogClient'; +import { Entity } from '@backstage/catalog-model'; const server = setupServer(); describe('CatalogClient', () => { @@ -36,21 +37,61 @@ describe('CatalogClient', () => { basePath: mockBasePath, }); }); - it('builds entity search filters properly', async () => { - expect.assertions(2); - server.use( - rest.get(`${mockApiOrigin}${mockBasePath}/entities`, (req, res, ctx) => { - expect(req.url.searchParams.toString()).toBe('a=1&b=2&b=3&%C3%B6=%3D'); - return res(ctx.json([])); - }), - ); - const entities = await client.getEntities({ - a: '1', - b: ['2', '3'], - ö: '=', + describe('getEntiies', () => { + const defaultResponse: Entity[] = [ + { + apiVersion: '1', + kind: 'Component', + metadata: { + name: 'Test1', + namespace: 'test1', + }, + }, + { + apiVersion: '1', + kind: 'Component', + metadata: { + name: 'Test2', + namespace: 'test1', + }, + }, + ]; + + beforeEach(() => { + server.use( + rest.get(`${mockApiOrigin}${mockBasePath}/entities`, (_, res, ctx) => { + return res(ctx.json(defaultResponse)); + }), + ); }); - expect(entities).toEqual([]); + it('should entities from correct endpoint', async () => { + const entities = await client.getEntities(); + expect(entities).toEqual(defaultResponse); + }); + + it('builds entity search filters properly', async () => { + expect.assertions(2); + server.use( + rest.get( + `${mockApiOrigin}${mockBasePath}/entities`, + (req, res, ctx) => { + expect(req.url.searchParams.toString()).toBe( + 'a=1&b=2&b=3&%C3%B6=%3D', + ); + return res(ctx.json([])); + }, + ), + ); + + const entities = await client.getEntities({ + a: '1', + b: ['2', '3'], + ö: '=', + }); + + expect(entities).toEqual([]); + }); }); });