Skip to content

Commit

Permalink
Only expose list method
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed Aug 10, 2023
1 parent 79b4131 commit 3013ecc
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 166 deletions.
8 changes: 0 additions & 8 deletions x-pack/plugins/index_management/server/lib/enrich_policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,3 @@ export const fetchAll = async (client: IScopedClusterClient) => {

return serializeEnrichmentPolicies(res.policies);
};

export const execute = (client: IScopedClusterClient, policyName: string) => {
return client.asCurrentUser.enrich.executePolicy({ name: policyName });
};

export const remove = (client: IScopedClusterClient, policyName: string) => {
return client.asCurrentUser.enrich.deletePolicy({ name: policyName });
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ const mockedPolicy = {
},
};

/**
* Since these route callbacks are so thin, these serve simply as integration tests
* to ensure they're wired up to the lib functions correctly. Business logic is tested
* more thoroughly in the es_deprecation_logging_apis test.
*/
describe('deprecation logging API', () => {
describe('Enrich policies API', () => {
const router = new RouterMock();

beforeEach(() => {
Expand Down Expand Up @@ -71,78 +66,4 @@ describe('deprecation logging API', () => {
await expect(router.runRequest(mockRequest)).rejects.toThrowError(error);
});
});

describe('Execute policy - PUT /api/index_management/enrich_policies/{policy}', () => {
const executeEnrichPolicy = router.getMockESApiFn('enrich.executePolicy');

it('correctly executes a policy', async () => {
const mockRequest: RequestMock = {
method: 'put',
path: addBasePath('/enrich_policies/{name}'),
params: {
name: 'my-policy',
},
};

executeEnrichPolicy.mockResolvedValue({ status: { phase: 'COMPLETE' } });

const res = await router.runRequest(mockRequest);

expect(res).toEqual({
body: { status: { phase: 'COMPLETE' } },
});
});

it('should return an error if it fails', async () => {
const mockRequest: RequestMock = {
method: 'put',
path: addBasePath('/enrich_policies/{name}'),
params: {
name: 'my-policy',
},
};

const error = new Error('Oh no!');
executeEnrichPolicy.mockRejectedValue(error);

await expect(router.runRequest(mockRequest)).rejects.toThrowError(error);
});
});

describe('Delete policy - DELETE /api/index_management/enrich_policies/{policy}', () => {
const deleteEnrichPolicy = router.getMockESApiFn('enrich.deletePolicy');

it('correctly deletes a policy', async () => {
const mockRequest: RequestMock = {
method: 'delete',
path: addBasePath('/enrich_policies/{name}'),
params: {
name: 'my-policy',
},
};

deleteEnrichPolicy.mockResolvedValue({ status: { phase: 'COMPLETE' } });

const res = await router.runRequest(mockRequest);

expect(res).toEqual({
body: { status: { phase: 'COMPLETE' } },
});
});

it('should return an error if it fails', async () => {
const mockRequest: RequestMock = {
method: 'delete',
path: addBasePath('/enrich_policies/{name}'),
params: {
name: 'my-policy',
},
};

const error = new Error('Oh no!');
deleteEnrichPolicy.mockRejectedValue(error);

await expect(router.runRequest(mockRequest)).rejects.toThrowError(error);
});
});
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import { RouteDependencies } from '../../../types';

import { registerListRoute } from './register_list_route';
import { registerDeleteRoute } from './register_delete_route';
import { registerExecuteRoute } from './register_execute_route';

export function registerEnrichPoliciesRoute(dependencies: RouteDependencies) {
registerListRoute(dependencies);
registerDeleteRoute(dependencies);
registerExecuteRoute(dependencies);
}

This file was deleted.

0 comments on commit 3013ecc

Please sign in to comment.