Skip to content

Commit

Permalink
start fixing types
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Apr 18, 2023
1 parent 5be68a2 commit 4537691
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ const getMockFetchClients = (hits?: unknown[]) => {
describe('Sample Data Fetch', () => {
let collectorFetchContext: CollectorFetchContext;

const getIndexForType = (index: string) => (type: string) => Promise.resolve(index);

test('uninitialized .kibana', async () => {
const fetch = fetchProvider('index');
const fetch = fetchProvider(getIndexForType('index'));
collectorFetchContext = getMockFetchClients();
const telemetry = await fetch(collectorFetchContext);

expect(telemetry).toMatchInlineSnapshot(`undefined`);
});

test('installed data set', async () => {
const fetch = fetchProvider('index');
const fetch = fetchProvider(getIndexForType('index'));
collectorFetchContext = getMockFetchClients([
{
_id: 'sample-data-telemetry:test1',
Expand All @@ -55,7 +57,7 @@ Object {
});

test('multiple installed data sets', async () => {
const fetch = fetchProvider('index');
const fetch = fetchProvider(getIndexForType('index'));
collectorFetchContext = getMockFetchClients([
{
_id: 'sample-data-telemetry:test1',
Expand Down Expand Up @@ -90,7 +92,7 @@ Object {
});

test('installed data set, missing counts', async () => {
const fetch = fetchProvider('index');
const fetch = fetchProvider(getIndexForType('index'));
collectorFetchContext = getMockFetchClients([
{
_id: 'sample-data-telemetry:test1',
Expand All @@ -112,7 +114,7 @@ Object {
});

test('installed and uninstalled data sets', async () => {
const fetch = fetchProvider('index');
const fetch = fetchProvider(getIndexForType('index'));
collectorFetchContext = getMockFetchClients([
{
_id: 'sample-data-telemetry:test0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ describe('getSavedObjectsCounts', () => {
test('should not fail if no body returned', async () => {
const esClient = mockGetSavedObjectsCounts({});

const results = await getSavedObjectsCounts(esClient, '.kibana', ['type-a']);
const results = await getSavedObjectsCounts(esClient, ['.kibana'], ['type-a']);
// Make sure ES.search is triggered (we'll test the actual params in other specific tests)
expect(esClient.search).toHaveBeenCalledTimes(1);
expect(results).toStrictEqual({ total: 0, per_type: [], non_expected_types: [], others: 0 });
});

test('should match all and request the `missing` bucket (size + 1) when `exclusive === false`', async () => {
const esClient = mockGetSavedObjectsCounts({});
await getSavedObjectsCounts(esClient, '.kibana', ['type-a', 'type_2']);
await getSavedObjectsCounts(esClient, ['.kibana'], ['type-a', 'type_2']);
expect(esClient.search).toHaveBeenCalledWith({
index: '.kibana',
index: ['.kibana'],
ignore_unavailable: true,
filter_path: [
'aggregations.types.buckets',
Expand All @@ -56,9 +56,9 @@ describe('getSavedObjectsCounts', () => {

test('should apply the terms query and aggregation with the size matching the length of the list when `exclusive === true`', async () => {
const esClient = mockGetSavedObjectsCounts({});
await getSavedObjectsCounts(esClient, '.kibana', ['type_one', 'type_two'], true);
await getSavedObjectsCounts(esClient, ['.kibana'], ['type_one', 'type_two'], true);
expect(esClient.search).toHaveBeenCalledWith({
index: '.kibana',
index: ['.kibana'],
ignore_unavailable: true,
filter_path: [
'aggregations.types.buckets',
Expand All @@ -85,11 +85,11 @@ describe('getSavedObjectsCounts', () => {
aggregations: { types: { buckets, sum_other_doc_count: 10 } },
});

const results = await getSavedObjectsCounts(esClient, '.kibana', [
'type_one',
'type-two',
'type-3',
]);
const results = await getSavedObjectsCounts(
esClient,
['.kibana'],
['type_one', 'type-two', 'type-3']
);
expect(results).toStrictEqual({
total: 13,
per_type: [
Expand All @@ -112,7 +112,7 @@ describe('getSavedObjectsCounts', () => {
aggregations: { types: { buckets, sum_other_doc_count: 10 } },
});

const results = await getSavedObjectsCounts(esClient, '.kibana', ['type_one', 'type-two']);
const results = await getSavedObjectsCounts(esClient, ['.kibana'], ['type_one', 'type-two']);
expect(results).toStrictEqual({
total: 13,
per_type: [
Expand All @@ -137,7 +137,7 @@ describe('getSavedObjectsCounts', () => {
aggregations: { types: { buckets, sum_other_doc_count: 6 } },
});

const results = await getSavedObjectsCounts(esClient, '.kibana', ['type_one', 'type-two']);
const results = await getSavedObjectsCounts(esClient, ['.kibana'], ['type_one', 'type-two']);
expect(results).toStrictEqual({
total: 13,
per_type: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ describe('kibana_usage', () => {
});

const kibanaIndex = '.kibana-tests';
const getIndexForTypes = (index: string) => (types: string[]) => Promise.resolve([index]);

beforeAll(() => registerKibanaUsageCollector(usageCollectionMock, kibanaIndex));
beforeAll(() => registerKibanaUsageCollector(usageCollectionMock, getIndexForTypes(kibanaIndex)));
afterAll(() => jest.clearAllTimers());

afterEach(() => getSavedObjectsCountsMock.mockReset());
Expand Down Expand Up @@ -61,7 +62,7 @@ describe('getKibanaSavedObjectCounts', () => {
non_expected_types: [],
others: 0,
});
const results = await getKibanaSavedObjectCounts(esClient, '.kibana');
const results = await getKibanaSavedObjectCounts(esClient, ['.kibana']);
expect(results).toStrictEqual({
dashboard: { total: 0 },
visualization: { total: 0 },
Expand All @@ -83,7 +84,7 @@ describe('getKibanaSavedObjectCounts', () => {
others: 0,
});

const results = await getKibanaSavedObjectCounts(esClient, '.kibana');
const results = await getKibanaSavedObjectCounts(esClient, ['.kibana']);
expect(results).toStrictEqual({
dashboard: { total: 1 },
visualization: { total: 0 },
Expand All @@ -94,7 +95,7 @@ describe('getKibanaSavedObjectCounts', () => {

expect(getSavedObjectsCountsMock).toHaveBeenCalledWith(
esClient,
'.kibana',
['.kibana'],
['dashboard', 'visualization', 'search', 'index-pattern', 'graph-workspace'],
true
);
Expand Down

0 comments on commit 4537691

Please sign in to comment.