Skip to content

Commit be044e9

Browse files
committed
Adding a type and refactoring a forgotten test
1 parent 230ed0a commit be044e9

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

x-pack/plugins/canvas/server/routes/functions/functions.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import { serializeProvider } from '../../../../../../src/plugins/expressions/com
99
import { RouteInitializerDeps } from '../';
1010
import { API_ROUTE_FUNCTIONS } from '../../../common/lib/constants';
1111

12+
interface FunctionCall {
13+
functionName: string;
14+
args: Record<string, any>;
15+
context: Record<string, any>;
16+
}
17+
1218
export function initializeGetFunctionsRoute(deps: RouteInitializerDeps) {
1319
const { router, expressions } = deps;
1420
router.get(
@@ -31,7 +37,7 @@ export function initializeBatchFunctionsRoute(deps: RouteInitializerDeps) {
3137

3238
async function runFunction(
3339
handlers: { environment: string; elasticsearchClient: LegacyAPICaller },
34-
fnCall: any
40+
fnCall: FunctionCall
3541
) {
3642
const { functionName, args, context } = fnCall;
3743
const { deserialize } = serializeProvider(expressions.getTypes());
@@ -51,7 +57,7 @@ export function initializeBatchFunctionsRoute(deps: RouteInitializerDeps) {
5157
*/
5258
bfetch.addBatchProcessingRoute(API_ROUTE_FUNCTIONS, (request) => {
5359
return {
54-
onBatchItem: async (fnCall: any) => {
60+
onBatchItem: async (fnCall: FunctionCall) => {
5561
const handlers = {
5662
environment: 'server',
5763
elasticsearchClient: elasticsearch.legacy.client.asScoped(request).callAsCurrentUser,

x-pack/plugins/canvas/server/routes/templates/list.test.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@
66

77
import { badRequest } from 'boom';
88
import { initializeListTemplates } from './list';
9-
import {
10-
IRouter,
11-
kibanaResponseFactory,
12-
RequestHandlerContext,
13-
RequestHandler,
14-
} from 'src/core/server';
15-
import {
16-
savedObjectsClientMock,
17-
httpServiceMock,
18-
httpServerMock,
19-
loggingSystemMock,
20-
} from 'src/core/server/mocks';
9+
import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server';
10+
import { savedObjectsClientMock, httpServerMock } from 'src/core/server/mocks';
11+
import { getMockedRouterDeps } from '../test_helpers';
2112

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

3324
beforeEach(() => {
34-
const httpService = httpServiceMock.createSetupContract();
35-
const router = httpService.createRouter() as jest.Mocked<IRouter>;
36-
initializeListTemplates({
37-
router,
38-
logger: loggingSystemMock.create().get(),
39-
});
25+
const routerDeps = getMockedRouterDeps();
26+
initializeListTemplates(routerDeps);
4027

41-
routeHandler = router.get.mock.calls[0][1];
28+
routeHandler = routerDeps.router.get.mock.calls[0][1];
4229
});
4330

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

0 commit comments

Comments
 (0)