From eb7fa18dbbb6ce3f41f5bf7212d192238b20f864 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Mon, 20 Apr 2020 09:01:13 +0200 Subject: [PATCH] remove clear API --- .../services/feature_usage_service.mock.ts | 1 - .../services/feature_usage_service.test.ts | 18 ----------- .../server/services/feature_usage_service.ts | 7 ---- .../feature_usage_test/server/routes/clear.ts | 32 ------------------- .../feature_usage_test/server/routes/index.ts | 2 -- .../licensed_feature_usage/feature_usage.ts | 15 ++------- 6 files changed, 3 insertions(+), 72 deletions(-) delete mode 100644 x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/routes/clear.ts diff --git a/x-pack/plugins/licensing/server/services/feature_usage_service.mock.ts b/x-pack/plugins/licensing/server/services/feature_usage_service.mock.ts index 252abcebae8830..f247c6ffcb526c 100644 --- a/x-pack/plugins/licensing/server/services/feature_usage_service.mock.ts +++ b/x-pack/plugins/licensing/server/services/feature_usage_service.mock.ts @@ -22,7 +22,6 @@ const createStartMock = (): jest.Mocked => { const mock = { notifyUsage: jest.fn(), getLastUsages: jest.fn(), - clear: jest.fn(), }; return mock; diff --git a/x-pack/plugins/licensing/server/services/feature_usage_service.test.ts b/x-pack/plugins/licensing/server/services/feature_usage_service.test.ts index cf054c3d69d876..e31e7abff509d8 100644 --- a/x-pack/plugins/licensing/server/services/feature_usage_service.test.ts +++ b/x-pack/plugins/licensing/server/services/feature_usage_service.test.ts @@ -102,23 +102,5 @@ describe('FeatureUsageService', () => { }); }); }); - - describe('#clear', () => { - it('clears the whole last usages map', () => { - const setup = service.setup(); - setup.register('featureA'); - setup.register('featureB'); - - const start = service.start(); - start.notifyUsage('featureA'); - start.notifyUsage('featureB'); - - expect([...start.getLastUsages().keys()]).toEqual(['featureA', 'featureB']); - - start.clear(); - - expect([...start.getLastUsages().keys()]).toEqual([]); - }); - }); }); }); diff --git a/x-pack/plugins/licensing/server/services/feature_usage_service.ts b/x-pack/plugins/licensing/server/services/feature_usage_service.ts index a0e15c61f9e19c..ff9cf7eb28149f 100644 --- a/x-pack/plugins/licensing/server/services/feature_usage_service.ts +++ b/x-pack/plugins/licensing/server/services/feature_usage_service.ts @@ -24,10 +24,6 @@ export interface FeatureUsageServiceStart { * Features that were not used yet do not appear in the map. */ getLastUsages(): ReadonlyMap; - /** - * Clear all usage records from the service. - */ - clear(): void; } export class FeatureUsageService { @@ -55,9 +51,6 @@ export class FeatureUsageService { this.lastUsages.set(featureName, Math.max(usedAt, currentValue)); }, getLastUsages: () => new Map(this.lastUsages.entries()), - clear: () => { - this.lastUsages.clear(); - }, }; } } diff --git a/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/routes/clear.ts b/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/routes/clear.ts deleted file mode 100644 index 764f945e91bae1..00000000000000 --- a/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/routes/clear.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 { IRouter, StartServicesAccessor } from 'src/core/server'; -import { FeatureUsageTestStartDependencies, FeatureUsageTestPluginStart } from '../plugin'; - -export function registerFeatureClearRoute( - router: IRouter, - getStartServices: StartServicesAccessor< - FeatureUsageTestStartDependencies, - FeatureUsageTestPluginStart - > -) { - router.get( - { - path: '/api/feature_usage_test/clear', - validate: false, - }, - async (context, request, response) => { - const [, { licensing }] = await getStartServices(); - try { - licensing.featureUsage.clear(); - return response.ok(); - } catch (e) { - return response.badRequest(); - } - } - ); -} diff --git a/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/routes/index.ts b/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/routes/index.ts index f618ed4783b633..a8225838fd9bfc 100644 --- a/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/routes/index.ts +++ b/x-pack/test/plugin_api_integration/plugins/feature_usage_test/server/routes/index.ts @@ -8,7 +8,6 @@ import { IRouter, StartServicesAccessor } from 'src/core/server'; import { FeatureUsageTestStartDependencies, FeatureUsageTestPluginStart } from '../plugin'; import { registerFeatureHitRoute } from './hit'; -import { registerFeatureClearRoute } from './clear'; export function registerRoutes( router: IRouter, @@ -18,5 +17,4 @@ export function registerRoutes( > ) { registerFeatureHitRoute(router, getStartServices); - registerFeatureClearRoute(router, getStartServices); } diff --git a/x-pack/test/plugin_api_integration/test_suites/licensed_feature_usage/feature_usage.ts b/x-pack/test/plugin_api_integration/test_suites/licensed_feature_usage/feature_usage.ts index 386bde5d42ce39..41f2cfc7983ef0 100644 --- a/x-pack/test/plugin_api_integration/test_suites/licensed_feature_usage/feature_usage.ts +++ b/x-pack/test/plugin_api_integration/test_suites/licensed_feature_usage/feature_usage.ts @@ -15,17 +15,9 @@ export default function({ getService }: FtrProviderContext) { await supertest.get(`/api/feature_usage_test/hit?featureName=${featureName}&usedAt=${usedAt}`); }; - const clearUsages = async () => { - await supertest.get(`/api/feature_usage_test/clear`); - }; - const toISO = (time: number) => new Date(time).toISOString(); describe('/api/licensing/feature_usage', () => { - beforeEach(async () => { - await clearUsages(); - }); - it('returns a map of last feature usages', async () => { const timeA = Date.now(); await notifyUsage('test_feature_a', timeA); @@ -34,10 +26,9 @@ export default function({ getService }: FtrProviderContext) { await notifyUsage('test_feature_b', timeB); const response = await supertest.get('/api/licensing/feature_usage').expect(200); - expect(response.body).to.eql({ - test_feature_a: toISO(timeA), - test_feature_b: toISO(timeB), - }); + + expect(response.body.test_feature_a).to.eql(toISO(timeA)); + expect(response.body.test_feature_b).to.eql(toISO(timeB)); }); }); }