Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Oct 13, 2021
1 parent d047745 commit 85ac258
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ export function extractRefsFromGeoContainmentAlert(
...doc.attributes,
params: newParams as SavedObjectAttributes,
},
references,
references: [...(doc.references || []), ...references],
};
}
64 changes: 63 additions & 1 deletion x-pack/plugins/alerting/server/saved_objects/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ describe('successful migrations', () => {
});
});

test('extracts references from geo-containment alerts', () => {
test('geo-containment alert migration extracts boundary and index references', () => {
const migration7160 = getMigrations(encryptedSavedObjectsSetup, isPreconfigured)['7.16.0'];
const alert = {
...getMockData({
Expand All @@ -1941,6 +1941,68 @@ describe('successful migrations', () => {
expect(migratedAlert.attributes.params.indexId).toEqual(undefined);
expect(migratedAlert.attributes.params.boundaryIndexId).toEqual(undefined);
});

test('geo-containment alert migration should preserve foreign references', () => {
const migration7160 = getMigrations(encryptedSavedObjectsSetup, isPreconfigured)['7.16.0'];
const alert = {
...getMockData({
alertTypeId: '.geo-containment',
params: {
indexId: 'foo',
boundaryIndexId: 'bar',
},
}),
references: [
{
name: 'foreign-name',
id: '999',
type: 'foreign-name',
},
],
};

const migratedAlert = migration7160(alert, migrationContext);

expect(migratedAlert.references).toEqual([
{
name: 'foreign-name',
id: '999',
type: 'foreign-name',
},
{ id: 'foo', name: 'tracked_index_foo', type: 'index-pattern' },
{ id: 'bar', name: 'boundary_index_bar', type: 'index-pattern' },
]);

expect(migratedAlert.attributes.params).toEqual({
boundaryIndexRefName: 'boundary_index_bar',
indexRefName: 'tracked_index_foo',
});

expect(migratedAlert.attributes.params.indexId).toEqual(undefined);
expect(migratedAlert.attributes.params.boundaryIndexId).toEqual(undefined);
});

test('geo-containment alert migration ignores other alert-types', () => {
const migration7160 = getMigrations(encryptedSavedObjectsSetup, isPreconfigured)['7.16.0'];
const alert = {
...getMockData({
alertTypeId: '.foo',
references: [
{
name: 'foreign-name',
id: '999',
type: 'foreign-name',
},
],
}),
};

const migratedAlert = migration7160(alert, migrationContext);

expect(typeof migratedAlert.attributes.legacyId).toEqual('string'); // introduced by setLegacyId migration
delete migratedAlert.attributes.legacyId;
expect(migratedAlert).toEqual(alert);
});
});

describe('8.0.0', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ describe('alertType', () => {
indexRefName: 'tracked_index_foobar',
},
[
{
id: 'foreign',
name: 'foobar',
type: 'foreign',
},
{
id: 'foobar',
name: 'tracked_index_foobar',
type: 'index-pattern',
},
{
id: 'foreignToo',
name: 'boundary_index_shouldbeignored',
type: 'index-pattern',
},
{
id: 'boundaryid',
name: 'boundary_index_boundaryid',
Expand Down

0 comments on commit 85ac258

Please sign in to comment.