forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from oatkiller/entity-upgrade-fix
* change 'data' state shape, nesting the tree fetcher data * rename 'TreeFetcherParameters' from 'DatabaseParameters' to make it more specific to the API it works on * fix bug in 'equal' method of 'TreeFetcherParameters'` * use mockTreeFetcherParameters method in tests that need to specify a TreeFetcherParameters but when the value isn't relevant to the test * Hide Resolver if there is no databaseDocumentID * add doc comments
- Loading branch information
Showing
17 changed files
with
295 additions
and
189 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/security_solution/public/resolver/mocks/tree_fetcher_parameters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { TreeFetcherParameters } from '../types'; | ||
|
||
/** | ||
* A factory for the most basic `TreeFetcherParameters`. Many tests need to provide this even when the values aren't relevant to the test. | ||
*/ | ||
export function mockTreeFetcherParameters(): TreeFetcherParameters { | ||
return { | ||
databaseDocumentID: '', | ||
indices: [], | ||
}; | ||
} |
12 changes: 0 additions & 12 deletions
12
x-pack/plugins/security_solution/public/resolver/models/database_parameters.ts
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
x-pack/plugins/security_solution/public/resolver/models/tree_fetcher_parameters.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { TreeFetcherParameters } from '../types'; | ||
|
||
import { equal } from './tree_fetcher_parameters'; | ||
describe('TreeFetcherParameters#equal:', () => { | ||
const cases: Array<[TreeFetcherParameters, TreeFetcherParameters, boolean]> = [ | ||
// different databaseDocumentID | ||
[{ databaseDocumentID: 'a', indices: [] }, { databaseDocumentID: 'b', indices: [] }, false], | ||
// different indices length | ||
[{ databaseDocumentID: 'a', indices: [''] }, { databaseDocumentID: 'a', indices: [] }, false], | ||
// same indices length, different databaseDocumentID | ||
[{ databaseDocumentID: 'a', indices: [''] }, { databaseDocumentID: 'b', indices: [''] }, false], | ||
// 1 item in `indices` | ||
[{ databaseDocumentID: 'b', indices: [''] }, { databaseDocumentID: 'b', indices: [''] }, true], | ||
// 2 item in `indices` | ||
[ | ||
{ databaseDocumentID: 'b', indices: ['1', '2'] }, | ||
{ databaseDocumentID: 'b', indices: ['1', '2'] }, | ||
true, | ||
], | ||
// 2 item in `indices`, but order inversed | ||
[ | ||
{ databaseDocumentID: 'b', indices: ['2', '1'] }, | ||
{ databaseDocumentID: 'b', indices: ['1', '2'] }, | ||
true, | ||
], | ||
]; | ||
describe.each(cases)('%p when compared to %p', (first, second, expected) => { | ||
it(`should ${expected ? '' : 'not'}be equal`, () => { | ||
expect(equal(first, second)).toBe(expected); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
x-pack/plugins/security_solution/public/resolver/models/tree_fetcher_parameters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { TreeFetcherParameters } from '../types'; | ||
|
||
/** | ||
* Determine if two instances of `TreeFetcherParameters` are equivalent. Use this to determine if | ||
* a change to a `TreeFetcherParameters` warrants invaliding a request or response. | ||
*/ | ||
export function equal(param1: TreeFetcherParameters, param2?: TreeFetcherParameters): boolean { | ||
if (!param2) { | ||
return false; | ||
} | ||
if (param1 === param2) { | ||
return true; | ||
} | ||
if (param1.databaseDocumentID !== param2.databaseDocumentID) { | ||
return false; | ||
} | ||
return arrayEqual(param1.indices, param2.indices); | ||
} | ||
|
||
function arrayEqual(first: unknown[], second: unknown[]): boolean { | ||
if (first === second) { | ||
return true; | ||
} | ||
if (first.length !== second.length) { | ||
return false; | ||
} | ||
const firstSet = new Set(first); | ||
for (let index = 0; index < second.length; index++) { | ||
if (!firstSet.has(second[index])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.