Skip to content

Commit

Permalink
Merge pull request RoadieHQ#1082 from adrien-saunier-decathlon/main
Browse files Browse the repository at this point in the history
bug/The widget Github insights Environment should handle the absence …
  • Loading branch information
Xantier authored Aug 23, 2023
2 parents 1920156 + 4abae0b commit a81a229
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-berries-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/backstage-plugin-github-insights': patch
---

Fix issue where .environment may be not available
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import { AnyApiRef, githubAuthApiRef } from '@backstage/core-plugin-api';
import { ConfigReader } from '@backstage/core-app-api';
import { rest } from 'msw';
Expand All @@ -31,8 +31,8 @@ import { lightTheme } from '@backstage/theme';
import EnvironmentsCard from '.';
import { EntityProvider } from '@backstage/plugin-catalog-react';
import {
scmIntegrationsApiRef,
ScmIntegrationsApi,
scmIntegrationsApiRef,
} from '@backstage/integration-react';
import { defaultIntegrationsConfig } from '../../../mocks/scmIntegrationsApiMock';

Expand Down Expand Up @@ -99,7 +99,7 @@ describe('EnvironmentsCard', () => {

worker.use(
rest.get(
'https://api.github.com/repos/mcalus3/backstage/releases',
'https://api.github.com/repos/mcalus3/backstage/environments',
(_, res, ctx) => res(ctx.status(304), ctx.json({})),
),
);
Expand All @@ -119,4 +119,38 @@ describe('EnvironmentsCard', () => {
expect(await screen.findAllByText('env1')).toHaveLength(1);
expect(await screen.findAllByText('env2')).toHaveLength(1);
});

it('should handle gracefully if no environment is found', async () => {
worker.restoreHandlers();
worker.use(
rest.get(
'https://api.github.com/repos/mcalus3/backstage/environments',
(_, res, ctx) =>
res(
ctx.status(404),
ctx.json({
message: 'Not Found',
documentation_url:
'https://docs.github.com/rest/deployments/environments#list-environments',
}),
),
),
);

render(
wrapInTestApp(
<TestApiProvider apis={apis}>
<ThemeProvider theme={lightTheme}>
<EntityProvider entity={entityMock}>
<EnvironmentsCard />
</EntityProvider>
</ThemeProvider>
</TestApiProvider>,
),
);

await waitFor(() => {
expect(screen.queryByText('Environments')).not.toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const EnvironmentsCard = () => {
);
}

return value.environments.length && owner && repo ? (
return value?.environments?.length && owner && repo ? (
<InfoCard
title="Environments"
deepLink={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const useRequest = (
result = requestState[requestName];
}
}

return result;
}, [baseUrl, requestName]);

Expand Down

0 comments on commit a81a229

Please sign in to comment.