Skip to content

Commit

Permalink
Adding a type and refactoring a forgotten test
Browse files Browse the repository at this point in the history
  • Loading branch information
poffdeluxe committed Aug 13, 2020
1 parent 230ed0a commit be044e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
10 changes: 8 additions & 2 deletions x-pack/plugins/canvas/server/routes/functions/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { serializeProvider } from '../../../../../../src/plugins/expressions/com
import { RouteInitializerDeps } from '../';
import { API_ROUTE_FUNCTIONS } from '../../../common/lib/constants';

interface FunctionCall {
functionName: string;
args: Record<string, any>;
context: Record<string, any>;
}

export function initializeGetFunctionsRoute(deps: RouteInitializerDeps) {
const { router, expressions } = deps;
router.get(
Expand All @@ -31,7 +37,7 @@ export function initializeBatchFunctionsRoute(deps: RouteInitializerDeps) {

async function runFunction(
handlers: { environment: string; elasticsearchClient: LegacyAPICaller },
fnCall: any
fnCall: FunctionCall
) {
const { functionName, args, context } = fnCall;
const { deserialize } = serializeProvider(expressions.getTypes());
Expand All @@ -51,7 +57,7 @@ export function initializeBatchFunctionsRoute(deps: RouteInitializerDeps) {
*/
bfetch.addBatchProcessingRoute(API_ROUTE_FUNCTIONS, (request) => {
return {
onBatchItem: async (fnCall: any) => {
onBatchItem: async (fnCall: FunctionCall) => {
const handlers = {
environment: 'server',
elasticsearchClient: elasticsearch.legacy.client.asScoped(request).callAsCurrentUser,
Expand Down
25 changes: 6 additions & 19 deletions x-pack/plugins/canvas/server/routes/templates/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@

import { badRequest } from 'boom';
import { initializeListTemplates } from './list';
import {
IRouter,
kibanaResponseFactory,
RequestHandlerContext,
RequestHandler,
} from 'src/core/server';
import {
savedObjectsClientMock,
httpServiceMock,
httpServerMock,
loggingSystemMock,
} from 'src/core/server/mocks';
import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server';
import { savedObjectsClientMock, httpServerMock } from 'src/core/server/mocks';
import { getMockedRouterDeps } from '../test_helpers';

const mockRouteContext = ({
core: {
Expand All @@ -31,14 +22,10 @@ describe('Find workpad', () => {
let routeHandler: RequestHandler<any, any, any>;

beforeEach(() => {
const httpService = httpServiceMock.createSetupContract();
const router = httpService.createRouter() as jest.Mocked<IRouter>;
initializeListTemplates({
router,
logger: loggingSystemMock.create().get(),
});
const routerDeps = getMockedRouterDeps();
initializeListTemplates(routerDeps);

routeHandler = router.get.mock.calls[0][1];
routeHandler = routerDeps.router.get.mock.calls[0][1];
});

it(`returns 200 with the found templates`, async () => {
Expand Down

0 comments on commit be044e9

Please sign in to comment.