@@ -13,6 +13,11 @@ const MOCK_METRICS_IDS = {
1313 MOBILE_MAX : 'ffffffff-ffff-4fff-bfff-ffffffffffff' ,
1414 EXTENSION_MIN : `0x${ '0' . repeat ( 64 ) as string } ` ,
1515 EXTENSION_MAX : `0x${ 'f' . repeat ( 64 ) as string } ` ,
16+ UUID_V3 : '00000000-0000-3000-8000-000000000000' ,
17+ INVALID_HEX_NO_PREFIX : '86bacb9b2bf9a7e8d2b147eadb95ac9aaa26842327cd24afc8bd4b3c1d136420' ,
18+ INVALID_HEX_SHORT : '0x86bacb9b2bf9a7e8d2b147eadb95ac9aaa26842327cd24afc8bd4b3c1d13642' ,
19+ INVALID_HEX_LONG : '0x86bacb9b2bf9a7e8d2b147eadb95ac9aaa26842327cd24afc8bd4b3c1d1364200' ,
20+ INVALID_HEX_INVALID_CHARS : '0x86bacb9b2bf9a7e8d2b147eadb95ac9aaa26842327cd24afc8bd4b3c1d13642g' ,
1621} ;
1722
1823const MOCK_FEATURE_FLAGS = {
@@ -125,6 +130,29 @@ describe('user-segmentation-utils', () => {
125130 } ) ;
126131 } ) ;
127132 } ) ;
133+
134+ describe ( 'MetaMetrics ID validation' , ( ) => {
135+ it ( 'throws an error if the MetaMetrics ID is not a valid UUIDv4' , ( ) => {
136+ expect ( ( ) => generateDeterministicRandomNumber ( MOCK_METRICS_IDS . UUID_V3 ) ) . toThrow ( 'Invalid UUID version. Expected v4, got v3' ) ;
137+ } ) ;
138+
139+ it ( 'throws an error if the MetaMetrics ID is not a valid hex string' , ( ) => {
140+ expect ( ( ) => generateDeterministicRandomNumber ( MOCK_METRICS_IDS . INVALID_HEX_NO_PREFIX ) ) . toThrow ( 'Hex ID must start with 0x prefix' ) ;
141+ } ) ;
142+
143+ it ( 'throws an error if the MetaMetrics ID is not a valid hex string' , ( ) => {
144+ expect ( ( ) => generateDeterministicRandomNumber ( MOCK_METRICS_IDS . INVALID_HEX_SHORT ) ) . toThrow ( 'Invalid hex ID length. Expected 64 characters, got 63' ) ;
145+ } ) ;
146+
147+ it ( 'throws an error if the MetaMetrics ID is not a valid hex string' , ( ) => {
148+ expect ( ( ) => generateDeterministicRandomNumber ( MOCK_METRICS_IDS . INVALID_HEX_LONG ) ) . toThrow ( 'Invalid hex ID length. Expected 64 characters, got 65' ) ;
149+ } ) ;
150+
151+ it ( 'throws an error if the MetaMetrics ID contains invalid hex characters' , ( ) => {
152+ expect ( ( ) => generateDeterministicRandomNumber ( MOCK_METRICS_IDS . INVALID_HEX_INVALID_CHARS ) )
153+ . toThrow ( 'Hex ID contains invalid characters' ) ;
154+ } ) ;
155+ } ) ;
128156 } ) ;
129157
130158 describe ( 'isFeatureFlagWithScopeValue' , ( ) => {
0 commit comments