Skip to content

Commit

Permalink
Merge branch 'search_session_better_route_definition' of github.com:m…
Browse files Browse the repository at this point in the history
…attkime/kibana into search_session_better_route_definition
  • Loading branch information
mattkime committed Jun 13, 2023
2 parents a64b3de + 2e88cf6 commit c771ee1
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/plugins/data/server/search/routes/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { dataPluginMock } from '../../mocks';

import { registerSessionRoutes } from './session';

enum GetHandlerIndex {
ID,
STATUS,
}

enum PostHandlerIndex {
SAVE,
FIND,
Expand Down Expand Up @@ -43,8 +48,8 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
const [, saveHandler] =
mockRouter.versioned.post.mock.results[0].value.addVersion.mock.calls[PostHandlerIndex.SAVE];
const [[, saveHandler]] =
mockRouter.versioned.post.mock.results[PostHandlerIndex.SAVE].value.addVersion.mock.calls;

await saveHandler(mockContext, mockRequest, mockResponse);

Expand Down Expand Up @@ -73,9 +78,9 @@ describe('registerSessionRoutes', () => {
const mockRequest = httpServerMock.createKibanaRequest({ params });
const mockResponse = httpServerMock.createResponseFactory();

const mockRouter = mockCoreSetup.http.createRouter.mock.results[1].value;
const statusHandler =
mockRouter.versioned.get.mock.results[0].value.addVersion.mock.calls[0][1];
const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
const [[, statusHandler]] =
mockRouter.versioned.get.mock.results[GetHandlerIndex.STATUS].value.addVersion.mock.calls;

await statusHandler(mockContext, mockRequest, mockResponse);

Expand All @@ -95,8 +100,8 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
const [, findHandler] =
mockRouter.versioned.post.mock.results[0].value.addVersion.mock.calls[PostHandlerIndex.FIND];
const [[, findHandler]] =
mockRouter.versioned.post.mock.results[PostHandlerIndex.FIND].value.addVersion.mock.calls;

await findHandler(mockContext, mockRequest, mockResponse);

Expand All @@ -114,7 +119,8 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
const [, updateHandler] = mockRouter.put.mock.calls[0];
const [[, updateHandler]] =
mockRouter.versioned.put.mock.results[0].value.addVersion.mock.calls;

await updateHandler(mockContext, mockRequest, mockResponse);

Expand All @@ -129,7 +135,8 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
const [, cancelHandler] = mockRouter.post.mock.calls[PostHandlerIndex.CANCEL];
const [[, cancelHandler]] =
mockRouter.versioned.post.mock.results[PostHandlerIndex.CANCEL].value.addVersion.mock.calls;

await cancelHandler(mockContext, mockRequest, mockResponse);

Expand All @@ -144,7 +151,8 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
const [, deleteHandler] = mockRouter.delete.mock.calls[0];
const [[, deleteHandler]] =
mockRouter.versioned.delete.mock.results[0].value.addVersion.mock.calls;

await deleteHandler(mockContext, mockRequest, mockResponse);

Expand All @@ -161,12 +169,8 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;

const [, extendHandler] =
mockRouter.versioned.post.mock.results[0].value.addVersion.mock.calls[0]; /* [
PostHandlerIndex.EXTEND
];
*/
const [[, extendHandler]] =
mockRouter.versioned.post.mock.results[PostHandlerIndex.EXTEND].value.addVersion.mock.calls;

await extendHandler(mockContext, mockRequest, mockResponse);

Expand Down

0 comments on commit c771ee1

Please sign in to comment.