@@ -13,32 +13,11 @@ describe('RudderStack Compatibility', () => {
1313 } ) ;
1414 } ) ;
1515
16- test ( 'decodeV3Cookie decodes base64 v3 RudderStack cookie' , ( ) => {
17- const v3Value = 'RS_ENC_v3_' + btoa ( JSON . stringify ( 'user123' ) ) ;
18- setCookie ( 'rl_user_id' , v3Value ) ;
19- expect ( decodeV3Cookie ( getCookie ( 'rl_user_id' ) ) ) . toBe ( 'user123' ) ;
20- } ) ;
21-
22- test ( 'decodeV3Cookie returns original value if not v3 format' , ( ) => {
23- setCookie ( 'rl_user_id' , 'plain-value' ) ;
24- expect ( decodeV3Cookie ( getCookie ( 'rl_user_id' ) ) ) . toBe ( 'plain-value' ) ;
25- } ) ;
26-
27- test ( 'decryptV1Cookie decrypts v1 RudderStack cookie' , ( ) => {
28- const plainValue = 'anon123asdasdasdlskdjasdlkajdalskdjasldsdl' ;
16+ test ( 'window.tt.getUserId reads v1 encrypted cookie' , ( ) => {
17+ const plainValue = 'user123' ;
2918 const encrypted = CryptoJS . AES . encrypt ( plainValue , 'Rudder' ) . toString ( ) ;
30- expect ( decryptV1Cookie ( encrypted ) ) . toBe ( plainValue ) ; // Direct test
31- } ) ;
32-
33- test ( 'decryptV1Cookie returns original value if not encrypted' , ( ) => {
34- setCookie ( 'rl_anonymous_id' , 'plain-value' ) ;
35- expect ( decryptV1Cookie ( getCookie ( 'rl_anonymous_id' ) ) ) . toBe ( 'plain-value' ) ;
36- } ) ;
37-
38- test ( 'window.tt.getUserId reads v3 encoded cookie' , ( ) => {
39- const v3Value = 'RS_ENC_v3_' + btoa ( JSON . stringify ( 'user123' ) ) ;
40- setCookie ( 'rl_user_id' , v3Value ) ;
41- expect ( window . tt . getUserId ( ) ) . toBe ( 'user123' ) ;
19+ setCookie ( 'rl_user_id' , encrypted ) ;
20+ expect ( window . tt . getUserId ( ) ) . toBe ( plainValue ) ;
4221 } ) ;
4322
4423 test ( 'window.tt.getAnonymousId reads v1 encrypted cookie' , ( ) => {
@@ -48,18 +27,10 @@ describe('RudderStack Compatibility', () => {
4827 expect ( window . tt . getAnonymousId ( ) ) . toBe ( plainValue ) ;
4928 } ) ;
5029
51- test ( 'window.tt.getTraits reads v3 encoded traits' , ( ) => {
30+ test ( 'window.tt.getTraits reads v1 encrypted traits' , ( ) => {
5231 const traits = { email :
'[email protected] ' } ; 53- const v3Value = 'RS_ENC_v3_' + btoa ( JSON . stringify ( JSON . stringify ( traits ) ) ) ;
54- setCookie ( 'rl_trait' , v3Value ) ;
32+ const encrypted = CryptoJS . AES . encrypt ( JSON . stringify ( traits ) , 'Rudder' ) . toString ( ) ;
33+ setCookie ( 'rl_trait' , encrypted ) ;
5534 expect ( window . tt . getTraits ( ) ) . toEqual ( traits ) ;
5635 } ) ;
57-
58- test ( 'decryptV1Cookie decrypts v1 RudderStack cookie' , ( ) => {
59- const plainValue = 'anon123asdasdasdlskdjasdlkajdalskdjasldsdl' ;
60- const encrypted = CryptoJS . AES . encrypt ( plainValue , 'Rudder' ) . toString ( ) ;
61- const decrypted = decryptV1Cookie ( encrypted ) ;
62- console . log ( 'Encrypted:' , encrypted , 'Decrypted:' , decrypted ) ;
63- expect ( decrypted ) . toBe ( plainValue ) ;
64- } ) ;
6536} ) ;
0 commit comments