Skip to content

Commit

Permalink
Revert decoupling, mock directly in api integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Mar 3, 2021
1 parent db9b28e commit 7c275b5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
27 changes: 0 additions & 27 deletions x-pack/plugins/fleet/server/mocks/app_context_mock.ts

This file was deleted.

26 changes: 21 additions & 5 deletions x-pack/plugins/fleet/server/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,31 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { coreMock } from '../../../../../src/core/server/mocks';
import {
elasticsearchServiceMock,
loggingSystemMock,
savedObjectsServiceMock,
coreMock,
} from '../../../../../src/core/server/mocks';
import { licensingMock } from '../../../../plugins/licensing/server/mocks';

import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/mocks';
import { securityMock } from '../../../security/server/mocks';
import type { PackagePolicyServiceInterface } from '../services/package_policy';
import type { AgentPolicyServiceInterface, AgentService } from '../services';
import type { FleetAppContext } from '../plugin';

// This mock is used in an api integration test, it lives in a separate file
// so that the jest dependency is decoupled
export { createAppContextStartContractMock } from './app_context_mock';
export const createAppContextStartContractMock = (): FleetAppContext => {
return {
elasticsearch: elasticsearchServiceMock.createStart(),
encryptedSavedObjectsStart: encryptedSavedObjectsMock.createStart(),
savedObjects: savedObjectsServiceMock.createStartContract(),
security: securityMock.createStart(),
logger: loggingSystemMock.create().get(),
isProductionMode: true,
kibanaVersion: '8.0.0',
kibanaBranch: 'master',
};
};

function createCoreRequestHandlerContextMock() {
return {
Expand Down
19 changes: 17 additions & 2 deletions x-pack/test/fleet_api_integration/apis/epm/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { createAppContextStartContractMock } from '../../../../plugins/fleet/server/mocks/app_context_mock';
import { appContextService } from '../../../../plugins/fleet/server/services';
import { getTemplate } from '../../../../plugins/fleet/server/services/epm/elasticsearch/template/template';

Expand All @@ -32,7 +31,23 @@ export default function ({ getService }: FtrProviderContext) {
// This test was inspired by https://github.com/elastic/kibana/blob/master/x-pack/test/api_integration/apis/monitoring/common/mappings_exist.js
describe('EPM - template', async () => {
beforeEach(async () => {
appContextService.start(createAppContextStartContractMock());
appContextService.start({
// @ts-ignore
elasticsearch: {},
// @ts-ignore
encryptedSavedObjectsStart: {},
// @ts-ignore
savedObjects: {},
// @ts-ignore
security: {},
// @ts-ignore
logger: {
warn: () => {},
},
isProductionMode: true,
kibanaVersion: '8.0.0',
kibanaBranch: 'master',
});
});

it('can be loaded', async () => {
Expand Down

0 comments on commit 7c275b5

Please sign in to comment.