Skip to content

Commit

Permalink
fix jest
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Feb 4, 2021
1 parent f35a778 commit 182b21c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/plugins/data/server/search/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ export function createSearchRequestHandlerContext() {
updateSession: jest.fn(),
extendSession: jest.fn(),
cancelSession: jest.fn(),
deleteSession: jest.fn(),
};
}
21 changes: 14 additions & 7 deletions x-pack/plugins/data_enhanced/server/routes/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import type {
import { dataPluginMock } from '../../../../../src/plugins/data/server/mocks';
import { registerSessionRoutes } from './session';

enum PostHandlerIndex {
SAVE,
FIND,
CANCEL,
EXTEND,
}

describe('registerSessionRoutes', () => {
let mockCoreSetup: MockedKeys<CoreSetup<{}, DataPluginStart>>;
let mockContext: jest.Mocked<DataRequestHandlerContext>;
Expand All @@ -37,7 +44,7 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

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

saveHandler(mockContext, mockRequest, mockResponse);

Expand Down Expand Up @@ -71,7 +78,7 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

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

findHandler(mockContext, mockRequest, mockResponse);

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

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

updateHandler(mockContext, mockRequest, mockResponse);

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

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

cancelHandler(mockContext, mockRequest, mockResponse);

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

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

deleteHandler(mockContext, mockRequest, mockResponse);
await deleteHandler(mockContext, mockRequest, mockResponse);

expect(mockContext.search!.deleteSession).toHaveBeenCalledWith(id);
});
Expand All @@ -136,7 +143,7 @@ describe('registerSessionRoutes', () => {
const mockResponse = httpServerMock.createResponseFactory();

const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
const [, , [, extendHandler]] = mockRouter.post.mock.calls;
const [, extendHandler] = mockRouter.post.mock.calls[PostHandlerIndex.EXTEND];

extendHandler(mockContext, mockRequest, mockResponse);

Expand Down

0 comments on commit 182b21c

Please sign in to comment.