d055f9f042
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
63 lines
2.3 KiB
TypeScript
63 lines
2.3 KiB
TypeScript
/*
|
|
* 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 expect from '@kbn/expect';
|
|
import { FtrProviderContext } from '../services';
|
|
import { LicensingPluginStart, LicenseType } from '../../../plugins/licensing/public';
|
|
import '../../../../test/plugin_functional/plugins/core_provider_plugin/types';
|
|
|
|
interface FeatureUsage {
|
|
last_used?: number;
|
|
license_level: LicenseType;
|
|
name: string;
|
|
}
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default function (ftrContext: FtrProviderContext) {
|
|
const { getService, getPageObjects } = ftrContext;
|
|
const supertest = getService('supertest');
|
|
const browser = getService('browser');
|
|
const PageObjects = getPageObjects(['common', 'security']);
|
|
|
|
const notifyFeatureUsage = async (featureName: string, lastUsed: number) => {
|
|
await browser.executeAsync(
|
|
async (feature, time, cb) => {
|
|
const { start } = window._coreProvider;
|
|
const licensing: LicensingPluginStart = start.plugins.licensing;
|
|
await licensing.featureUsage.notifyUsage(feature, time);
|
|
cb();
|
|
},
|
|
featureName,
|
|
lastUsed
|
|
);
|
|
};
|
|
|
|
describe('feature_usage API', () => {
|
|
before(async () => {
|
|
await PageObjects.security.login();
|
|
});
|
|
|
|
it('allows to register features to the server', async () => {
|
|
const response = await supertest.get('/api/licensing/feature_usage').expect(200);
|
|
const features = response.body.features.map(({ name }: FeatureUsage) => name);
|
|
|
|
// These were registered by the plugin in ../plugins/test_feature_usage
|
|
expect(features).to.contain('test-client-A');
|
|
expect(features).to.contain('test-client-B');
|
|
});
|
|
|
|
it('allows to notify feature usage', async () => {
|
|
const now = new Date();
|
|
|
|
await notifyFeatureUsage('test-client-A', now.getTime());
|
|
|
|
const response = await supertest.get('/api/licensing/feature_usage').expect(200);
|
|
const features = response.body.features as FeatureUsage[];
|
|
|
|
expect(features.find((f) => f.name === 'test-client-A')?.last_used).to.be(now.toISOString());
|
|
expect(features.find((f) => f.name === 'test-client-B')?.last_used).to.be(null);
|
|
});
|
|
});
|
|
}
|