From 82641a96d40fafadfa5ab61a8e11605756ffa653 Mon Sep 17 00:00:00 2001 From: Karan Shah Date: Mon, 7 Feb 2022 16:25:49 +0000 Subject: [PATCH] Fleshing out more tests with API failures Signed-off-by: Karan Shah --- .../airbrake/src/api/production-api.test.ts | 2 +- .../EntityAirbrakeWidget.test.tsx | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/plugins/airbrake/src/api/production-api.test.ts b/plugins/airbrake/src/api/production-api.test.ts index 89b7908f9a..3753cab592 100644 --- a/plugins/airbrake/src/api/production-api.test.ts +++ b/plugins/airbrake/src/api/production-api.test.ts @@ -40,7 +40,7 @@ describe('The production Airbrake API', () => { it('throws if fetching groups was unsuccessful', async () => { const scope = nock('https://api.airbrake.io') .get('/api/v4/projects/123456/groups?key=fakeApiKey') - .reply(500, mockGroupsData); + .reply(500); expect(scope.isDone()).toBe(false); await expect(productionApi.fetchGroups('123456')).rejects.toThrow(); diff --git a/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx b/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx index 5baabe92f6..5d3787b875 100644 --- a/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx +++ b/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx @@ -19,7 +19,12 @@ import { EntityAirbrakeWidget } from './EntityAirbrakeWidget'; import exampleData from '../../api/mock/airbrake-groups-api-mock.json'; import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; import { createEntity } from '../../api/mock/mock-entity'; -import { airbrakeApiRef, MockAirbrakeApi } from '../../api'; +import { + airbrakeApiRef, + MockAirbrakeApi, + ProductionAirbrakeApi, +} from '../../api'; +import nock from 'nock'; describe('EntityAirbrakeContent', () => { it('renders all errors sent from Airbrake', async () => { @@ -36,15 +41,34 @@ describe('EntityAirbrakeContent', () => { } }); - it('states that the annotation is missing if no annotation is provided', async () => { + it('states that the annotation is missing if no project ID annotation is provided', async () => { const table = await renderInTestApp( , ); - expect(exampleData.groups.length).toBeGreaterThan(0); await expect( table.findByText('Missing Annotation'), ).resolves.toBeInTheDocument(); }); + + it('states that an error occurred if API call fails', async () => { + const scope = nock('https://api.airbrake.io') + .get('/api/v4/projects/123/groups?key=fakeApiKey') + .reply(500); + expect(scope.isDone()).toBe(false); + + const table = await renderInTestApp( + + + , + ); + + await expect( + table.findByText('*there was an issue communicating with Airbrake*'), + ).resolves.toBeInTheDocument(); + expect(scope.isDone()).toBe(true); + }); });