2017-06-28 10:20:22 +02:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
2017-06-28 10:20:22 +02:00
|
|
|
const store = require('./../../../test/fixtures/store');
|
|
|
|
const supertest = require('supertest');
|
|
|
|
const getApp = require('../../app');
|
|
|
|
|
|
|
|
const { EventEmitter } = require('events');
|
|
|
|
const eventBus = new EventEmitter();
|
|
|
|
|
|
|
|
function getSetup() {
|
|
|
|
const stores = store.createStores();
|
|
|
|
const app = getApp({
|
|
|
|
baseUriPath: '',
|
|
|
|
stores,
|
|
|
|
eventBus,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
request: supertest(app),
|
|
|
|
stores,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
test('should validate client metrics', t => {
|
|
|
|
t.plan(0);
|
|
|
|
const { request } = getSetup();
|
|
|
|
return request
|
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({ random: 'blush' })
|
|
|
|
.expect(400);
|
|
|
|
});
|
|
|
|
|
2017-08-04 11:24:58 +02:00
|
|
|
test('should accept empty client metrics', t => {
|
2017-06-28 10:20:22 +02:00
|
|
|
t.plan(0);
|
|
|
|
const { request } = getSetup();
|
|
|
|
return request
|
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({
|
|
|
|
appName: 'demo',
|
|
|
|
instanceId: '1',
|
|
|
|
bucket: {
|
|
|
|
start: Date.now(),
|
|
|
|
stop: Date.now(),
|
|
|
|
toggles: {},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.expect(202);
|
|
|
|
});
|
2017-08-04 11:24:58 +02:00
|
|
|
|
|
|
|
test('should accept client metrics with yes/no', t => {
|
|
|
|
t.plan(0);
|
|
|
|
const { request } = getSetup();
|
|
|
|
return 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);
|
|
|
|
});
|
|
|
|
|
2019-01-25 13:05:25 +01:00
|
|
|
test('should accept client metrics with variants', t => {
|
|
|
|
t.plan(0);
|
|
|
|
const { request } = getSetup();
|
|
|
|
return request
|
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({
|
|
|
|
appName: 'demo',
|
|
|
|
instanceId: '1',
|
|
|
|
bucket: {
|
|
|
|
start: Date.now(),
|
|
|
|
stop: Date.now(),
|
|
|
|
toggles: {
|
|
|
|
toggleA: {
|
|
|
|
yes: 200,
|
|
|
|
no: 0,
|
|
|
|
variants: {
|
|
|
|
variant1: 1,
|
|
|
|
variant2: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.expect(202);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should accept client metrics without yes/no', t => {
|
2017-08-04 11:24:58 +02:00
|
|
|
t.plan(0);
|
|
|
|
const { request } = getSetup();
|
|
|
|
return request
|
|
|
|
.post('/api/client/metrics')
|
|
|
|
.send({
|
|
|
|
appName: 'demo',
|
|
|
|
instanceId: '1',
|
|
|
|
bucket: {
|
|
|
|
start: Date.now(),
|
|
|
|
stop: Date.now(),
|
|
|
|
toggles: {
|
|
|
|
toggleA: {
|
|
|
|
blue: 200,
|
|
|
|
green: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2019-01-25 13:05:25 +01:00
|
|
|
.expect(202);
|
2017-08-04 11:24:58 +02:00
|
|
|
});
|