diff --git a/src/core/server/config/index.ts b/src/core/server/config/index.ts index e89f608b9816..ec9f8ed2c8bd 100644 --- a/src/core/server/config/index.ts +++ b/src/core/server/config/index.ts @@ -30,8 +30,6 @@ export { coreDeprecationProvider } from './deprecation'; -export { dynamicConfigServiceMock } from './mocks'; - export { config } from './dynamic_config_service_config'; export { diff --git a/src/core/server/config/mocks.ts b/src/core/server/config/mocks.ts index 372b5c980e1a..3114dad39dc4 100644 --- a/src/core/server/config/mocks.ts +++ b/src/core/server/config/mocks.ts @@ -36,3 +36,8 @@ export { } from '@osd/config/target/mocks'; export { dynamicConfigServiceMock } from './dynamic_config_service.mock'; + +export { + internalDynamicConfigurationClientMock, + dynamicConfigurationClientMock, +} from './service/configuration_client.mock'; diff --git a/src/core/server/config/service/config_store_client/dummy_config_store_client.test.ts b/src/core/server/config/service/config_store_client/dummy_config_store_client.test.ts new file mode 100644 index 000000000000..e51393d07124 --- /dev/null +++ b/src/core/server/config/service/config_store_client/dummy_config_store_client.test.ts @@ -0,0 +1,63 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { DummyConfigStoreClient } from './dummy_config_store_client'; + +describe('DummyConfigStoreClient', () => { + const expectedResponse = { + body: {}, + statusCode: 200, + headers: {}, + warnings: [], + meta: {}, + }; + const dummyStoreConfigClient = new DummyConfigStoreClient(); + + it('should return empty map for listConfigs', async () => { + const response = await dummyStoreConfigClient.listConfigs(); + expect(response).toMatchObject(new Map()); + }); + + it('should return expectedResponse for bulkCreateConfigs', async () => { + const response = await dummyStoreConfigClient.bulkCreateConfigs({ + configs: [], + }); + expect(response).toMatchObject(expectedResponse); + }); + + it('should return expectedResponse for createConfigs', async () => { + const response = await dummyStoreConfigClient.createConfig({ + config: { + name: 'foo', + updatedConfig: {}, + }, + }); + expect(response).toMatchObject(expectedResponse); + }); + + it('should return expectedResponse for bulkDeleteConfigs', async () => { + const response = await dummyStoreConfigClient.bulkDeleteConfigs({ + paths: [], + }); + expect(response).toMatchObject(expectedResponse); + }); + + it('should return expectedResponse for deleteConfig', async () => { + const response = await dummyStoreConfigClient.deleteConfig({ + pluginConfigPath: 'foo', + }); + expect(response).toMatchObject(expectedResponse); + }); + + it('should return undefined for getConfig', async () => { + const response = await dummyStoreConfigClient.getConfig('foo'); + expect(response).toBeUndefined(); + }); + + it('should return empty for bulkGetConfigs', async () => { + const response = await dummyStoreConfigClient.bulkGetConfigs([]); + expect(response).toMatchObject(new Map()); + }); +}); diff --git a/src/core/server/config/service/config_store_client/dummy_config_store_client.ts b/src/core/server/config/service/config_store_client/dummy_config_store_client.ts index c81839e34662..05f4831bebf1 100644 --- a/src/core/server/config/service/config_store_client/dummy_config_store_client.ts +++ b/src/core/server/config/service/config_store_client/dummy_config_store_client.ts @@ -11,7 +11,7 @@ import { DynamicConfigurationClientOptions, IDynamicConfigStoreClient, } from '../../types'; -import { dynamicConfigurationClientMock } from '../configuration_client.mock'; +import { createApiResponse } from '../../utils/utils'; /** * The DummyConfigStoreClient is the client DAO that will used when dynamic config service is "disabled". @@ -27,28 +27,28 @@ export class DummyConfigStoreClient implements IDynamicConfigStoreClient { bulkCreateConfigProps: BulkCreateConfigProps, options?: DynamicConfigurationClientOptions | undefined ) { - return Promise.resolve(dynamicConfigurationClientMock.createApiResponse()); + return Promise.resolve(createApiResponse()); } public async createConfig( createConfigProps: CreateConfigProps, options?: DynamicConfigurationClientOptions | undefined ) { - return Promise.resolve(dynamicConfigurationClientMock.createApiResponse()); + return Promise.resolve(createApiResponse()); } public async bulkDeleteConfigs( bulkDeleteConfigs: BulkDeleteConfigProps, options?: DynamicConfigurationClientOptions | undefined ) { - return Promise.resolve(dynamicConfigurationClientMock.createApiResponse()); + return Promise.resolve(createApiResponse()); } public async deleteConfig( deleteConfigs: ConfigIdentifier, options?: DynamicConfigurationClientOptions | undefined ) { - return Promise.resolve(dynamicConfigurationClientMock.createApiResponse()); + return Promise.resolve(createApiResponse()); } public async getConfig( diff --git a/src/core/server/config/service/configuration_client.mock.ts b/src/core/server/config/service/configuration_client.mock.ts index 0a5aeede1d9f..25bbfa559b81 100644 --- a/src/core/server/config/service/configuration_client.mock.ts +++ b/src/core/server/config/service/configuration_client.mock.ts @@ -5,19 +5,7 @@ import { ApiResponse } from '@opensearch-project/opensearch/.'; import { IDynamicConfigurationClient, IInternalDynamicConfigurationClient } from '../types'; - -const createApiResponse = >( - opts: Partial = {} -): ApiResponse => { - return { - body: {} as any, - statusCode: 200, - headers: {}, - warnings: [], - meta: {} as any, - ...opts, - }; -}; +import { createApiResponse } from '../utils/utils'; const createInternalDynamicConfigurationClientMock = ( props: InternalDynamicConfigurationClientMockProps = { diff --git a/src/core/server/config/utils/utils.ts b/src/core/server/config/utils/utils.ts index f7283f18a96e..46d992fbc369 100644 --- a/src/core/server/config/utils/utils.ts +++ b/src/core/server/config/utils/utils.ts @@ -6,6 +6,7 @@ import _ from 'lodash'; import { Logger } from '@osd/logging'; import { Request } from 'hapi__hapi'; +import { ApiResponse } from '@opensearch-project/opensearch/.'; import { ConfigIdentifier } from '../types'; import { DYNAMIC_APP_CONFIG_INDEX_PREFIX } from './constants'; import { OpenSearchDashboardsRequest } from '../../http'; @@ -25,6 +26,19 @@ export const pathToString = (configIdentifier: ConfigIdentifier) => { return _.snakeCase(name); }; +export const createApiResponse = >( + opts: Partial = {} +): ApiResponse => { + return { + body: {} as any, + statusCode: 200, + headers: {}, + warnings: [], + meta: {} as any, + ...opts, + }; +}; + /** * Given the config from the config file and the config store, merge the two configs. * diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index e9315a620e84..823e778b469e 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -55,6 +55,7 @@ import { crossCompatibilityServiceMock } from './cross_compatibility/cross_compa import { dynamicConfigServiceMock } from './config/dynamic_config_service.mock'; export { configServiceMock } from './config/mocks'; +export { dynamicConfigServiceMock } from './config/mocks'; export { httpServerMock } from './http/http_server.mocks'; export { httpResourcesMock } from './http_resources/http_resources_service.mock'; export { sessionStorageMock } from './http/cookie_session_storage.mocks'; diff --git a/src/plugins/data_source/server/routes/fetch_data_source_metadata.test.ts b/src/plugins/data_source/server/routes/fetch_data_source_metadata.test.ts index 2c9bb9811cb3..5f88d44a5251 100644 --- a/src/plugins/data_source/server/routes/fetch_data_source_metadata.test.ts +++ b/src/plugins/data_source/server/routes/fetch_data_source_metadata.test.ts @@ -16,8 +16,7 @@ import { registerFetchDataSourceMetaDataRoute } from './fetch_data_source_metada import { AuthType } from '../../common/data_sources'; // eslint-disable-next-line @osd/eslint/no-restricted-paths import { opensearchClientMock } from '../../../../../src/core/server/opensearch/client/mocks'; -// eslint-disable-next-line @osd/eslint/no-restricted-paths -import { dynamicConfigServiceMock } from '../../../../../src/core/server/config'; +import { dynamicConfigServiceMock } from '../../../../../src/core/server/mocks'; type SetupServerReturn = UnwrapPromise>; diff --git a/src/plugins/data_source/server/routes/test_connection.test.ts b/src/plugins/data_source/server/routes/test_connection.test.ts index 65775c5e3334..7a3fa66cb694 100644 --- a/src/plugins/data_source/server/routes/test_connection.test.ts +++ b/src/plugins/data_source/server/routes/test_connection.test.ts @@ -16,8 +16,7 @@ import { registerTestConnectionRoute } from './test_connection'; import { AuthType } from '../../common/data_sources'; // eslint-disable-next-line @osd/eslint/no-restricted-paths import { opensearchClientMock } from '../../../../../src/core/server/opensearch/client/mocks'; -// eslint-disable-next-line @osd/eslint/no-restricted-paths -import { dynamicConfigServiceMock } from '../../../../../src/core/server/config'; +import { dynamicConfigServiceMock } from '../../../../../src/core/server/mocks'; type SetupServerReturn = UnwrapPromise>; diff --git a/src/plugins/usage_collection/server/routes/integration_tests/stats.test.ts b/src/plugins/usage_collection/server/routes/integration_tests/stats.test.ts index b658718e20db..705de44afb26 100644 --- a/src/plugins/usage_collection/server/routes/integration_tests/stats.test.ts +++ b/src/plugins/usage_collection/server/routes/integration_tests/stats.test.ts @@ -45,8 +45,7 @@ import { createHttpServer } from '../../../../../core/server/test_utils'; import { registerStatsRoute } from '../stats'; import supertest from 'supertest'; import { CollectorSet } from '../../collector'; -// eslint-disable-next-line @osd/eslint/no-restricted-paths -import { dynamicConfigServiceMock } from '../../../../../core/server/config'; +import { dynamicConfigServiceMock } from '../../../../../core/server/mocks'; type HttpService = ReturnType; type HttpSetup = UnwrapPromise>; diff --git a/src/plugins/workspace/server/integration_tests/duplicate.test.ts b/src/plugins/workspace/server/integration_tests/duplicate.test.ts index d74fed99b6cd..777d9d4f224b 100644 --- a/src/plugins/workspace/server/integration_tests/duplicate.test.ts +++ b/src/plugins/workspace/server/integration_tests/duplicate.test.ts @@ -12,8 +12,7 @@ import { setupServer } from '../../../../core/server/test_utils'; import { registerDuplicateRoute } from '../routes/duplicate'; import { createListStream } from '../../../../core/server/utils/streams'; import Boom from '@hapi/boom'; -// eslint-disable-next-line @osd/eslint/no-restricted-paths -import { dynamicConfigServiceMock } from '../../../../core/server/config'; +import { dynamicConfigServiceMock } from '../../../../core/server/mocks'; jest.mock('../../../../core/server/saved_objects/export', () => ({ exportSavedObjectsToStream: jest.fn(),