Added working tests, one of which fails because of a bug in the code that needs to be fixed

Signed-off-by: Karan Shah <karan.shah@simplybusiness.co.uk>
This commit is contained in:
Karan Shah
2022-03-02 00:15:26 +00:00
parent c1cb49008b
commit 5d98a4263e
2 changed files with 18 additions and 3 deletions
@@ -20,6 +20,7 @@ import mockGroupsData from './mock/airbrakeGroupsApiMock.json';
import { setupServer } from 'msw/node';
import { setupRequestMockHandlers } from '@backstage/test-utils';
import { localDiscoveryApi } from './mock';
import { NoProjectIdError } from './AirbrakeApi';
describe('The production Airbrake API', () => {
const productionApi = new ProductionAirbrakeApi(localDiscoveryApi);
@@ -53,4 +54,10 @@ describe('The production Airbrake API', () => {
await expect(productionApi.fetchGroups('123456')).rejects.toThrow();
});
it('throws if project ID is empty', async () => {
await expect(productionApi.fetchGroups('')).rejects.toThrowError(
NoProjectIdError,
);
});
});
@@ -23,9 +23,9 @@ import {
setupRequestMockHandlers,
TestApiProvider,
} from '@backstage/test-utils';
import { createEntity } from '../../api';
import {
airbrakeApiRef,
createEntity,
localDiscoveryApi,
MockAirbrakeApi,
ProductionAirbrakeApi,
@@ -52,15 +52,23 @@ describe('EntityAirbrakeContent', () => {
}
});
it('states that the annotation is missing if no project ID annotation is provided', async () => {
it('states that the annotation is missing if no project ID annotation is provided but does not error', async () => {
const mockErrorApi = new MockErrorApi({ collect: true });
const widget = await renderInTestApp(
<TestApiProvider apis={[[airbrakeApiRef, new MockAirbrakeApi()]]}>
<TestApiProvider
apis={[
[airbrakeApiRef, new ProductionAirbrakeApi(localDiscoveryApi)],
[errorApiRef, mockErrorApi],
]}
>
<EntityAirbrakeWidget entity={createEntity()} />
</TestApiProvider>,
);
await expect(
widget.findByText('Missing Annotation'),
).resolves.toBeInTheDocument();
expect(mockErrorApi.getErrors().length).toBe(0);
});
it('states that an error occurred if the API call fails', async () => {