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:
parent
2b74651c18
commit
14694fdf04
@ -84,7 +84,7 @@ test('should require strategies field', () => {
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
test('should allow an empty instanceId field', () => {
|
||||
test('should allow an no instanceId field', () => {
|
||||
expect.assertions(0);
|
||||
return request
|
||||
.post('/api/client/register')
|
||||
@ -96,3 +96,17 @@ test('should allow an empty instanceId field', () => {
|
||||
})
|
||||
.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);
|
||||
});
|
||||
|
95
src/lib/services/client-metrics/schema.test.ts
Normal file
95
src/lib/services/client-metrics/schema.test.ts
Normal 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');
|
||||
});
|
@ -15,7 +15,7 @@ export const clientMetricsSchema = joi
|
||||
.keys({
|
||||
environment: joi.string().optional(),
|
||||
appName: joi.string().required(),
|
||||
instanceId: joi.string().default('default'),
|
||||
instanceId: joi.string().empty(['', null]).default('default'),
|
||||
bucket: joi
|
||||
.object()
|
||||
.required()
|
||||
@ -48,7 +48,7 @@ export const clientRegisterSchema = joi
|
||||
.options({ stripUnknown: true })
|
||||
.keys({
|
||||
appName: joi.string().required(),
|
||||
instanceId: joi.string().default('default'),
|
||||
instanceId: joi.string().empty(['', null]).default('default'),
|
||||
sdkVersion: joi.string().optional(),
|
||||
strategies: joi
|
||||
.array()
|
||||
|
Loading…
Reference in New Issue
Block a user