Skip to content

Commit

Permalink
Fix mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Jun 25, 2020
1 parent eada4cc commit 60a47e6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion x-pack/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { licensingMock } from './plugins/licensing/server/mocks';
function createCoreRequestHandlerContextMock() {
return {
core: coreMock.createRequestHandlerContext(),
licensing: { license: licensingMock.createLicense() },
licensing: licensingMock.createRequestHandlerContext(),
};
}

Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/features/server/routes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { FeatureConfig } from '../../common';
function createContextMock(licenseType: LicenseType = 'gold') {
return {
core: coreMock.createRequestHandlerContext(),
licensing: {
license: licensingMock.createLicense({ license: { type: licenseType } }),
},
licensing: licensingMock.createRequestHandlerContext({ license: { type: licenseType } }),
};
}

Expand Down
18 changes: 17 additions & 1 deletion x-pack/plugins/licensing/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { BehaviorSubject } from 'rxjs';
import { LicensingPluginSetup, LicensingPluginStart } from './types';
import {
LicensingPluginSetup,
LicensingPluginStart,
LicensingRequestHandlerContext,
} from './types';
import { licenseMock } from '../common/licensing.mock';
import { featureUsageMock } from './services/feature_usage_service.mock';

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

const createRequestHandlerContextMock = (
...options: Parameters<typeof licenseMock.createLicense>
): jest.Mocked<LicensingRequestHandlerContext> => {
const mock: jest.Mocked<LicensingRequestHandlerContext> = {
license: licenseMock.createLicense(...options),
featureUsage: featureUsageMock.createStart(),
};

return mock;
};

export const licensingMock = {
createSetup: createSetupMock,
createStart: createStartMock,
createRequestHandlerContext: createRequestHandlerContextMock,
...licenseMock,
};
14 changes: 10 additions & 4 deletions x-pack/plugins/licensing/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ export interface RawLicense {
mode: LicenseType;
}

/**
* The APIs exposed on the `licensing` key of {@link RequestHandlerContext} for plugins that depend on licensing.
* @public
*/
export interface LicensingRequestHandlerContext {
featureUsage: FeatureUsageServiceStart;
license: ILicense;
}

declare module 'src/core/server' {
interface RequestHandlerContext {
licensing: {
featureUsage: FeatureUsageServiceStart;
license: ILicense;
};
licensing: LicensingRequestHandlerContext;
}
}

Expand Down

0 comments on commit 60a47e6

Please sign in to comment.