Skip to content

Commit

Permalink
fixed jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Apr 16, 2020
1 parent 420253c commit 41e96fb
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions x-pack/plugins/event_log/server/es/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ beforeEach(() => {
});

describe('createEsContext', () => {
test('should return is ready state as falsy if not initialized', async () => {
const context = createEsContext({ logger, clusterClient, indexNameRoot: 'test0' });
test('should return is ready state as falsy if not initialized', () => {
const context = createEsContext({
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test0',
});

expect(context.initialized).toBeFalsy();

await context.initialize();
context.initialize();
expect(context.initialized).toBeTruthy();
});

test('should return esNames', () => {
const context = createEsContext({ logger, clusterClient, indexNameRoot: 'test-index' });
const context = createEsContext({
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test-index',
});

const esNames = context.esNames;
expect(esNames).toStrictEqual({
Expand All @@ -44,7 +52,11 @@ describe('createEsContext', () => {
});

test('should return exist false for esAdapter ilm policy, index template and alias before initialize', async () => {
const context = createEsContext({ logger, clusterClient, indexNameRoot: 'test1' });
const context = createEsContext({
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test1',
});
clusterClient.callAsInternalUser.mockResolvedValue(false);

const doesAliasExist = await context.esAdapter.doesAliasExist(context.esNames.alias);
Expand All @@ -57,9 +69,13 @@ describe('createEsContext', () => {
});

test('should return exist true for esAdapter ilm policy, index template and alias after initialize', async () => {
const context = createEsContext({ logger, clusterClient, indexNameRoot: 'test2' });
const context = createEsContext({
logger,
clusterClientPromise: Promise.resolve(clusterClient),
indexNameRoot: 'test2',
});
clusterClient.callAsInternalUser.mockResolvedValue(true);
await context.initialize();
context.initialize();

const doesIlmPolicyExist = await context.esAdapter.doesIlmPolicyExist(
context.esNames.ilmPolicy
Expand Down

0 comments on commit 41e96fb

Please sign in to comment.