mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
fix onLicenseInfoChange callback to be called on update (#53559)
This commit is contained in:
parent
ecf8657d82
commit
fd4f139be2
2 changed files with 50 additions and 0 deletions
|
@ -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, {
|
||||
|
|
|
@ -101,6 +101,8 @@ export class XPackInfo {
|
|||
error: license.error,
|
||||
};
|
||||
}
|
||||
|
||||
this._licenseInfoChangedListeners.forEach(fn => fn());
|
||||
});
|
||||
|
||||
this._license = new XPackInfoLicense(() => this._cache.license);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue