Fleshing out more tests with API failures
Signed-off-by: Karan Shah <karan.shah@simplybusiness.co.uk>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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(
|
||||
<TestApiProvider apis={[[airbrakeApiRef, new MockAirbrakeApi()]]}>
|
||||
<EntityAirbrakeWidget entity={createEntity()} />
|
||||
</TestApiProvider>,
|
||||
);
|
||||
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(
|
||||
<TestApiProvider
|
||||
apis={[[airbrakeApiRef, new ProductionAirbrakeApi('fakeApiKey')]]}
|
||||
>
|
||||
<EntityAirbrakeWidget entity={createEntity(123)} />
|
||||
</TestApiProvider>,
|
||||
);
|
||||
|
||||
await expect(
|
||||
table.findByText('*there was an issue communicating with Airbrake*'),
|
||||
).resolves.toBeInTheDocument();
|
||||
expect(scope.isDone()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user