mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: should be more allow about empty metrics
This commit is contained in:
		
							parent
							
								
									2ceab239ee
								
							
						
					
					
						commit
						826174dfb5
					
				| @ -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)), | ||||
|     }); | ||||
|  | ||||
| @ -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); | ||||
| }); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user