1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: allow missing instanceId in client metrics (#1522)

* fix: allow missing instanceId in client metrics

* fix: remove ts-ignore
This commit is contained in:
Ivar Conradi Østhus 2022-04-22 13:52:27 +02:00 committed by GitHub
parent 2b74651c18
commit 14694fdf04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 3 deletions

View File

@ -84,7 +84,7 @@ test('should require strategies field', () => {
.expect(400); .expect(400);
}); });
test('should allow an empty instanceId field', () => { test('should allow an no instanceId field', () => {
expect.assertions(0); expect.assertions(0);
return request return request
.post('/api/client/register') .post('/api/client/register')
@ -96,3 +96,17 @@ test('should allow an empty instanceId field', () => {
}) })
.expect(202); .expect(202);
}); });
test('should allow an empty instanceId field', () => {
expect.assertions(0);
return request
.post('/api/client/register')
.send({
appName: 'demo',
instanceId: '',
strategies: ['default'],
started: Date.now(),
interval: 10,
})
.expect(202);
});

View File

@ -0,0 +1,95 @@
import { clientRegisterSchema, clientMetricsSchema } from './schema';
test('clientRegisterSchema should allow empty ("") instanceId', () => {
const { value } = clientRegisterSchema.validate({
appName: 'test',
instanceId: '',
strategies: ['default'],
started: Date.now(),
interval: 100,
});
//@ts-ignore
expect(value.instanceId).toBe('default');
});
test('clientRegisterSchema should allow undefined instanceId', () => {
const { value } = clientRegisterSchema.validate({
appName: 'test',
strategies: ['default'],
started: Date.now(),
interval: 100,
});
expect(value.instanceId).toBe('default');
});
test('clientRegisterSchema should allow null instanceId', () => {
const { value } = clientRegisterSchema.validate({
appName: 'test',
instanceId: null,
strategies: ['default'],
started: Date.now(),
interval: 100,
});
expect(value.instanceId).toBe('default');
});
test('clientRegisterSchema should use instanceId', () => {
const { value } = clientRegisterSchema.validate({
appName: 'test',
instanceId: 'some',
strategies: ['default'],
started: Date.now(),
interval: 100,
});
expect(value.instanceId).toBe('some');
});
test('clientMetricsSchema should allow null instanceId', () => {
const { value } = clientMetricsSchema.validate({
appName: 'test',
instanceId: null,
bucket: {
started: Date.now(),
stopped: Date.now(),
},
});
expect(value.instanceId).toBe('default');
});
test('clientMetricsSchema should allow empty ("") instanceId', () => {
const { value } = clientMetricsSchema.validate({
appName: 'test',
instanceId: '',
bucket: {
started: Date.now(),
stopped: Date.now(),
},
});
expect(value.instanceId).toBe('default');
});
test('clientMetricsSchema should allow undefined instanceId', () => {
const { value } = clientMetricsSchema.validate({
appName: 'test',
bucket: {
started: Date.now(),
stopped: Date.now(),
},
});
expect(value.instanceId).toBe('default');
});
test('clientMetricsSchema should use instanceId', () => {
const { value } = clientMetricsSchema.validate({
appName: 'test',
instanceId: 'some',
bucket: {
started: Date.now(),
stopped: Date.now(),
},
});
expect(value.instanceId).toBe('some');
});

View File

@ -15,7 +15,7 @@ export const clientMetricsSchema = joi
.keys({ .keys({
environment: joi.string().optional(), environment: joi.string().optional(),
appName: joi.string().required(), appName: joi.string().required(),
instanceId: joi.string().default('default'), instanceId: joi.string().empty(['', null]).default('default'),
bucket: joi bucket: joi
.object() .object()
.required() .required()
@ -48,7 +48,7 @@ export const clientRegisterSchema = joi
.options({ stripUnknown: true }) .options({ stripUnknown: true })
.keys({ .keys({
appName: joi.string().required(), appName: joi.string().required(),
instanceId: joi.string().default('default'), instanceId: joi.string().empty(['', null]).default('default'),
sdkVersion: joi.string().optional(), sdkVersion: joi.string().optional(),
strategies: joi strategies: joi
.array() .array()