Skip to content

Commit

Permalink
[ML] Adds unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Jun 26, 2020
1 parent e7d8834 commit dde9f54
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 { Observable, Subject } from 'rxjs';
import { ILicense } from '../../../../licensing/common/types';

import { MlClientLicense } from './ml_client_license';

describe('MlClientLicense', () => {
test('should miss the license update when initialized without postInitFunction', () => {
const mlLicense = new MlClientLicense();

// upon instantiation the full license doesn't get set
expect(mlLicense.isFullLicense()).toBe(false);

const license$ = new Subject();

mlLicense.setup(license$ as Observable<ILicense>);

// if the observable wasn't triggered the full license is still not set
expect(mlLicense.isFullLicense()).toBe(false);

license$.next({
check: () => ({ state: 'valid' }),
getFeature: () => ({ isEnabled: true }),
status: 'valid',
});

// once the observable triggered the license should be set
expect(mlLicense.isFullLicense()).toBe(true);
});

test('should not miss the license update when initialized with postInitFunction', (done) => {
const mlLicense = new MlClientLicense();

// upon instantiation the full license doesn't get set
expect(mlLicense.isFullLicense()).toBe(false);

const license$ = new Subject();

mlLicense.setup(license$ as Observable<ILicense>, [
(license) => {
// when passed in via postInitFunction callback, the license should be valid
// even if the license$ observable gets triggered after this setup.
expect(license.isFullLicense()).toBe(true);
done();
},
]);

license$.next({
check: () => ({ state: 'valid' }),
getFeature: () => ({ isEnabled: true }),
status: 'valid',
});
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {

// We pass the code to mount the app as a `postInitFunctions`
// callback to setLicenseCache/MlLicense.setup() so we make
// sure the app get mounted only after we received the
// sure the app gets mounted only after we received the
// license information.
const mlLicense = setLicenseCache(pluginsSetup.licensing, [
() => {
Expand Down

0 comments on commit dde9f54

Please sign in to comment.