Skip to content

Commit 60a47e6

Browse files
committed
Fix mocks
1 parent eada4cc commit 60a47e6

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

x-pack/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { licensingMock } from './plugins/licensing/server/mocks';
99
function createCoreRequestHandlerContextMock() {
1010
return {
1111
core: coreMock.createRequestHandlerContext(),
12-
licensing: { license: licensingMock.createLicense() },
12+
licensing: licensingMock.createRequestHandlerContext(),
1313
};
1414
}
1515

x-pack/plugins/features/server/routes/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import { FeatureConfig } from '../../common';
1616
function createContextMock(licenseType: LicenseType = 'gold') {
1717
return {
1818
core: coreMock.createRequestHandlerContext(),
19-
licensing: {
20-
license: licensingMock.createLicense({ license: { type: licenseType } }),
21-
},
19+
licensing: licensingMock.createRequestHandlerContext({ license: { type: licenseType } }),
2220
};
2321
}
2422

x-pack/plugins/licensing/server/mocks.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { BehaviorSubject } from 'rxjs';
7-
import { LicensingPluginSetup, LicensingPluginStart } from './types';
7+
import {
8+
LicensingPluginSetup,
9+
LicensingPluginStart,
10+
LicensingRequestHandlerContext,
11+
} from './types';
812
import { licenseMock } from '../common/licensing.mock';
913
import { featureUsageMock } from './services/feature_usage_service.mock';
1014

@@ -43,8 +47,20 @@ const createStartMock = (): jest.Mocked<LicensingPluginStart> => {
4347
return mock;
4448
};
4549

50+
const createRequestHandlerContextMock = (
51+
...options: Parameters<typeof licenseMock.createLicense>
52+
): jest.Mocked<LicensingRequestHandlerContext> => {
53+
const mock: jest.Mocked<LicensingRequestHandlerContext> = {
54+
license: licenseMock.createLicense(...options),
55+
featureUsage: featureUsageMock.createStart(),
56+
};
57+
58+
return mock;
59+
};
60+
4661
export const licensingMock = {
4762
createSetup: createSetupMock,
4863
createStart: createStartMock,
64+
createRequestHandlerContext: createRequestHandlerContextMock,
4965
...licenseMock,
5066
};

x-pack/plugins/licensing/server/types.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ export interface RawLicense {
4040
mode: LicenseType;
4141
}
4242

43+
/**
44+
* The APIs exposed on the `licensing` key of {@link RequestHandlerContext} for plugins that depend on licensing.
45+
* @public
46+
*/
47+
export interface LicensingRequestHandlerContext {
48+
featureUsage: FeatureUsageServiceStart;
49+
license: ILicense;
50+
}
51+
4352
declare module 'src/core/server' {
4453
interface RequestHandlerContext {
45-
licensing: {
46-
featureUsage: FeatureUsageServiceStart;
47-
license: ILicense;
48-
};
54+
licensing: LicensingRequestHandlerContext;
4955
}
5056
}
5157

0 commit comments

Comments
 (0)