Skip to content

Commit

Permalink
Merge branch 'alerting/created_at-and-updated_at' into alerting/clien…
Browse files Browse the repository at this point in the history
…t-types

* alerting/created_at-and-updated_at:
  fixed misuse of null on updatedAt
  used createdAt in place of empty updatedAt
  added missing assetion
  • Loading branch information
gmmorris committed Jan 3, 2020
2 parents fa3e74f + 2f50541 commit 1457a5a
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 10 deletions.
10 changes: 5 additions & 5 deletions x-pack/legacy/plugins/alerting/server/alerts_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -421,7 +421,7 @@ describe('create()', () => {
"interval": "10s",
},
"scheduledTaskId": "task-123",
"updatedAt": null,
"updatedAt": 2019-02-12T21:01:22.479Z,
}
`);
expect(savedObjectsClient.bulkGet).toHaveBeenCalledWith([
Expand Down Expand Up @@ -510,7 +510,7 @@ describe('create()', () => {
"schedule": Object {
"interval": 10000,
},
"updatedAt": null,
"updatedAt": 2019-02-12T21:01:22.479Z,
}
`);
expect(savedObjectsClient.create).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -1267,7 +1267,7 @@ describe('get()', () => {
"schedule": Object {
"interval": "10s",
},
"updatedAt": null,
"updatedAt": 2019-02-12T21:01:22.479Z,
}
`);
expect(savedObjectsClient.get).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -1368,7 +1368,7 @@ describe('find()', () => {
"schedule": Object {
"interval": "10s",
},
"updatedAt": null,
"updatedAt": 2019-02-12T21:01:22.479Z,
},
],
"page": 1,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/alerting/server/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
Expand Down Expand Up @@ -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 || [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/alerting/server/routes/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const mockedAlert = {
bar: true,
},
createdAt: new Date(),
updatedAt: null,
updatedAt: new Date(),
actions: [
{
group: 'default',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
Expand Down Expand Up @@ -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)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 1457a5a

Please sign in to comment.