mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
ccaab0c47b
Instead of instructing users to do static calls in to Unleash, she should instead be allwed to specify the log provider as an option to Unleash. This commit introduces the "getLogger" option, a function responsible for creating a logger.
122 lines
2.9 KiB
JavaScript
122 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('ava');
|
|
const store = require('./../../../test/fixtures/store');
|
|
const getLogger = require('../../../test/fixtures/no-logger');
|
|
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,
|
|
getLogger,
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
test('should accept empty client metrics', 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: {},
|
|
},
|
|
})
|
|
.expect(202);
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
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 => {
|
|
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,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
.expect(202);
|
|
});
|