diff --git a/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/request/schemas/v1.ts b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/request/schemas/v1.ts index 42d238b5a9d59..a03370a55e8d7 100644 --- a/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/request/schemas/v1.ts +++ b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/request/schemas/v1.ts @@ -10,6 +10,7 @@ import { validateStartDateV1, validateEndDateV1, createValidateRecurrenceByV1, + validateRecurrenceByWeekdayV1, } from '../../validation'; export const rRuleRequestSchema = schema.object({ @@ -40,20 +41,9 @@ export const rRuleRequestSchema = schema.object({ }) ), byweekday: schema.maybe( - schema.arrayOf( - schema.oneOf([ - schema.literal('MO'), - schema.literal('TU'), - schema.literal('WE'), - schema.literal('TH'), - schema.literal('FR'), - schema.literal('SA'), - schema.literal('SU'), - ]), - { - validate: createValidateRecurrenceByV1('byweekday'), - } - ) + schema.arrayOf(schema.string(), { + validate: validateRecurrenceByWeekdayV1, + }) ), bymonthday: schema.maybe( schema.arrayOf(schema.number({ min: 1, max: 31 }), { diff --git a/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/index.ts b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/index.ts index fc98963e03189..b52c37cb76b47 100644 --- a/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/index.ts +++ b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/index.ts @@ -8,7 +8,9 @@ export { validateStartDate } from './validate_start_date/latest'; export { validateEndDate } from './validate_end_date/latest'; export { createValidateRecurrenceBy } from './validate_recurrence_by/latest'; +export { validateRecurrenceByWeekday } from './validate_recurrence_by_weekday/latest'; export { validateStartDate as validateStartDateV1 } from './validate_start_date/v1'; export { validateEndDate as validateEndDateV1 } from './validate_end_date/v1'; export { createValidateRecurrenceBy as createValidateRecurrenceByV1 } from './validate_recurrence_by/v1'; +export { validateRecurrenceByWeekday as validateRecurrenceByWeekdayV1 } from './validate_recurrence_by_weekday/v1'; diff --git a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_start_date.ts b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/latest.ts similarity index 60% rename from x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_start_date.ts rename to x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/latest.ts index 3cbc0da0af1b5..25300c97a6d2e 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_start_date.ts +++ b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/latest.ts @@ -5,8 +5,4 @@ * 2.0. */ -export const validateStartDate = (date: string) => { - const parsedValue = Date.parse(date); - if (isNaN(parsedValue)) return `Invalid date: ${date}`; - return; -}; +export * from './v1'; diff --git a/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/v1.test.ts b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/v1.test.ts new file mode 100644 index 0000000000000..975b55fd07227 --- /dev/null +++ b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/v1.test.ts @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { validateRecurrenceByWeekday } from './v1'; + +describe('validateRecurrenceByWeekday', () => { + it('validates empty array', () => { + expect(validateRecurrenceByWeekday([])).toEqual('rRule byweekday cannot be empty'); + }); + + it('validates properly formed byweekday strings', () => { + const weekdays = ['+1MO', '+2TU', '+3WE', '+4TH', '-4FR', '-3SA', '-2SU', '-1MO']; + + expect(validateRecurrenceByWeekday(weekdays)).toBeUndefined(); + }); + + it('validates improperly formed byweekday strings', () => { + expect(validateRecurrenceByWeekday(['+1MO', 'FOO', '+3WE', 'BAR', '-4FR'])).toEqual( + 'invalid byweekday values in rRule byweekday: FOO,BAR' + ); + }); + + it('validates byweekday strings without recurrence', () => { + expect(validateRecurrenceByWeekday(['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'])).toBeUndefined(); + }); +}); diff --git a/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/v1.ts b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/v1.ts new file mode 100644 index 0000000000000..daf1f38c78198 --- /dev/null +++ b/x-pack/platform/plugins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/v1.ts @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export const validateRecurrenceByWeekday = (array: string[]) => { + if (array.length === 0) { + return 'rRule byweekday cannot be empty'; + } + + const byWeekDayRegex = new RegExp('^(((\\+|-)[1-4])?(MO|TU|WE|TH|FR|SA|SU))$'); + const invalidDays: string[] = []; + + array.forEach((day) => { + if (!byWeekDayRegex.test(day)) { + invalidDays.push(day); + } + }); + + if (invalidDays.length > 0) { + return `invalid byweekday values in rRule byweekday: ${invalidDays.join(',')}`; + } +}; diff --git a/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/create/create_maintenance_window.test.ts b/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/create/create_maintenance_window.test.ts index 57f7153bd0231..c1091f58abe13 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/create/create_maintenance_window.test.ts +++ b/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/create/create_maintenance_window.test.ts @@ -6,21 +6,24 @@ */ import moment from 'moment-timezone'; -import { createMaintenanceWindow } from './create_maintenance_window'; -import { CreateMaintenanceWindowParams } from './types'; + import { savedObjectsClientMock, loggingSystemMock, uiSettingsServiceMock, } from '@kbn/core/server/mocks'; import { SavedObject } from '@kbn/core/server'; +import { FilterStateStore } from '@kbn/es-query'; +import { Frequency } from '@kbn/rrule'; + import { MaintenanceWindowClientContext, MAINTENANCE_WINDOW_SAVED_OBJECT_TYPE, } from '../../../../../common'; import { getMockMaintenanceWindow } from '../../../../data/maintenance_window/test_helpers'; import type { MaintenanceWindow } from '../../types'; -import { FilterStateStore } from '@kbn/es-query'; +import { createMaintenanceWindow } from './create_maintenance_window'; +import { CreateMaintenanceWindowParams } from './types'; const savedObjectsClient = savedObjectsClientMock.create(); const uiSettings = uiSettingsServiceMock.createClient(); @@ -57,6 +60,13 @@ describe('MaintenanceWindowClient - create', () => { const mockMaintenanceWindow = getMockMaintenanceWindow({ expirationDate: moment(new Date()).tz('UTC').add(1, 'year').toISOString(), + rRule: { + tzid: 'UTC', + dtstart: '2023-02-26T00:00:00.000Z', + freq: Frequency.WEEKLY, + byweekday: ['-4MO', 'TU'], + count: 2, + }, }); savedObjectsClient.create.mockResolvedValueOnce({ diff --git a/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/create/schemas/create_maintenance_window_params_schema.ts b/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/create/schemas/create_maintenance_window_params_schema.ts index b55a4871d0b6f..8a00dbc704862 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/create/schemas/create_maintenance_window_params_schema.ts +++ b/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/create/schemas/create_maintenance_window_params_schema.ts @@ -6,8 +6,9 @@ */ import { schema } from '@kbn/config-schema'; +import { rRuleRequestSchema } from '../../../../../../common/routes/r_rule'; import { maintenanceWindowCategoryIdsSchema } from '../../../schemas'; -import { rRuleRequestSchema } from '../../../../r_rule/schemas'; + import { alertsFilterQuerySchema } from '../../../../alerts_filter_query/schemas'; export const createMaintenanceWindowParamsSchema = schema.object({ diff --git a/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/update/schemas/update_maintenance_window_params_schema.ts b/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/update/schemas/update_maintenance_window_params_schema.ts index 1aca8ab24fcda..679571c6f324b 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/update/schemas/update_maintenance_window_params_schema.ts +++ b/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/update/schemas/update_maintenance_window_params_schema.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { maintenanceWindowCategoryIdsSchema } from '../../../schemas'; -import { rRuleRequestSchema } from '../../../../r_rule/schemas'; +import { rRuleRequestSchema } from '../../../../../../common/routes/r_rule'; import { alertsFilterQuerySchema } from '../../../../alerts_filter_query/schemas'; export const updateMaintenanceWindowParamsSchema = schema.object({ diff --git a/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/update/update_maintenance_window.test.ts b/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/update/update_maintenance_window.test.ts index e377fb3209d63..586a5a0e882ed 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/update/update_maintenance_window.test.ts +++ b/x-pack/platform/plugins/shared/alerting/server/application/maintenance_window/methods/update/update_maintenance_window.test.ts @@ -38,6 +38,7 @@ const updatedAttributes = { dtstart: '2023-03-26T00:00:00.000Z', freq: Frequency.WEEKLY, count: 2, + byweekday: ['-1MO', 'WE'], }, }; @@ -110,8 +111,8 @@ describe('MaintenanceWindowClient - update', () => { { ...updatedAttributes, events: [ - { gte: '2023-03-26T00:00:00.000Z', lte: '2023-03-26T02:00:00.000Z' }, - { gte: '2023-04-01T23:00:00.000Z', lte: '2023-04-02T01:00:00.000Z' }, // Daylight savings + { gte: '2023-03-26T23:00:00.000Z', lte: '2023-03-27T01:00:00.000Z' }, + { gte: '2023-03-28T23:00:00.000Z', lte: '2023-03-29T01:00:00.000Z' }, // Daylight savings ], expirationDate: moment(new Date(secondTimestamp)).tz('UTC').add(1, 'year').toISOString(), createdAt: '2023-02-26T00:00:00.000Z', diff --git a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/schemas/index.ts b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/schemas/index.ts index 12e793318558d..9ff41d1fcad0d 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/schemas/index.ts +++ b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/schemas/index.ts @@ -6,4 +6,3 @@ */ export { rRuleSchema } from './r_rule_schema'; -export { rRuleRequestSchema } from './r_rule_request_schema'; diff --git a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/schemas/r_rule_request_schema.ts b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/schemas/r_rule_request_schema.ts deleted file mode 100644 index 978d000b137ab..0000000000000 --- a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/schemas/r_rule_request_schema.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import { schema } from '@kbn/config-schema'; -import { validateStartDate, validateEndDate, createValidateRecurrenceBy } from '../validation'; - -export const rRuleRequestSchema = schema.object({ - dtstart: schema.string({ validate: validateStartDate }), - tzid: schema.string(), - freq: schema.maybe( - schema.oneOf([schema.literal(0), schema.literal(1), schema.literal(2), schema.literal(3)]) - ), - interval: schema.maybe( - schema.number({ - validate: (interval: number) => { - if (!Number.isInteger(interval)) { - return 'rRule interval must be an integer greater than 0'; - } - }, - min: 1, - }) - ), - until: schema.maybe(schema.string({ validate: validateEndDate })), - count: schema.maybe( - schema.number({ - validate: (count: number) => { - if (!Number.isInteger(count)) { - return 'rRule count must be an integer greater than 0'; - } - }, - min: 1, - }) - ), - byweekday: schema.maybe( - schema.arrayOf( - schema.oneOf([ - schema.literal('MO'), - schema.literal('TU'), - schema.literal('WE'), - schema.literal('TH'), - schema.literal('FR'), - schema.literal('SA'), - schema.literal('SU'), - ]), - { - validate: createValidateRecurrenceBy('byweekday'), - } - ) - ), - bymonthday: schema.maybe( - schema.arrayOf(schema.number({ min: 1, max: 31 }), { - validate: createValidateRecurrenceBy('bymonthday'), - }) - ), - bymonth: schema.maybe( - schema.arrayOf(schema.number({ min: 1, max: 12 }), { - validate: createValidateRecurrenceBy('bymonth'), - }) - ), -}); diff --git a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/types/index.ts b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/types/index.ts index 080598aca88e3..6f5fe18d0539c 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/types/index.ts +++ b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/types/index.ts @@ -6,4 +6,3 @@ */ export type { RRule } from './r_rule'; -export type { RRuleRequest } from './r_rule_request'; diff --git a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/types/r_rule_request.ts b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/types/r_rule_request.ts deleted file mode 100644 index 4f90eae946935..0000000000000 --- a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/types/r_rule_request.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import { TypeOf } from '@kbn/config-schema'; -import { rRuleRequestSchema } from '../schemas/r_rule_request_schema'; - -export type RRuleRequest = TypeOf; diff --git a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/index.ts b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/index.ts deleted file mode 100644 index f48e8d5bf1c9a..0000000000000 --- a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export { validateStartDate } from './validate_start_date'; -export { validateEndDate } from './validate_end_date'; -export { validateRecurrenceBy, createValidateRecurrenceBy } from './validate_recurrence_by'; diff --git a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_end_date.ts b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_end_date.ts deleted file mode 100644 index 895c1aeea4dfb..0000000000000 --- a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_end_date.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export const validateEndDate = (date: string) => { - const parsedValue = Date.parse(date); - if (isNaN(parsedValue)) return `Invalid date: ${date}`; - if (parsedValue <= Date.now()) return `Invalid snooze date as it is in the past: ${date}`; - return; -}; diff --git a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_recurrence_by.ts b/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_recurrence_by.ts deleted file mode 100644 index 0ab609355c680..0000000000000 --- a/x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/validate_recurrence_by.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export const validateRecurrenceBy = (name: string, array: T[]) => { - if (array.length === 0) { - return `rRule ${name} cannot be empty`; - } -}; - -export const createValidateRecurrenceBy = (name: string) => { - return (array: T[]) => validateRecurrenceBy(name, array); -}; diff --git a/x-pack/platform/plugins/shared/alerting/server/application/rule/methods/bulk_edit/schemas/bulk_edit_rules_option_schemas.ts b/x-pack/platform/plugins/shared/alerting/server/application/rule/methods/bulk_edit/schemas/bulk_edit_rules_option_schemas.ts index 1f3456d8ca02b..8fbf1380790a5 100644 --- a/x-pack/platform/plugins/shared/alerting/server/application/rule/methods/bulk_edit/schemas/bulk_edit_rules_option_schemas.ts +++ b/x-pack/platform/plugins/shared/alerting/server/application/rule/methods/bulk_edit/schemas/bulk_edit_rules_option_schemas.ts @@ -5,8 +5,8 @@ * 2.0. */ import { schema } from '@kbn/config-schema'; -import { rRuleRequestSchema } from '../../../../r_rule/schemas'; import { notifyWhenSchema, actionRequestSchema, systemActionRequestSchema } from '../../../schemas'; +import { rRuleRequestSchema } from '../../../../../../common/routes/r_rule'; import { validateDuration } from '../../../validation'; import { validateSnoozeSchedule } from '../validation'; diff --git a/x-pack/platform/plugins/shared/alerting/server/saved_objects/schemas/raw_maintenance_window/v1.ts b/x-pack/platform/plugins/shared/alerting/server/saved_objects/schemas/raw_maintenance_window/v1.ts index 66c5c432bb370..90cee9c9fec9a 100644 --- a/x-pack/platform/plugins/shared/alerting/server/saved_objects/schemas/raw_maintenance_window/v1.ts +++ b/x-pack/platform/plugins/shared/alerting/server/saved_objects/schemas/raw_maintenance_window/v1.ts @@ -27,7 +27,7 @@ export const alertsFilterQuerySchema = schema.object({ dsl: schema.maybe(schema.string()), }); -const rRuleSchema = schema.object({ +export const rRuleSchema = schema.object({ dtstart: schema.string(), tzid: schema.string(), freq: schema.maybe( @@ -55,15 +55,17 @@ const rRuleSchema = schema.object({ schema.literal('SU'), ]) ), - byweekday: schema.maybe(schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))), - bymonth: schema.maybe(schema.number()), - bysetpos: schema.maybe(schema.number()), - bymonthday: schema.maybe(schema.number()), - byyearday: schema.maybe(schema.number()), - byweekno: schema.maybe(schema.number()), - byhour: schema.maybe(schema.number()), - byminute: schema.maybe(schema.number()), - bysecond: schema.maybe(schema.number()), + byweekday: schema.maybe( + schema.nullable(schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))) + ), + bymonth: schema.maybe(schema.nullable(schema.arrayOf(schema.number()))), + bysetpos: schema.maybe(schema.nullable(schema.arrayOf(schema.number()))), + bymonthday: schema.maybe(schema.nullable(schema.arrayOf(schema.number()))), + byyearday: schema.maybe(schema.nullable(schema.arrayOf(schema.number()))), + byweekno: schema.maybe(schema.nullable(schema.arrayOf(schema.number()))), + byhour: schema.maybe(schema.nullable(schema.arrayOf(schema.number()))), + byminute: schema.maybe(schema.nullable(schema.arrayOf(schema.number()))), + bysecond: schema.maybe(schema.nullable(schema.arrayOf(schema.number()))), }); const rawMaintenanceWindowEventsSchema = schema.object({ diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/maintenance_window/create_maintenance_window.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/maintenance_window/create_maintenance_window.ts index 1b6f32715c9ef..fc2fdf11d8ea9 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/maintenance_window/create_maintenance_window.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/maintenance_window/create_maintenance_window.ts @@ -110,6 +110,71 @@ export default function createMaintenanceWindowTests({ getService }: FtrProvider }); } + describe('rRuleSchema validation', () => { + it('should create maintenance window with byweekday', async () => { + const rrule = { + dtstart: new Date().toISOString(), + tzid: 'UTC', + byweekday: ['+1MO', 'TH'], + }; + + const response = await supertest + .post(`${getUrlPrefix('space1')}/internal/alerting/rules/maintenance_window`) + .set('kbn-xsrf', 'foo') + .send({ + ...createParams, + r_rule: rrule, + }) + .expect(200); + + objectRemover.add('space1', response.body.id, 'rules/maintenance_window', 'alerting', true); + + expect(response.body.r_rule.byweekday).to.eql(rrule.byweekday); + }); + + it('should create maintenance window with bymonth', async () => { + const rrule = { + dtstart: new Date().toISOString(), + tzid: 'UTC', + bymonth: [9, 4], + }; + + const response = await supertest + .post(`${getUrlPrefix('space1')}/internal/alerting/rules/maintenance_window`) + .set('kbn-xsrf', 'foo') + .send({ + ...createParams, + r_rule: rrule, + }) + .expect(200); + + objectRemover.add('space1', response.body.id, 'rules/maintenance_window', 'alerting', true); + + expect(response.body.r_rule.bymonth).to.eql(rrule.bymonth); + }); + + it('should create maintenance window with bymonthday', async () => { + const rrule = { + dtstart: new Date().toISOString(), + tzid: 'UTC', + bymonthday: [1, 30], + }; + + const response = await supertest + .post(`${getUrlPrefix('space1')}/internal/alerting/rules/maintenance_window`) + .set('kbn-xsrf', 'foo') + .send({ + ...createParams, + r_rule: rrule, + }) + .expect(200); + + objectRemover.add('space1', response.body.id, 'rules/maintenance_window', 'alerting', true); + + expect(response.body.r_rule.bymonthday).to.eql(rrule.bymonthday); + }); + }); + it('should create maintenance window with category ids', async () => { const response = await supertest .post(`${getUrlPrefix('space1')}/internal/alerting/rules/maintenance_window`)