test warning for incorrect routing key annotation
This adds a test asserting that the correct component is rendered when the entity `splunk.com/on-call-routing-key` does not properly map to any associated teams. Signed-off-by: Mike Ball <mikedball@gmail.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
import {
|
||||
EscalationPolicyInfo,
|
||||
Incident,
|
||||
RoutingKey,
|
||||
Team,
|
||||
User,
|
||||
} from '../components/types';
|
||||
@@ -88,6 +89,18 @@ export const MOCK_TEAM: Team = {
|
||||
isDefaultTeam: false,
|
||||
};
|
||||
|
||||
export const MOCK_ROUTING_KEY: RoutingKey = {
|
||||
routingKey: 'test-routing-key',
|
||||
targets: [
|
||||
{
|
||||
policyName: 'some policy',
|
||||
policySlug: MOCK_TEAM.slug || '',
|
||||
_teamUrl: `/api-public/v1/team/${MOCK_TEAM.slug}`,
|
||||
},
|
||||
],
|
||||
isDefault: false,
|
||||
};
|
||||
|
||||
export const MOCK_TEAM_NO_INCIDENTS: Team = {
|
||||
...MOCK_TEAM,
|
||||
name: 'test-noincidents',
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
MOCKED_ON_CALL,
|
||||
MOCKED_USER,
|
||||
MOCK_INCIDENT,
|
||||
MOCK_ROUTING_KEY,
|
||||
MOCK_TEAM,
|
||||
MOCK_TEAM_NO_INCIDENTS,
|
||||
} from '../api/mocks';
|
||||
@@ -45,6 +46,7 @@ const mockSplunkOnCallApi: Partial<SplunkOnCallClient> = {
|
||||
getIncidents: async () => [MOCK_INCIDENT],
|
||||
getOnCallUsers: async () => MOCKED_ON_CALL,
|
||||
getTeams: async () => [MOCK_TEAM],
|
||||
getRoutingKeys: async () => [MOCK_ROUTING_KEY],
|
||||
getEscalationPolicies: async () => ESCALATION_POLICIES,
|
||||
};
|
||||
|
||||
@@ -71,6 +73,17 @@ const mockEntity = {
|
||||
},
|
||||
} as Entity;
|
||||
|
||||
const mockEntityWithRoutingKeyAnnotation = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'splunkoncall-test',
|
||||
annotations: {
|
||||
'splunk.com/on-call-routing-key': MOCK_ROUTING_KEY.routingKey,
|
||||
},
|
||||
},
|
||||
} as Entity;
|
||||
|
||||
const mockEntityNoIncidents = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
@@ -176,6 +189,34 @@ describe('SplunkOnCallCard', () => {
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('handles warning for incorrect routing key annotation', async () => {
|
||||
mockSplunkOnCallApi.getUsers = jest
|
||||
.fn()
|
||||
.mockImplementationOnce(async () => [MOCKED_USER]);
|
||||
mockSplunkOnCallApi.getRoutingKeys = jest
|
||||
.fn()
|
||||
.mockImplementationOnce(async () => [MOCK_ROUTING_KEY]);
|
||||
mockSplunkOnCallApi.getTeams = jest
|
||||
.fn()
|
||||
.mockImplementationOnce(async () => []);
|
||||
|
||||
const { getByText, queryByTestId } = render(
|
||||
wrapInTestApp(
|
||||
<ApiProvider apis={apis}>
|
||||
<EntityProvider entity={mockEntityWithRoutingKeyAnnotation}>
|
||||
<EntitySplunkOnCallCard />
|
||||
</EntityProvider>
|
||||
</ApiProvider>,
|
||||
),
|
||||
);
|
||||
await waitFor(() => !queryByTestId('progress'));
|
||||
expect(
|
||||
getByText(
|
||||
`Splunk On-Call API returned no record of teams associated with the "${MOCK_ROUTING_KEY.routingKey}" routing key`,
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('opens the dialog when trigger button is clicked', async () => {
|
||||
mockSplunkOnCallApi.getUsers = jest
|
||||
.fn()
|
||||
|
||||
@@ -161,12 +161,14 @@ export const EntitySplunkOnCallCard = () => {
|
||||
key => key.routingKey === routingKeyAnnotation,
|
||||
);
|
||||
foundTeams = foundRoutingKey
|
||||
? foundRoutingKey.targets.map(target => {
|
||||
const teamUrlParts = target._teamUrl.split('/');
|
||||
const teamSlug = teamUrlParts[teamUrlParts.length - 1];
|
||||
? foundRoutingKey.targets
|
||||
.map(target => {
|
||||
const teamUrlParts = target._teamUrl.split('/');
|
||||
const teamSlug = teamUrlParts[teamUrlParts.length - 1];
|
||||
|
||||
return teams.find(teamValue => teamValue.slug === teamSlug);
|
||||
})
|
||||
return teams.find(teamValue => teamValue.slug === teamSlug);
|
||||
})
|
||||
.filter(team => team !== undefined)
|
||||
: [];
|
||||
}
|
||||
|
||||
@@ -197,6 +199,15 @@ export const EntitySplunkOnCallCard = () => {
|
||||
return <Progress />;
|
||||
}
|
||||
|
||||
if (!usersAndTeams?.foundTeams || !usersAndTeams?.foundTeams.length) {
|
||||
return (
|
||||
<InvalidAnnotation
|
||||
teamName={teamAnnotation}
|
||||
routingKey={routingKeyAnnotation}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const Content = ({
|
||||
team,
|
||||
usersHashMap,
|
||||
@@ -237,15 +248,6 @@ export const EntitySplunkOnCallCard = () => {
|
||||
|
||||
const teams = usersAndTeams?.foundTeams || [];
|
||||
|
||||
if (!teams.length) {
|
||||
return (
|
||||
<InvalidAnnotation
|
||||
teamName={teamAnnotation}
|
||||
routingKey={routingKeyAnnotation}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{teams.map((team, i) => (
|
||||
|
||||
Reference in New Issue
Block a user