1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-22 11:18:20 +02:00
unleash.unleash/src/test/e2e/api/client/metrics.e2e.access.e2e.test.ts
Christopher Kolstad 53354224fc
chore: Bump biome and configure husky (#6589)
Upgrades biome to 1.6.1, and updates husky pre-commit hook.

Most changes here are making type imports explicit.
2024-03-18 13:58:05 +01:00

46 lines
1.3 KiB
TypeScript

import { type IUnleashTest, setupAppWithAuth } from '../../helpers/test-helper';
import metricsExample from '../../../examples/client-metrics.json';
import dbInit, { type ITestDb } from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
import { ApiTokenType } from '../../../../lib/types/models/api-token';
let app: IUnleashTest;
let db: ITestDb;
beforeAll(async () => {
db = await dbInit('metrics_api_e2e_access_client', getLogger);
app = await setupAppWithAuth(db.stores);
});
afterAll(async () => {
await app.destroy();
await db.destroy();
});
test('should enrich metrics with environment from api-token', async () => {
const { apiTokenService } = app.services;
const { environmentStore, clientMetricsStoreV2 } = db.stores;
await environmentStore.create({
name: 'some',
type: 'test',
});
const token = await apiTokenService.createApiToken({
type: ApiTokenType.CLIENT,
tokenName: 'test',
environment: 'some',
project: '*',
});
await app.request
.post('/api/client/metrics')
.set('Authorization', token.secret)
.send(metricsExample)
.expect(202);
await app.services.clientMetricsServiceV2.bulkAdd();
const all = await clientMetricsStoreV2.getAll();
expect(all[0].environment).toBe('some');
});