Skip to content

Commit

Permalink
fix onLicenseInfoChange callback to be called on update
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Dec 19, 2019
1 parent 93e0d4e commit 03954fc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,54 @@ describe('XPackInfo', () => {
});
});

it('onLicenseInfoChange() allows to subscribe to license update', async () => {
const license$ = new BehaviorSubject(createLicense());

const xPackInfo = new XPackInfo(mockServer, {
licensing: {
license$,
refresh: () => null,
},
});

const watcherFeature = xPackInfo.feature('watcher');
watcherFeature.registerLicenseCheckResultsGenerator(info => ({
type: info.license.getType(),
}));

const statuses = [];
xPackInfo.onLicenseInfoChange(() => statuses.push(watcherFeature.getLicenseCheckResults()));

license$.next(createLicense({ type: 'basic' }));
expect(statuses).to.eql([{ type: 'basic' }]);

license$.next(createLicense({ type: 'trial' }));
expect(statuses).to.eql([{ type: 'basic' }, { type: 'trial' }]);
});

it('refreshNow() leads to onLicenseInfoChange()', async () => {
const license$ = new BehaviorSubject(createLicense());

const xPackInfo = new XPackInfo(mockServer, {
licensing: {
license$,
refresh: () => license$.next({ type: 'basic' }),
},
});

const watcherFeature = xPackInfo.feature('watcher');

watcherFeature.registerLicenseCheckResultsGenerator(info => ({
type: info.license.getType(),
}));

const statuses = [];
xPackInfo.onLicenseInfoChange(() => statuses.push(watcherFeature.getLicenseCheckResults()));

await xPackInfo.refreshNow();
expect(statuses).to.eql([{ type: 'basic' }]);
});

it('getSignature() returns correct signature.', async () => {
const license$ = new BehaviorSubject(createLicense());
const xPackInfo = new XPackInfo(mockServer, {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/xpack_main/server/lib/xpack_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export class XPackInfo {
error: license.error,
};
}

this._licenseInfoChangedListeners.forEach(fn => fn());
});

this._license = new XPackInfoLicense(() => this._cache.license);
Expand Down

0 comments on commit 03954fc

Please sign in to comment.