diff --git a/x-pack/plugins/ml/public/license/__tests__/check_license.js b/x-pack/plugins/ml/public/license/__tests__/check_license.js new file mode 100644 index 0000000000000..92dd5d27db61e --- /dev/null +++ b/x-pack/plugins/ml/public/license/__tests__/check_license.js @@ -0,0 +1,41 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + + + +import expect from 'expect.js'; +import { + xpackFeatureProvider, +} from '../check_license'; + +function Private() { + return { + get(str) { + if (str === 'features.watcher.isAvailable') { + return true; + } else { + return false; + } + } + }; +} + +describe('ML - check license', () => { + + describe('xpackFeatureProvider', () => { + it('returns true for enabled feature', () => { + const xpackFeature = xpackFeatureProvider(Private); + const result = xpackFeature.isAvailable('watcher'); + expect(result).to.be(true); + }); + + it('returns false for disabled feature', () => { + const xpackFeature = xpackFeatureProvider(Private); + const result = xpackFeature.isAvailable('noSuchFeature'); + expect(result).to.be(false); + }); + }); +}); diff --git a/x-pack/plugins/ml/public/license/check_license.js b/x-pack/plugins/ml/public/license/check_license.js index 3cc5577629d7c..a6cc7175aa582 100644 --- a/x-pack/plugins/ml/public/license/check_license.js +++ b/x-pack/plugins/ml/public/license/check_license.js @@ -119,7 +119,7 @@ export function xpackFeatureProvider(Private) { return { isAvailable(feature) { - xpackInfo.get(`features.${feature}.isAvailable`, false); + return xpackInfo.get(`features.${feature}.isAvailable`, false); } }; }