diff --git a/x-pack/test/alerting_api_integration/common/lib/alert_utils.ts b/x-pack/test/alerting_api_integration/common/lib/alert_utils.ts index cff3ed710bf6d..480c4baaab198 100644 --- a/x-pack/test/alerting_api_integration/common/lib/alert_utils.ts +++ b/x-pack/test/alerting_api_integration/common/lib/alert_utils.ts @@ -43,6 +43,15 @@ interface UpdateAlwaysFiringAction { overwrites: Record; } +const SNOOZE_SCHEDULE = { + rRule: { + dtstart: '2021-03-07T00:00:00.000Z', + tzid: 'UTC', + count: 1, + }, + duration: 864000000, +}; + export class AlertUtils { private referenceCounter = 1; private readonly user?: User; @@ -105,7 +114,11 @@ export class AlertUtils { const request = this.supertestWithoutAuth .post(`${getUrlPrefix(this.space.id)}/internal/alerting/rule/${alertId}/_snooze`) .set('kbn-xsrf', 'foo') - .set('content-type', 'application/json'); + .set('content-type', 'application/json') + .send({ + snooze_schedule: SNOOZE_SCHEDULE, + }); + if (this.user) { return request.auth(this.user.username, this.user.password); } @@ -116,7 +129,10 @@ export class AlertUtils { const request = this.supertestWithoutAuth .post(`${getUrlPrefix(this.space.id)}/internal/alerting/rule/${alertId}/_unsnooze`) .set('kbn-xsrf', 'foo') - .set('content-type', 'application/json'); + .set('content-type', 'application/json') + .send({ + schedule_ids: [alertId], + }); if (this.user) { return request.auth(this.user.username, this.user.password); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/index.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/index.ts index ea009fc24bbc6..1a2a69cd95d69 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/index.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/index.ts @@ -44,6 +44,7 @@ export default function alertingTests({ loadTestFile, getService }: FtrProviderC loadTestFile(require.resolve('./health')); loadTestFile(require.resolve('./excluded')); loadTestFile(require.resolve('./snooze')); + loadTestFile(require.resolve('./unsnooze')); loadTestFile(require.resolve('./global_execution_log')); loadTestFile(require.resolve('./get_global_execution_kpi')); loadTestFile(require.resolve('./get_action_error_log')); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/unsnooze.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/unsnooze.ts index 8b6a8aa2c6c45..39b5b720ccda3 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/unsnooze.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/unsnooze.ts @@ -27,7 +27,6 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte const objectRemover = new ObjectRemover(supertest); after(() => objectRemover.removeAll()); - for (const scenario of UserAtSpaceScenarios) { const { user, space } = scenario; const alertUtils = new AlertUtils({ user, space, supertestWithoutAuth }); @@ -98,7 +97,7 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte .set('kbn-xsrf', 'foo') .auth(user.username, user.password) .expect(200); - expect(updatedAlert.snooze_schedule).to.eql(null); + expect(updatedAlert.snooze_schedule).to.eql([]); expect(updatedAlert.mute_all).to.eql(false); // Ensure AAD isn't broken await checkAAD({ @@ -155,7 +154,7 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte .set('kbn-xsrf', 'foo') .auth(user.username, user.password) .expect(200); - expect(updatedAlert.snooze_schedule).to.eql(null); + expect(updatedAlert.snooze_schedule).to.eql([]); expect(updatedAlert.mute_all).to.eql(false); // Ensure AAD isn't broken await checkAAD({ @@ -223,7 +222,7 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte .set('kbn-xsrf', 'foo') .auth(user.username, user.password) .expect(200); - expect(updatedAlert.snooze_schedule).to.eql(null); + expect(updatedAlert.snooze_schedule).to.eql([]); expect(updatedAlert.mute_all).to.eql(false); // Ensure AAD isn't broken await checkAAD({ @@ -291,7 +290,7 @@ export default function createUnsnoozeRuleTests({ getService }: FtrProviderConte .set('kbn-xsrf', 'foo') .auth(user.username, user.password) .expect(200); - expect(updatedAlert.snooze_schedule).to.eql(null); + expect(updatedAlert.snooze_schedule).to.eql([]); expect(updatedAlert.mute_all).to.eql(false); // Ensure AAD isn't broken await checkAAD({ diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/index.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/index.ts index 0adcfe10009ca..fda6c1b9c80b2 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/index.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/index.ts @@ -21,6 +21,7 @@ export default function alertingTests({ loadTestFile, getService }: FtrProviderC loadTestFile(require.resolve('./ephemeral')); loadTestFile(require.resolve('./event_log_alerts')); loadTestFile(require.resolve('./snooze')); + loadTestFile(require.resolve('./unsnooze')); loadTestFile(require.resolve('./bulk_edit')); loadTestFile(require.resolve('./capped_action_type')); loadTestFile(require.resolve('./scheduled_task_id')); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/snooze.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/snooze.ts index 110acf31039ae..a658e461917f4 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/snooze.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/snooze.ts @@ -35,8 +35,7 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext const log = getService('log'); const retry = getService('retry'); - // FLAKY: https://github.com/elastic/kibana/issues/159076 - describe.skip('snooze', () => { + describe('snooze', () => { const objectRemover = new ObjectRemover(supertest); after(() => objectRemover.removeAll()); @@ -354,11 +353,19 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext .expect(200); objectRemover.add(Spaces.space1.id, createdRule.id, 'rule', 'alerting'); - const response = await alertUtils.getSnoozeRequest(createdRule.id).send({ - snooze_schedule: { - ...SNOOZE_SCHEDULE, - duration: 3000, + const dateStart = new Date().toISOString(); + const snooze = { + ...SNOOZE_SCHEDULE, + rRule: { + ...SNOOZE_SCHEDULE.rRule, + // updating the dtstart to the current time because otherwise the snooze might be over already + dtstart: dateStart, }, + duration: 3000, + }; + + const response = await alertUtils.getSnoozeRequest(createdRule.id).send({ + snooze_schedule: snooze, }); expect(response.statusCode).to.eql(204); @@ -369,12 +376,7 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext .get(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rule/${createdRule.id}`) .set('kbn-xsrf', 'foo') .expect(200); - expect(updatedAlert.snooze_schedule).to.eql([ - { - ...SNOOZE_SCHEDULE, - duration: 3000, - }, - ]); + expect(updatedAlert.snooze_schedule).to.eql([snooze]); }); log.info('wait for snoozing to end'); await retry.try(async () => { diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/unsnooze.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/unsnooze.ts index 4c3937d23190c..81e246de3214a 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/unsnooze.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/unsnooze.ts @@ -30,7 +30,7 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext it('should handle unsnooze rule request appropriately', async () => { const { body: createdAction } = await supertest - .post(`${getUrlPrefix(Spaces.space1.id)}}/api/actions/connector`) + .post(`${getUrlPrefix(Spaces.space1.id)}/api/actions/connector`) .set('kbn-xsrf', 'foo') .send({ name: 'MY action', @@ -58,7 +58,7 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext .expect(200); objectRemover.add(Spaces.space1.id, createdAlert.id, 'rule', 'alerting'); - const response = await alertUtils.getSnoozeRequest(createdAlert.id); + const response = await alertUtils.getUnsnoozeRequest(createdAlert.id); expect(response.statusCode).to.eql(204); expect(response.body).to.eql('');