diff --git a/x-pack/legacy/plugins/alerting/server/alerts_client.test.ts b/x-pack/legacy/plugins/alerting/server/alerts_client.test.ts index 95fbe4ceb4c57..fa5d866584fbe 100644 --- a/x-pack/legacy/plugins/alerting/server/alerts_client.test.ts +++ b/x-pack/legacy/plugins/alerting/server/alerts_client.test.ts @@ -170,7 +170,7 @@ describe('create()', () => { "interval": "10s", }, "scheduledTaskId": "task-123", - "updatedAt": null, + "updatedAt": 2019-02-12T21:01:22.479Z, } `); expect(savedObjectsClient.create).toHaveBeenCalledTimes(1); @@ -421,7 +421,7 @@ describe('create()', () => { "interval": "10s", }, "scheduledTaskId": "task-123", - "updatedAt": null, + "updatedAt": 2019-02-12T21:01:22.479Z, } `); expect(savedObjectsClient.bulkGet).toHaveBeenCalledWith([ @@ -510,7 +510,7 @@ describe('create()', () => { "schedule": Object { "interval": 10000, }, - "updatedAt": null, + "updatedAt": 2019-02-12T21:01:22.479Z, } `); expect(savedObjectsClient.create).toHaveBeenCalledTimes(1); @@ -1267,7 +1267,7 @@ describe('get()', () => { "schedule": Object { "interval": "10s", }, - "updatedAt": null, + "updatedAt": 2019-02-12T21:01:22.479Z, } `); expect(savedObjectsClient.get).toHaveBeenCalledTimes(1); @@ -1368,7 +1368,7 @@ describe('find()', () => { "schedule": Object { "interval": "10s", }, - "updatedAt": null, + "updatedAt": 2019-02-12T21:01:22.479Z, }, ], "page": 1, diff --git a/x-pack/legacy/plugins/alerting/server/alerts_client.ts b/x-pack/legacy/plugins/alerting/server/alerts_client.ts index 87b5cfb277f44..a9420db289248 100644 --- a/x-pack/legacy/plugins/alerting/server/alerts_client.ts +++ b/x-pack/legacy/plugins/alerting/server/alerts_client.ts @@ -224,7 +224,7 @@ export class AlertsClient { updateResult.scheduledTaskId && !isEqual(alert.attributes.schedule, updateResult.schedule) ) { - this.taskManager.runNow(updateResult.scheduledTaskId).catch(err => { + this.taskManager.runNow(updateResult.scheduledTaskId).catch((err: Error) => { this.logger.error( `Alert update failed to run its underlying task. TaskManager runNow failed with Error: ${err.message}` ); @@ -462,7 +462,7 @@ export class AlertsClient { // we currently only support the Interval Schedule type // Once we support additional types, this type signature will likely change schedule: rawAlert.schedule as IntervalSchedule, - updatedAt: updatedAt ? new Date(updatedAt) : null, + updatedAt: updatedAt ? new Date(updatedAt) : new Date(rawAlert.createdAt!), createdAt: new Date(rawAlert.createdAt!), actions: rawAlert.actions ? this.injectReferencesIntoActions(rawAlert.actions, references || []) diff --git a/x-pack/legacy/plugins/alerting/server/routes/create.test.ts b/x-pack/legacy/plugins/alerting/server/routes/create.test.ts index 6fe26763d179c..d37d07ad2d1b4 100644 --- a/x-pack/legacy/plugins/alerting/server/routes/create.test.ts +++ b/x-pack/legacy/plugins/alerting/server/routes/create.test.ts @@ -52,7 +52,7 @@ test('creates an alert with proper parameters', async () => { }; const createdAt = new Date(); - const updatedAt = null; + const updatedAt = new Date(); alertsClient.create.mockResolvedValueOnce({ ...mockedAlert, ...mockedAlertComputerFields, diff --git a/x-pack/legacy/plugins/alerting/server/routes/get.test.ts b/x-pack/legacy/plugins/alerting/server/routes/get.test.ts index ae1854f924479..0609e56ce0691 100644 --- a/x-pack/legacy/plugins/alerting/server/routes/get.test.ts +++ b/x-pack/legacy/plugins/alerting/server/routes/get.test.ts @@ -18,7 +18,7 @@ const mockedAlert = { bar: true, }, createdAt: new Date(), - updatedAt: null, + updatedAt: new Date(), actions: [ { group: 'default', diff --git a/x-pack/legacy/plugins/alerting/server/types.ts b/x-pack/legacy/plugins/alerting/server/types.ts index 5efce1f129935..62dcf07abb7bd 100644 --- a/x-pack/legacy/plugins/alerting/server/types.ts +++ b/x-pack/legacy/plugins/alerting/server/types.ts @@ -78,7 +78,7 @@ export interface Alert { createdBy: string | null; updatedBy: string | null; createdAt: Date; - updatedAt: Date | null; + updatedAt: Date; apiKey: string | null; apiKeyOwner: string | null; throttle: string | null; diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts index 2bf370d1f9df6..efc6506e009e7 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts @@ -101,6 +101,11 @@ export default function createAlertTests({ getService }: FtrProviderContext) { mutedInstanceIds: [], }); expect(typeof response.body.scheduledTaskId).to.be('string'); + expect(Date.parse(response.body.createdAt)).to.be.greaterThan(0); + expect(Date.parse(response.body.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(response.body.updatedAt)).to.be.greaterThan( + Date.parse(response.body.createdAt) + ); const { _source: taskRecord } = await getScheduledTask(response.body.scheduledTaskId); expect(taskRecord.type).to.eql('task'); expect(taskRecord.task.taskType).to.eql('alerting:test.noop'); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/find.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/find.ts index d99ab794cd28f..4d47e0c936d00 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/find.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/find.ts @@ -76,6 +76,7 @@ export default function createFindTests({ getService }: FtrProviderContext) { }); expect(Date.parse(match.createdAt)).to.be.greaterThan(0); expect(Date.parse(match.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(match.updatedAt)).to.be.greaterThan(Date.parse(match.createdAt)); break; default: throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); @@ -166,6 +167,7 @@ export default function createFindTests({ getService }: FtrProviderContext) { }); expect(Date.parse(match.createdAt)).to.be.greaterThan(0); expect(Date.parse(match.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(match.updatedAt)).to.be.greaterThan(Date.parse(match.createdAt)); break; default: throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/get.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/get.ts index 20eed4013d7dd..ad1890ad6beec 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/get.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/get.ts @@ -70,6 +70,9 @@ export default function createGetTests({ getService }: FtrProviderContext) { }); expect(Date.parse(response.body.createdAt)).to.be.greaterThan(0); expect(Date.parse(response.body.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(response.body.updatedAt)).to.be.greaterThan( + Date.parse(response.body.createdAt) + ); break; default: throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts index eed0d57d98d05..e89b54b1caa55 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts @@ -86,6 +86,9 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { }); expect(Date.parse(response.body.createdAt)).to.be.greaterThan(0); expect(Date.parse(response.body.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(response.body.updatedAt)).to.be.greaterThan( + Date.parse(response.body.createdAt) + ); // Ensure AAD isn't broken await checkAAD({ supertest, diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/create.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/create.ts index 755007f06d369..a34cf0b8beb72 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/create.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/create.ts @@ -84,6 +84,10 @@ export default function createAlertTests({ getService }: FtrProviderContext) { }); expect(Date.parse(response.body.createdAt)).to.be.greaterThan(0); expect(Date.parse(response.body.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(response.body.updatedAt)).to.be.greaterThan( + Date.parse(response.body.createdAt) + ); + expect(typeof response.body.scheduledTaskId).to.be('string'); const { _source: taskRecord } = await getScheduledTask(response.body.scheduledTaskId); expect(taskRecord.type).to.eql('task'); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/find.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/find.ts index 70935a462d03e..1e285acf09637 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/find.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/find.ts @@ -59,6 +59,7 @@ export default function createFindTests({ getService }: FtrProviderContext) { }); expect(Date.parse(match.createdAt)).to.be.greaterThan(0); expect(Date.parse(match.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(match.updatedAt)).to.be.greaterThan(Date.parse(match.createdAt)); }); it(`shouldn't find alert from another space`, async () => { diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/get.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/get.ts index 30b5e43aee585..a34e82ee888c1 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/get.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/get.ts @@ -53,6 +53,9 @@ export default function createGetTests({ getService }: FtrProviderContext) { }); expect(Date.parse(response.body.createdAt)).to.be.greaterThan(0); expect(Date.parse(response.body.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(response.body.updatedAt)).to.be.greaterThan( + Date.parse(response.body.createdAt) + ); }); it(`shouldn't find alert from another space`, async () => { diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/update.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/update.ts index 3dd831cafa59c..5a35d4bf83865 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/update.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/update.ts @@ -60,6 +60,9 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { }); expect(Date.parse(response.body.createdAt)).to.be.greaterThan(0); expect(Date.parse(response.body.updatedAt)).to.be.greaterThan(0); + expect(Date.parse(response.body.updatedAt)).to.be.greaterThan( + Date.parse(response.body.createdAt) + ); // Ensure AAD isn't broken await checkAAD({