1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

fix: should be more allow about empty metrics

This commit is contained in:
ivaosthu 2019-05-06 10:50:50 +02:00 committed by Ivar Conradi Østhus
parent 7683325721
commit 06186a7638
2 changed files with 37 additions and 1 deletions

View File

@ -9,10 +9,12 @@ const countSchema = joi
yes: joi
.number()
.min(0)
.empty('')
.default(0),
no: joi
.number()
.min(0)
.empty('')
.default(0),
variants: joi.object().pattern(joi.string(), joi.number().min(0)),
});

View File

@ -1,10 +1,12 @@
'use strict';
const test = require('ava');
const supertest = require('supertest');
const joi = require('joi');
const store = require('./../../../test/fixtures/store');
const getLogger = require('../../../test/fixtures/no-logger');
const supertest = require('supertest');
const getApp = require('../../app');
const { clientMetricsSchema } = require('./metrics-schema');
const { EventEmitter } = require('events');
const eventBus = new EventEmitter();
@ -119,3 +121,35 @@ test('should accept client metrics without yes/no', t => {
})
.expect(202);
});
test('shema allow empty strings', t => {
const data = {
appName: 'java-test',
instanceId: 'instance y',
bucket: {
toggles: { Demo2: { yes: '', no: '', variants: {} } },
start: '2019-05-06T08:30:40.514Z',
stop: '2019-05-06T09:30:50.515Z',
},
};
const { error, value } = joi.validate(data, clientMetricsSchema);
t.falsy(error);
t.is(value.bucket.toggles.Demo2.yes, 0);
t.is(value.bucket.toggles.Demo2.no, 0);
});
test('shema allow yes=<string nbr>', t => {
const data = {
appName: 'java-test',
instanceId: 'instance y',
bucket: {
toggles: { Demo2: { yes: '12', no: 256, variants: {} } },
start: '2019-05-06T08:30:40.514Z',
stop: '2019-05-06T09:30:50.515Z',
},
};
const { error, value } = joi.validate(data, clientMetricsSchema);
t.falsy(error);
t.is(value.bucket.toggles.Demo2.yes, 12);
t.is(value.bucket.toggles.Demo2.no, 256);
});