Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow missing instanceId in client metrics (#1522)
* fix: allow missing instanceId in client metrics * fix: remove ts-ignore
- Loading branch information
Showing
3 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters