diff --git a/plugins/splunk-on-call/src/api/mocks.ts b/plugins/splunk-on-call/src/api/mocks.ts index d5335bfef4..8db06fb9d3 100644 --- a/plugins/splunk-on-call/src/api/mocks.ts +++ b/plugins/splunk-on-call/src/api/mocks.ts @@ -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', diff --git a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx index da2cfbc2a3..8b58af8e46 100644 --- a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx +++ b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx @@ -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 = { 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( + + + + + , + ), + ); + 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() diff --git a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.tsx b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.tsx index 559f7c551e..db479f9459 100644 --- a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.tsx +++ b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.tsx @@ -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 ; } + if (!usersAndTeams?.foundTeams || !usersAndTeams?.foundTeams.length) { + return ( + + ); + } + const Content = ({ team, usersHashMap, @@ -237,15 +248,6 @@ export const EntitySplunkOnCallCard = () => { const teams = usersAndTeams?.foundTeams || []; - if (!teams.length) { - return ( - - ); - } - return ( <> {teams.map((team, i) => (