2021-09-14 20:17:13 +02:00
|
|
|
import { setupApp } from '../../helpers/test-helper';
|
|
|
|
import metricsExample from '../../../examples/client-metrics.json';
|
|
|
|
import dbInit from '../../helpers/database-init';
|
|
|
|
import getLogger from '../../../fixtures/no-logger';
|
2019-10-03 15:01:33 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
let app;
|
2021-03-19 22:25:21 +01:00
|
|
|
let db;
|
2019-10-03 15:01:33 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
beforeAll(async () => {
|
2021-03-19 22:25:21 +01:00
|
|
|
db = await dbInit('metrics_api_client', getLogger);
|
2021-05-28 11:10:24 +02:00
|
|
|
app = await setupApp(db.stores);
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
afterAll(async () => {
|
|
|
|
await app.destroy();
|
2021-03-19 22:25:21 +01:00
|
|
|
await db.destroy();
|
2019-10-03 15:01:33 +02:00
|
|
|
});
|
2017-12-18 14:21:11 +01:00
|
|
|
|
2021-10-08 10:09:22 +02:00
|
|
|
test('should be possible to send metrics', async () => {
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2017-12-18 14:21:11 +01:00
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send(metricsExample)
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(202);
|
2017-12-18 14:21:11 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should require valid send metrics', async () => {
|
|
|
|
return app.request
|
2017-12-18 14:21:11 +01:00
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({
|
|
|
|
appName: 'test',
|
|
|
|
})
|
2019-10-03 15:01:33 +02:00
|
|
|
.expect(400);
|
2017-12-18 14:21:11 +01:00
|
|
|
});
|
2020-09-25 09:39:12 +02:00
|
|
|
|
2021-10-08 10:09:22 +02:00
|
|
|
test('should accept empty client metrics', async () => {
|
2021-05-28 11:10:24 +02:00
|
|
|
return app.request
|
2020-09-25 09:39:12 +02:00
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({
|
|
|
|
appName: 'demo',
|
|
|
|
instanceId: '1',
|
|
|
|
bucket: {
|
|
|
|
start: Date.now(),
|
|
|
|
stop: Date.now(),
|
|
|
|
toggles: {},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.expect(202);
|
|
|
|
});
|