Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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