@@ -274,122 +274,6 @@ describe('RoktManager', () => {
274274 } ) ;
275275 } ) ;
276276
277- describe ( '#hashSha256' , ( ) => {
278- interface Hasher {
279- sha256Hex ( input : string ) : Promise < string >
280- }
281-
282- const nodeCrypto = require ( 'crypto' ) ;
283- let shaSpy : jest . SpyInstance ;
284-
285- beforeEach ( ( ) => {
286- shaSpy = jest . spyOn ( roktManager as unknown as Hasher , 'sha256Hex' ) ;
287- shaSpy . mockImplementation ( ( s : any ) =>
288- Promise . resolve ( nodeCrypto . createHash ( 'sha256' ) . update ( String ( s ) ) . digest ( 'hex' ) ) ,
289- ) ;
290- } ) ;
291-
292- afterEach ( ( ) => {
293- shaSpy . mockRestore ( ) ;
294- } ) ;
295-
296- it ( 'should hash a single string value using SHA-256' , async ( ) => {
297- const result = await roktManager . hashSha256 ( 'test@example.com' ) ;
298- const expected = nodeCrypto . createHash ( 'sha256' ) . update ( 'test@example.com' ) . digest ( 'hex' ) ;
299-
300- expect ( result ) . toBe ( expected ) ;
301- expect ( shaSpy ) . toHaveBeenCalledWith ( 'test@example.com' ) ;
302- expect ( shaSpy ) . toHaveBeenCalledTimes ( 1 ) ;
303- } ) ;
304-
305- it ( 'should hash values without kit being attached' , async ( ) => {
306- // Verify kit is not attached
307- expect ( roktManager [ 'kit' ] ) . toBeNull ( ) ;
308-
309- const result = await roktManager . hashSha256 ( 'user@example.com' ) ;
310- const expected = nodeCrypto . createHash ( 'sha256' ) . update ( 'user@example.com' ) . digest ( 'hex' ) ;
311-
312- expect ( result ) . toBe ( expected ) ;
313- } ) ;
314-
315- it ( 'should handle empty string' , async ( ) => {
316- const emptyStringHash = await roktManager . hashSha256 ( '' ) ;
317-
318- // Empty string after trim becomes '', hash of empty string
319- expect ( emptyStringHash ) . toBe ( 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' ) ;
320- } ) ;
321-
322- it ( 'should return null and log warning when value is null' , async ( ) => {
323- const result = await roktManager . hashSha256 ( null ) ;
324-
325- expect ( result ) . toBeNull ( ) ;
326- expect ( mockMPInstance . Logger . warning ) . toHaveBeenCalledWith ( 'hashSha256 received null as input' ) ;
327- } ) ;
328-
329- it ( 'should return undefined and log warning when value is undefined' , async ( ) => {
330- const result = await roktManager . hashSha256 ( undefined ) ;
331-
332- expect ( result ) . toBeUndefined ( ) ;
333- expect ( mockMPInstance . Logger . warning ) . toHaveBeenCalledWith ( 'hashSha256 received undefined as input' ) ;
334- } ) ;
335-
336- it ( 'should return undefined and log error when hashing fails' , async ( ) => {
337- shaSpy . mockRejectedValue ( new Error ( 'Hash failed' ) ) ;
338-
339- const result = await roktManager . hashSha256 ( 'test@example.com' ) ;
340-
341- expect ( result ) . toBeUndefined ( ) ;
342- expect ( mockMPInstance . Logger . error ) . toHaveBeenCalledWith (
343- expect . stringContaining ( 'Failed to hash "test@example.com" and returning undefined, selectPlacements will continue' )
344- ) ;
345- } ) ;
346-
347- it ( 'should hash firstName to known SHA-256 value' , async ( ) => {
348- const hashedFirstName = await roktManager . hashSha256 ( 'jane' ) ;
349-
350- // Expected SHA-256 hash of 'jane'
351- expect ( hashedFirstName ) . toBe ( '81f8f6dde88365f3928796ec7aa53f72820b06db8664f5fe76a7eb13e24546a2' ) ;
352- } ) ;
353-
354- it ( 'should produce same hash for different case and whitespace variations' , async ( ) => {
355- const lowercaseEmail = await roktManager . hashSha256 ( 'jane.doe@gmail.com' ) ;
356- const mixedCaseEmail = await roktManager . hashSha256 ( 'Jane.Doe@gmail.com' ) ;
357- const emailWithWhitespace = await roktManager . hashSha256 ( ' jane.doe@gmail.com ' ) ;
358-
359- // All should normalize to same hash
360- expect ( lowercaseEmail ) . toBe ( mixedCaseEmail ) ;
361- expect ( mixedCaseEmail ) . toBe ( emailWithWhitespace ) ;
362- expect ( lowercaseEmail ) . toBe ( '831f6494ad6be4fcb3a724c3d5fef22d3ceffa3c62ef3a7984e45a0ea177f982' ) ;
363- } ) ;
364-
365- it ( 'should handle numeric values and match known SHA-256' , async ( ) => {
366- const hashedNumber = await roktManager . hashSha256 ( 42 ) ;
367- const hashedString = await roktManager . hashSha256 ( '42' ) ;
368-
369- // Numeric value should be converted to string and produce same hash
370- expect ( hashedNumber ) . toBe ( hashedString ) ;
371- // Expected SHA-256 hash of '42'
372- expect ( hashedNumber ) . toBe ( '73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049' ) ;
373- } ) ;
374-
375- it ( 'should handle boolean values and match known SHA-256' , async ( ) => {
376- const hashedBoolean = await roktManager . hashSha256 ( true ) ;
377- const hashedString = await roktManager . hashSha256 ( 'true' ) ;
378-
379- // Boolean value should be converted to string and produce same hash
380- expect ( hashedBoolean ) . toBe ( hashedString ) ;
381- // Expected SHA-256 hash of 'true'
382- expect ( hashedBoolean ) . toBe ( 'b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b' ) ;
383- } ) ;
384-
385- it ( 'should hash phone number to known SHA-256 value' , async ( ) => {
386- const hashedPhone = await roktManager . hashSha256 ( '1234567890' ) ;
387-
388- // Expected SHA-256 hash of '1234567890'
389- expect ( hashedPhone ) . toBe ( 'c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646' ) ;
390- } ) ;
391- } ) ;
392-
393277 describe ( '#init' , ( ) => {
394278 it ( 'should initialize the manager with defaults when no config is provided' , ( ) => {
395279 roktManager . init (
0 commit comments