1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-05 17:53:12 +02:00

fix: add env metrics

This commit is contained in:
Ivar Conradi Østhus 2021-10-07 20:10:26 +02:00
parent 7a91c5aaa1
commit 30c7e6f78e
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
2 changed files with 31 additions and 4 deletions

View File

@ -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')

View File

@ -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<void> {
throw new Error('Method not implemented.');
metrics.forEach((m) => this.metrics.push(m));
return Promise.resolve();
}
get(key: IClientMetricsEnvKey): Promise<IClientMetricsEnv> {
throw new Error('Method not implemented.');