-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions test and refactor other router tests
- Loading branch information
1 parent
073730b
commit 230ed0a
Showing
9 changed files
with
119 additions
and
90 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/canvas/server/routes/functions/functions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { kibanaResponseFactory, RequestHandlerContext, RequestHandler } from 'src/core/server'; | ||
import { httpServerMock } from 'src/core/server/mocks'; | ||
import { ExpressionFunction } from 'src/plugins/expressions/common/expression_functions'; | ||
import { initializeGetFunctionsRoute } from './functions'; | ||
import { getMockedRouterDeps } from '../test_helpers'; | ||
import { API_ROUTE_FUNCTIONS } from '../../../common/lib'; | ||
import { functions } from '../../../canvas_plugin_src/functions/server'; | ||
|
||
const mockRouteContext = {} as RequestHandlerContext; | ||
const routePath = API_ROUTE_FUNCTIONS; | ||
|
||
describe('Get list of serverside expression functions', () => { | ||
let routeHandler: RequestHandler<any, any, any>; | ||
let mockFuncs: Record<string, ExpressionFunction>; | ||
|
||
beforeEach(() => { | ||
mockFuncs = { | ||
demodata: new ExpressionFunction(functions[0]()), | ||
}; | ||
|
||
const routerDeps = getMockedRouterDeps(); | ||
|
||
routerDeps.expressions.getFunctions.mockReturnValueOnce(mockFuncs); | ||
|
||
initializeGetFunctionsRoute(routerDeps); | ||
|
||
routeHandler = routerDeps.router.get.mock.calls[0][1]; | ||
}); | ||
|
||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it(`returns 200 with list of functions`, async () => { | ||
const request = httpServerMock.createKibanaRequest({ | ||
method: 'get', | ||
path: routePath, | ||
}); | ||
|
||
const response = await routeHandler(mockRouteContext, request, kibanaResponseFactory); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.payload).toBe(JSON.stringify(mockFuncs)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
httpServiceMock, | ||
loggingSystemMock, | ||
elasticsearchServiceMock, | ||
} from 'src/core/server/mocks'; | ||
import { bfetchPluginMock } from '../../../../../src/plugins/bfetch/server/mocks'; | ||
import { expressionsPluginMock } from '../../../../../src/plugins/expressions/server/mocks'; | ||
|
||
export function getMockedRouterDeps() { | ||
const httpService = httpServiceMock.createSetupContract(); | ||
const elasticsearch = elasticsearchServiceMock.createSetup(); | ||
const bfetch = bfetchPluginMock.createSetupContract(); | ||
const expressions = expressionsPluginMock.createSetupContract(); | ||
const router = httpService.createRouter(); | ||
|
||
return { | ||
router, | ||
expressions, | ||
elasticsearch, | ||
bfetch, | ||
logger: loggingSystemMock.create().get(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters