diff --git a/src/lib/routes/client-api/metrics.test.ts b/src/lib/routes/client-api/metrics.test.ts index 4cbb1bb55a..c8b61c5b74 100644 --- a/src/lib/routes/client-api/metrics.test.ts +++ b/src/lib/routes/client-api/metrics.test.ts @@ -6,13 +6,14 @@ import { createTestConfig } from '../../../test/config/test-config'; import { clientMetricsSchema } from '../../services/client-metrics/client-metrics-schema'; import { createServices } from '../../services'; import { IUnleashStores } from '../../types'; +import { IUnleashOptions } from '../../server-impl'; const eventBus = new EventEmitter(); -function getSetup() { +function getSetup(opts?: IUnleashOptions) { const stores = createStores(); - const config = createTestConfig(); + const config = createTestConfig(opts); const services = createServices(stores, config); const app = getApp(config, stores, services, eventBus); @@ -84,6 +85,31 @@ test('should accept client metrics with yes/no', () => { .expect(202); }); +test('should accept client metrics with yes/no with metricsV2', async () => { + const testRunner = getSetup({ + experimental: { metricsV2: { enabled: true } }, + }); + await testRunner.request + .post('/api/client/metrics') + .send({ + appName: 'demo', + instanceId: '1', + bucket: { + start: Date.now(), + stop: Date.now(), + toggles: { + toggleA: { + yes: 200, + no: 0, + }, + }, + }, + }) + .expect(202); + + testRunner.destroy(); +}); + test('should accept client metrics with variants', () => { return request .post('/api/client/metrics') diff --git a/src/test/fixtures/fake-client-metrics-store-v2.ts b/src/test/fixtures/fake-client-metrics-store-v2.ts index d70ee53077..310b5f9115 100644 --- a/src/test/fixtures/fake-client-metrics-store-v2.ts +++ b/src/test/fixtures/fake-client-metrics-store-v2.ts @@ -12,7 +12,7 @@ export default class FakeClientMetricsStoreV2 extends EventEmitter implements IClientMetricsStoreV2 { - metrics: IClientMetric[] = []; + metrics: IClientMetricsEnv[] = []; constructor() { super(); @@ -31,7 +31,8 @@ export default class FakeClientMetricsStoreV2 throw new Error('Method not implemented.'); } batchInsertMetrics(metrics: IClientMetricsEnv[]): Promise { - throw new Error('Method not implemented.'); + metrics.forEach((m) => this.metrics.push(m)); + return Promise.resolve(); } get(key: IClientMetricsEnvKey): Promise { throw new Error('Method not implemented.');