Skip to content

Commit

Permalink
Unit tests for create_lifecycle_rule_type_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Jun 16, 2021
1 parent 788a76b commit 044a5c1
Show file tree
Hide file tree
Showing 3 changed files with 425 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 { Assign } from '@kbn/utility-types';
import type { RuleDataClient } from '.';
import { RuleDataReader, RuleDataWriter } from './types';

type MockInstances<T extends Record<string, any>> = {
[K in keyof T]: T[K] extends (...args: infer TArgs) => infer TReturn
? jest.MockInstance<TReturn, TArgs>
: never;
};

export function createRuleDataClientMock() {
const bulk = jest.fn();
const search = jest.fn();
const getDynamicIndexPattern = jest.fn();

return ({
createOrUpdateWriteTarget: jest.fn(({ namespace }) => Promise.resolve()),
getReader: jest.fn(() => ({
getDynamicIndexPattern,
search,
})),
getWriter: jest.fn(() => ({
bulk,
})),
} as unknown) as Assign<
RuleDataClient & Omit<MockInstances<RuleDataClient>, 'options' | 'getClusterClient'>,
{
getWriter: (
...args: Parameters<RuleDataClient['getWriter']>
) => MockInstances<RuleDataWriter>;
getReader: (
...args: Parameters<RuleDataClient['getReader']>
) => MockInstances<RuleDataReader>;
}
>;
}
Loading

0 comments on commit 044a5c1

Please sign in to comment.