fix onLicenseInfoChange callback to be called on update (#53559)

This commit is contained in:
Mikhail Shustov 2019-12-19 10:42:46 +01:00 committed by GitHub
parent ecf8657d82
commit fd4f139be2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View file

@ -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, {

View file

@ -101,6 +101,8 @@ export class XPackInfo {
error: license.error,
};
}
this._licenseInfoChangedListeners.forEach(fn => fn());
});
this._license = new XPackInfoLicense(() => this._cache.license);