Skip to content

Commit

Permalink
Omit timestamps from monitor tests as dates are quite volatile.
Browse files Browse the repository at this point in the history
  • Loading branch information
awahab07 committed Jul 27, 2023
1 parent 31b0c0e commit aa70edf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 56 deletions.
96 changes: 40 additions & 56 deletions x-pack/test/api_integration/apis/synthetics/edit_monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import moment from 'moment';
import { v4 as uuidv4 } from 'uuid';
import { omit } from 'lodash';
import { secretKeys } from '@kbn/synthetics-plugin/common/constants/monitor_management';
import {
ConfigKey,
EncryptedSyntheticsSavedMonitor,
Expand All @@ -18,6 +17,7 @@ import { SYNTHETICS_API_URLS } from '@kbn/synthetics-plugin/common/constants';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { getFixtureJson } from './helper/get_fixture_json';
import { omitTimestamps, omitTimestampsAndSecrets } from './helper/monitor';
import { PrivateLocationTestService } from './services/private_location_test_service';
import { SyntheticsMonitorTestService } from './services/synthetics_monitor_test_service';

Expand Down Expand Up @@ -79,17 +79,12 @@ export default function ({ getService }: FtrProviderContext) {
const { created_at: createdAt, updated_at: updatedAt } = savedMonitor;
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);

expect(savedMonitor).eql(
omit(
{
...newMonitor,
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
[ConfigKey.CONFIG_ID]: monitorId,
created_at: createdAt,
updated_at: updatedAt,
},
secretKeys
)
expect(omitTimestamps(savedMonitor)).eql(
omitTimestampsAndSecrets({
...newMonitor,
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
[ConfigKey.CONFIG_ID]: monitorId,
})
);

const updates: Partial<HTTPFields> = {
Expand Down Expand Up @@ -133,7 +128,12 @@ export default function ({ getService }: FtrProviderContext) {
.send(modifiedMonitor)
.expect(200);

expect(editResponse.body).eql(omit({ ...modifiedMonitor, revision: 2 }, secretKeys));
expect(omitTimestamps(editResponse.body)).eql(
omitTimestampsAndSecrets({
...modifiedMonitor,
revision: 2,
})
);
});

it('strips unknown keys from monitor edits', async () => {
Expand All @@ -145,17 +145,12 @@ export default function ({ getService }: FtrProviderContext) {
const { created_at: createdAt, updated_at: updatedAt } = savedMonitor;
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);

expect(savedMonitor).eql(
omit(
{
...newMonitor,
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
[ConfigKey.CONFIG_ID]: monitorId,
created_at: createdAt,
updated_at: updatedAt,
},
secretKeys
)
expect(omitTimestamps(savedMonitor)).eql(
omitTimestampsAndSecrets({
...newMonitor,
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
[ConfigKey.CONFIG_ID]: monitorId,
})
);

const updates: Partial<HTTPFields> = {
Expand Down Expand Up @@ -202,15 +197,12 @@ export default function ({ getService }: FtrProviderContext) {
.send(modifiedMonitor)
.expect(200);

expect(editResponse.body).eql(
omit(
{
...savedMonitor,
...modifiedMonitor,
revision: 2,
},
secretKeys
)
expect(omitTimestamps(editResponse.body)).eql(
omitTimestampsAndSecrets({
...savedMonitor,
...modifiedMonitor,
revision: 2,
})
);
expect(editResponse.body).not.to.have.keys('unknownkey');
});
Expand Down Expand Up @@ -272,18 +264,13 @@ export default function ({ getService }: FtrProviderContext) {
const { created_at: createdAt, updated_at: updatedAt } = savedMonitor;
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);

expect(savedMonitor).eql(
omit(
{
...newMonitor,
[ConfigKey.CONFIG_ID]: monitorId,
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
[ConfigKey.CONFIG_HASH]: configHash,
created_at: createdAt,
updated_at: updatedAt,
},
secretKeys
)
expect(omitTimestamps(savedMonitor)).eql(
omitTimestampsAndSecrets({
...newMonitor,
[ConfigKey.CONFIG_ID]: monitorId,
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
[ConfigKey.CONFIG_HASH]: configHash,
})
);

const updates: Partial<HTTPFields> = {
Expand All @@ -305,17 +292,14 @@ export default function ({ getService }: FtrProviderContext) {
.send(modifiedMonitor)
.expect(200);

expect(editResponse.body).eql(
omit(
{
...modifiedMonitor,
[ConfigKey.CONFIG_ID]: monitorId,
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
[ConfigKey.CONFIG_HASH]: '',
revision: 2,
},
secretKeys
)
expect(omitTimestamps(editResponse.body)).eql(
omitTimestampsAndSecrets({
...modifiedMonitor,
[ConfigKey.CONFIG_ID]: monitorId,
[ConfigKey.MONITOR_QUERY_ID]: monitorId,
[ConfigKey.CONFIG_HASH]: '',
revision: 2,
})
);
expect(editResponse.body).not.to.have.keys('unknownkey');
});
Expand Down
17 changes: 17 additions & 0 deletions x-pack/test/api_integration/apis/synthetics/helper/monitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { omit } from 'lodash';
import { secretKeys } from '@kbn/synthetics-plugin/common/constants/monitor_management';

export function omitTimestamps(monitor: object) {
return omit(monitor, ['created_at', 'updated_at']);
}

export function omitTimestampsAndSecrets(monitor: object) {
return omit(monitor, ['created_at', 'updated_at', ...secretKeys]);
}

0 comments on commit aa70edf

Please sign in to comment.