Skip to content

Commit fb33cb6

Browse files
committed
fix type issue and jest tests
1 parent 06e6396 commit fb33cb6

4 files changed

Lines changed: 45 additions & 20 deletions

File tree

src/plugins/console/server/__tests__/proxy_route/mocks.ts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,45 @@ jest.mock('../../lib/proxy_request', () => ({
2323

2424
import { duration } from 'moment';
2525
import { ProxyConfigCollection } from '../../lib';
26-
import { ProxyHandlerDependencies } from '../../routes/api/console/proxy/create_handler';
27-
import { coreMock } from '../../../../../core/server/mocks';
26+
import { RouteDependencies, ProxyDependencies } from '../../routes';
27+
import { EsLegacyConfigService, SpecDefinitionsService } from '../../services';
28+
import { coreMock, httpServiceMock } from '../../../../../core/server/mocks';
2829

29-
export const getProxyRouteHandlerDeps = ({
30-
proxyConfigCollection = new ProxyConfigCollection([]),
31-
pathFilters = [/.*/],
32-
readLegacyESConfig = () => ({
30+
const defaultProxyValue = Object.freeze({
31+
readLegacyESConfig: async () => ({
3332
requestTimeout: duration(30000),
3433
customHeaders: {},
3534
requestHeadersWhitelist: [],
3635
hosts: ['http://localhost:9200'],
3736
}),
38-
log = coreMock.createPluginInitializerContext().logger.get(),
39-
}: Partial<ProxyHandlerDependencies>): ProxyHandlerDependencies => ({
40-
proxyConfigCollection,
41-
pathFilters,
42-
readLegacyESConfig,
43-
log,
37+
pathFilters: [/.*/],
38+
proxyConfigCollection: new ProxyConfigCollection([]),
4439
});
40+
41+
interface MockDepsArgument extends Partial<Omit<RouteDependencies, 'proxy'>> {
42+
proxy: Partial<ProxyDependencies>;
43+
}
44+
45+
export const getProxyRouteHandlerDeps = ({
46+
proxy = defaultProxyValue,
47+
log = coreMock.createPluginInitializerContext().logger.get(),
48+
router = httpServiceMock.createSetupContract().createRouter(),
49+
}: MockDepsArgument): RouteDependencies => {
50+
const services: RouteDependencies['services'] = {
51+
esLegacyConfigService: new EsLegacyConfigService(),
52+
specDefinitionService: new SpecDefinitionsService(),
53+
};
54+
55+
return {
56+
services,
57+
router,
58+
proxy:
59+
defaultProxyValue !== proxy
60+
? {
61+
...defaultProxyValue,
62+
...proxy,
63+
}
64+
: defaultProxyValue,
65+
log,
66+
};
67+
};

src/plugins/console/server/__tests__/proxy_route/params.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Console Proxy Route', () => {
3636
describe('no matches', () => {
3737
it('rejects with 403', async () => {
3838
handler = createHandler(
39-
getProxyRouteHandlerDeps({ pathFilters: [/^\/foo\//, /^\/bar\//] })
39+
getProxyRouteHandlerDeps({ proxy: { pathFilters: [/^\/foo\//, /^\/bar\//] } })
4040
);
4141

4242
const { status } = await handler(

src/plugins/console/server/__tests__/proxy_route/proxy_fallback.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ describe('Console Proxy Route', () => {
3838

3939
const handler = createHandler(
4040
getProxyRouteHandlerDeps({
41-
readLegacyESConfig: () => ({
42-
requestTimeout: duration(30000),
43-
customHeaders: {},
44-
requestHeadersWhitelist: [],
45-
hosts: ['http://localhost:9201', 'http://localhost:9202', 'http://localhost:9203'],
46-
}),
41+
proxy: {
42+
readLegacyESConfig: async () => ({
43+
requestTimeout: duration(30000),
44+
customHeaders: {},
45+
requestHeadersWhitelist: [],
46+
hosts: ['http://localhost:9201', 'http://localhost:9202', 'http://localhost:9203'],
47+
}),
48+
},
4749
})
4850
);
4951

src/plugins/console/server/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { registerEsConfigRoute } from './api/console/es_config';
2727
import { registerProxyRoute } from './api/console/proxy';
2828
import { registerSpecDefinitionsRoute } from './api/console/spec_definitions';
2929

30-
interface ProxyDependencies {
30+
export interface ProxyDependencies {
3131
readLegacyESConfig: () => Promise<ESConfigForProxy>;
3232
pathFilters: RegExp[];
3333
proxyConfigCollection: ProxyConfigCollection;

0 commit comments

Comments
 (0)