Skip to content

Commit

Permalink
Remove indexing of evaluation documents
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Jul 13, 2021
1 parent e9f42d2 commit 92bffc8
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,37 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { Assign } from '@kbn/utility-types';
import { PublicContract } 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>
? jest.MockInstance<TReturn, TArgs> & T[K]
: never;
};

export function createRuleDataClientMock() {
type RuleDataClientMock = jest.Mocked<
Omit<PublicContract<RuleDataClient>, 'getWriter' | 'getReader'>
> & {
getWriter: (...args: Parameters<RuleDataClient['getWriter']>) => MockInstances<RuleDataWriter>;
getReader: (...args: Parameters<RuleDataClient['getReader']>) => MockInstances<RuleDataReader>;
};

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

return ({
createOrUpdateWriteTarget: jest.fn(({ namespace }) => Promise.resolve()),
getReader: jest.fn(() => ({
return {
createWriteTargetIfNeeded: jest.fn(({}) => Promise.resolve()),
getReader: jest.fn((_options?: { namespace?: string }) => ({
getDynamicIndexPattern,
search,
})),
getWriter: jest.fn(() => ({
bulk,
})),
isWriteEnabled: jest.fn(() => true),
} as unknown) as Assign<
RuleDataClient & Omit<MockInstances<RuleDataClient>, 'options' | 'getClusterClient'>,
{
getWriter: (
...args: Parameters<RuleDataClient['getWriter']>
) => MockInstances<RuleDataWriter>;
getReader: (
...args: Parameters<RuleDataClient['getReader']>
) => MockInstances<RuleDataReader>;
}
>;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface RuleDataWriter {
export interface IRuleDataClient {
getReader(options?: { namespace?: string }): RuleDataReader;
getWriter(options?: { namespace?: string }): RuleDataWriter;
isWriteEnabled(): boolean;
createWriteTargetIfNeeded(options: { namespace?: string }): Promise<void>;
}

Expand Down
Loading

0 comments on commit 92bffc8

Please sign in to comment.