Skip to content

Commit

Permalink
fix(alerts): Copy integration id when duplicating alert (#45162)
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper authored Feb 28, 2023
1 parent 82133f7 commit 1702653
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
67 changes: 67 additions & 0 deletions static/app/views/alerts/rules/metric/duplicate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ describe('Incident Rules Duplicate', function () {
type: 'email',
integrationId: null,
},
{
allowedTargetTypes: ['specific'],
integrationName: null,
type: 'slack',
integrationId: 1,
},
],
});
MockApiClient.addMockResponse({
Expand Down Expand Up @@ -105,4 +111,65 @@ describe('Incident Rules Duplicate', function () {
// Has the updated alert rule name
expect(screen.getByTestId('alert-name')).toHaveValue(`${rule.name} copy`);
});

it('duplicates slack actions', function () {
const rule = TestStubs.MetricRule();
rule.triggers[0].actions.push({
id: '13',
alertRuleTriggerId: '12',
type: 'slack',
targetType: 'specific',
targetIdentifier: '#feed-ecosystem',
inputChannelId: 'ABC123',
integrationId: 1,
sentryAppId: null,
desc: 'Send a Slack notification to #feed-ecosystem',
});

const {organization, project, router} = initializeOrg({
organization: {
access: ['alerts:write'],
},
router: {
params: {},
location: {
query: {
createFromDuplicate: true,
duplicateRuleId: `${rule.id}`,
},
},
},
project: rule.projects[0],
projects: rule.projects,
});

const req = MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/alert-rules/${rule.id}/`,
body: rule,
});

render(
<MetricRulesDuplicate
params={{}}
route={{}}
routeParams={router.params}
router={router}
routes={router.routes}
location={router.location}
organization={organization}
project={project}
userTeamIds={[]}
/>
);

// Duplicated alert has been called
expect(req).toHaveBeenCalled();

// Still has a selected slack action
expect(screen.getByText('Slack')).toBeInTheDocument();
expect(screen.getByPlaceholderText('optional: channel ID or user ID')).toHaveValue(
'ABC123'
);
expect(screen.getByText(/Enter a channel or user ID/)).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion static/app/views/alerts/rules/metric/duplicate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MetricRulesDuplicate extends AsyncView<Props, State> {
...pick(trigger, DuplicateTriggerFields),
actions: trigger.actions.map(action => ({
inputChannelId: null,
integrationId: undefined,
integrationId: action.integrationId ?? undefined,
options: null,
sentryAppId: undefined,
unsavedId: uniqueId(),
Expand Down

0 comments on commit 1702653

Please sign in to comment.