Skip to content

Commit 47eaf60

Browse files
authored
fix preAuth/preRouting mocks (#72663)
1 parent ad65b2c commit 47eaf60

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/core/server/http/http_server.mocks.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ function createKibanaRequestMock<P = any, Q = any, B = any>({
8989
settings: { tags: routeTags, auth: routeAuthRequired, app: kibanaRouteState },
9090
},
9191
raw: {
92-
req: { socket },
92+
req: {
93+
socket,
94+
// these are needed to avoid an error when consuming KibanaRequest.events
95+
on: jest.fn(),
96+
off: jest.fn(),
97+
},
9398
},
9499
}),
95100
{

src/core/server/http/http_service.mock.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { OnPreRoutingToolkit } from './lifecycle/on_pre_routing';
3333
import { AuthToolkit } from './lifecycle/auth';
3434
import { sessionStorageMock } from './cookie_session_storage.mocks';
3535
import { OnPostAuthToolkit } from './lifecycle/on_post_auth';
36+
import { OnPreAuthToolkit } from './lifecycle/on_pre_auth';
3637
import { OnPreResponseToolkit } from './lifecycle/on_pre_response';
3738

3839
type BasePathMocked = jest.Mocked<InternalHttpServiceSetup['basePath']>;
@@ -175,15 +176,19 @@ const createHttpServiceMock = () => {
175176
return mocked;
176177
};
177178

178-
const createOnPreAuthToolkitMock = (): jest.Mocked<OnPreRoutingToolkit> => ({
179+
const createOnPreAuthToolkitMock = (): jest.Mocked<OnPreAuthToolkit> => ({
179180
next: jest.fn(),
180-
rewriteUrl: jest.fn(),
181181
});
182182

183183
const createOnPostAuthToolkitMock = (): jest.Mocked<OnPostAuthToolkit> => ({
184184
next: jest.fn(),
185185
});
186186

187+
const createOnPreRoutingToolkitMock = (): jest.Mocked<OnPreRoutingToolkit> => ({
188+
next: jest.fn(),
189+
rewriteUrl: jest.fn(),
190+
});
191+
187192
const createAuthToolkitMock = (): jest.Mocked<AuthToolkit> => ({
188193
authenticated: jest.fn(),
189194
notHandled: jest.fn(),
@@ -205,6 +210,7 @@ export const httpServiceMock = {
205210
createOnPreAuthToolkit: createOnPreAuthToolkitMock,
206211
createOnPostAuthToolkit: createOnPostAuthToolkitMock,
207212
createOnPreResponseToolkit: createOnPreResponseToolkitMock,
213+
createOnPreRoutingToolkit: createOnPreRoutingToolkitMock,
208214
createAuthToolkit: createAuthToolkitMock,
209215
createRouter: mockRouter.create,
210216
};

0 commit comments

Comments
 (0)