Skip to content

Commit

Permalink
Refactor mocked policies
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed Aug 10, 2023
1 parent adcb8d5 commit 62be03e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
24 changes: 24 additions & 0 deletions x-pack/plugins/index_management/server/lib/enrich_policies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { serializeEnrichmentPolicies } from './enrich_policies';
import { createTestESEnrichPolicy } from '../test/helpers';

describe('serializeEnrichmentPolicies', () => {
it('knows how to serialize a list of policies', async () => {
const mockedESPolicy = createTestESEnrichPolicy('my-policy', 'match');
expect(serializeEnrichmentPolicies([mockedESPolicy])).toEqual([
{
name: 'my-policy',
type: 'match',
sourceIndices: ['users'],
matchField: 'email',
enrichFields: ['first_name', 'last_name', 'city'],
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,11 @@
import { addBasePath } from '..';
import { RouterMock, routeDependencies, RequestMock } from '../../../test/helpers';
import { serializeEnrichmentPolicies } from '../../../lib/enrich_policies';
import { createTestESEnrichPolicy } from '../../../test/helpers';

import { registerEnrichPoliciesRoute } from './register_enrich_policies_routes';

const mockedPolicy = {
config: {
match: {
name: 'my-policy',
indices: ['users'],
match_field: 'email',
enrich_fields: ['first_name', 'last_name', 'city', 'zip', 'state'],
},
},
};
const mockedPolicy = createTestESEnrichPolicy('my-policy', 'match');

describe('Enrich policies API', () => {
const router = new RouterMock();
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/index_management/server/test/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export type { RequestMock } from './router_mock';
export { RouterMock } from './router_mock';

export { routeDependencies } from './route_dependencies';

export { createTestESEnrichPolicy } from './policies_fixtures';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 type { EnrichPolicyType } from '@elastic/elasticsearch/lib/api/types';

export const createTestESEnrichPolicy = (name: string, type: EnrichPolicyType) => ({
config: {
[type]: {
name,
indices: ['users'],
match_field: 'email',
enrich_fields: ['first_name', 'last_name', 'city'],
},
},
});

0 comments on commit 62be03e

Please sign in to comment.