test: clientOptions config accessed but not required

Signed-off-by: Sam Robson <srobson@gocardless.com>
This commit is contained in:
Sam Robson
2021-09-13 11:36:48 +01:00
parent f0c2c81676
commit 129bd23852
@@ -24,6 +24,7 @@ import {
ElasticSearchSearchEngine,
encodePageCursor,
} from './ElasticSearchSearchEngine';
import { ConfigReader } from '@backstage/config';
class ElasticSearchSearchEngineForTranslatorTests extends ElasticSearchSearchEngine {
getTranslator() {
@@ -558,6 +559,55 @@ describe('ElasticSearchSearchEngine', () => {
]);
});
});
describe('ElasticSearchSearchEngine.fromConfig', () => {
it('accesses the clientOptions config', async () => {
const esOptions = {
clientOptions: {
ssl: {
rejectUnauthorized: true,
},
},
node: 'http://test-node',
auth: {
apiKey: 'key',
},
};
const config = new ConfigReader({});
const esConfig = new ConfigReader(esOptions);
jest.spyOn(config, 'getConfig').mockImplementation(() => esConfig);
const getOptionalConfig = jest.spyOn(esConfig, 'getOptionalConfig');
await ElasticSearchSearchEngine.fromConfig({
logger: getVoidLogger(),
config,
});
expect(getOptionalConfig.mock.calls[0][0]).toEqual('clientOptions');
});
it('does not require the clientOptions config', async () => {
const config = new ConfigReader({
search: {
elasticsearch: {
node: 'http://test-node',
auth: {
apiKey: 'test-key',
},
},
},
});
expect(
async () =>
await ElasticSearchSearchEngine.fromConfig({
logger: getVoidLogger(),
config,
}),
).not.toThrowError();
});
});
});
describe('decodePageCursor', () => {