44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- // eslint-disable-next-line max-classes-per-file
87import { savedObjectsClientMock , loggingSystemMock } from 'src/core/server/mocks' ;
98import { Logger } from 'src/core/server' ;
9+ import { PackageConfigServiceInterface } from '../../../../../../ingest_manager/server' ;
10+ import { createPackageConfigServiceMock } from '../../../../../../ingest_manager/server/mocks' ;
1011import { getFoundExceptionListItemSchemaMock } from '../../../../../../lists/common/schemas/response/found_exception_list_item_schema.mock' ;
1112import { listMock } from '../../../../../../lists/server/mocks' ;
1213import {
@@ -21,40 +22,6 @@ import { getArtifactClientMock } from '../artifact_client.mock';
2122import { getManifestClientMock } from '../manifest_client.mock' ;
2223import { ManifestManager } from './manifest_manager' ;
2324
24- function getMockPackageConfig ( ) {
25- return {
26- id : 'c6d16e42-c32d-4dce-8a88-113cfe276ad1' ,
27- inputs : [
28- {
29- config : { } ,
30- } ,
31- ] ,
32- revision : 1 ,
33- version : 'abcd' , // TODO: not yet implemented in ingest_manager (https://github.com/elastic/kibana/issues/69992)
34- updated_at : '2020-06-25T16:03:38.159292' ,
35- updated_by : 'kibana' ,
36- created_at : '2020-06-25T16:03:38.159292' ,
37- created_by : 'kibana' ,
38- } ;
39- }
40-
41- class PackageConfigServiceMock {
42- public create = jest . fn ( ) . mockResolvedValue ( getMockPackageConfig ( ) ) ;
43- public get = jest . fn ( ) . mockResolvedValue ( getMockPackageConfig ( ) ) ;
44- public getByIds = jest . fn ( ) . mockResolvedValue ( [ getMockPackageConfig ( ) ] ) ;
45- public list = jest . fn ( ) . mockResolvedValue ( {
46- items : [ getMockPackageConfig ( ) ] ,
47- total : 1 ,
48- page : 1 ,
49- perPage : 20 ,
50- } ) ;
51- public update = jest . fn ( ) . mockResolvedValue ( getMockPackageConfig ( ) ) ;
52- }
53-
54- export function getPackageConfigServiceMock ( ) {
55- return new PackageConfigServiceMock ( ) ;
56- }
57-
5825async function mockBuildExceptionListArtifacts (
5926 os : string ,
6027 schemaVersion : string
@@ -66,35 +33,33 @@ async function mockBuildExceptionListArtifacts(
6633 return [ await buildArtifact ( exceptions , os , schemaVersion ) ] ;
6734}
6835
69- // @ts -ignore
7036export class ManifestManagerMock extends ManifestManager {
71- // @ts -ignore
72- private buildExceptionListArtifacts = async ( ) => {
73- return mockBuildExceptionListArtifacts ( 'linux' , 'v1' ) ;
74- } ;
37+ protected buildExceptionListArtifacts = jest
38+ . fn ( )
39+ . mockResolvedValue ( mockBuildExceptionListArtifacts ( 'linux' , 'v1' ) ) ;
7540
76- // @ts -ignore
77- private getLastDispatchedManifest = jest
41+ public getLastDispatchedManifest = jest
7842 . fn ( )
7943 . mockResolvedValue ( new Manifest ( new Date ( ) , 'v1' , ManifestConstants . INITIAL_VERSION ) ) ;
8044
81- // @ts -ignore
82- private getManifestClient = jest
45+ protected getManifestClient = jest
8346 . fn ( )
8447 . mockReturnValue ( getManifestClientMock ( this . savedObjectsClient ) ) ;
48+
49+ public syncArtifacts = jest . fn ( ) . mockResolvedValue ( [ ] ) ;
8550}
8651
8752export const getManifestManagerMock = ( opts ?: {
8853 cache ?: ExceptionsCache ;
89- packageConfigService ?: PackageConfigServiceMock ;
54+ packageConfigService ?: jest . Mocked < PackageConfigServiceInterface > ;
9055 savedObjectsClient ?: ReturnType < typeof savedObjectsClientMock . create > ;
9156} ) : ManifestManagerMock => {
9257 let cache = new ExceptionsCache ( 5 ) ;
9358 if ( opts ?. cache !== undefined ) {
9459 cache = opts . cache ;
9560 }
9661
97- let packageConfigService = getPackageConfigServiceMock ( ) ;
62+ let packageConfigService = createPackageConfigServiceMock ( ) ;
9863 if ( opts ?. packageConfigService !== undefined ) {
9964 packageConfigService = opts . packageConfigService ;
10065 }
@@ -107,7 +72,6 @@ export const getManifestManagerMock = (opts?: {
10772 const manifestManager = new ManifestManagerMock ( {
10873 artifactClient : getArtifactClientMock ( savedObjectsClient ) ,
10974 cache,
110- // @ts -ignore
11175 packageConfigService,
11276 exceptionListClient : listMock . getExceptionListClient ( ) ,
11377 logger : loggingSystemMock . create ( ) . get ( ) as jest . Mocked < Logger > ,
0 commit comments