Skip to content

Commit

Permalink
remove clear API
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Apr 20, 2020
1 parent 250081c commit eb7fa18
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const createStartMock = (): jest.Mocked<FeatureUsageServiceStart> => {
const mock = {
notifyUsage: jest.fn(),
getLastUsages: jest.fn(),
clear: jest.fn(),
};

return mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export interface FeatureUsageServiceStart {
* Features that were not used yet do not appear in the map.
*/
getLastUsages(): ReadonlyMap<string, number>;
/**
* Clear all usage records from the service.
*/
clear(): void;
}

export class FeatureUsageService {
Expand Down Expand Up @@ -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();
},
};
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,5 +17,4 @@ export function registerRoutes(
>
) {
registerFeatureHitRoute(router, getStartServices);
registerFeatureClearRoute(router, getStartServices);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
});
});
}

0 comments on commit eb7fa18

Please sign in to comment.