@@ -6,7 +6,6 @@ jest.mock('../../../util/stats', () => ({
66
77import stats from '../../../util/stats' ;
88import type { WrappedResponse } from './types' ;
9-
109const basePayload = {
1110 responseField : {
1211 access_token : 'ABC' ,
@@ -51,6 +50,9 @@ const baseResponse = {
5150 method : '' ,
5251} ;
5352
53+ const TEST_WORKSPACE_ID = 'ws-1' ;
54+ const TEST_DESTINATION_ID = 'dest-1' ;
55+
5456describe ( 'FB_custom_audience utils test' , ( ) => {
5557 describe ( 'getDataSource function tests' , ( ) => {
5658 it ( 'Should return empty datasource if type and subType are both NA' , ( ) => {
@@ -108,12 +110,12 @@ describe('FB_custom_audience utils test', () => {
108110 expected : [ '59107c750fd5ee2758d1988f2bf12d9f110439221ebdb7997e70d6a2c1c5afda' ] ,
109111 } ,
110112 {
111- name : 'Should not hash field if isHashRequired is set to false (pre-hashed input is passed through as-is) ' ,
113+ name : 'Should not hash field if isHashRequired is set to false' ,
112114 initialData : [ ] ,
113115 isHashRequired : false ,
114116 field : 'FN' ,
115- value : '59107c750fd5ee2758d1988f2bf12d9f110439221ebdb7997e70d6a2c1c5afda ' ,
116- expected : [ '59107c750fd5ee2758d1988f2bf12d9f110439221ebdb7997e70d6a2c1c5afda ' ] ,
117+ value : 'some-name ' ,
118+ expected : [ 'some-name ' ] ,
117119 } ,
118120 {
119121 name : 'Should not hash MADID and just pass value' ,
@@ -212,8 +214,8 @@ describe('FB_custom_audience utils test', () => {
212214 isHashRequired ,
213215 field ,
214216 value ,
215- 'ws-1' ,
216- 'dest-1' ,
217+ TEST_WORKSPACE_ID ,
218+ TEST_DESTINATION_ID ,
217219 ) ;
218220 expect ( result ) . toEqual ( expected ) ;
219221 } ) ;
@@ -229,87 +231,121 @@ describe('FB_custom_audience utils test', () => {
229231 } ) ;
230232
231233 afterEach ( ( ) => {
232- delete process . env . FB_CUSTOM_AUDIENCE_HASHING_VALIDATION_ENABLED ;
234+ delete process . env . AUDIENCE_HASHING_VALIDATION_ENABLED ;
233235 } ) ;
234236
235237 it ( 'Hashing ON + pre-hashed value → emits metric and throws when validation enabled' , ( ) => {
236- process . env . FB_CUSTOM_AUDIENCE_HASHING_VALIDATION_ENABLED = 'true' ;
238+ process . env . AUDIENCE_HASHING_VALIDATION_ENABLED = 'true' ;
237239 expect ( ( ) =>
238- getUpdatedDataElement ( [ ] , true , 'EMAIL' , hashedValue , 'ws-1' , 'dest-1' ) ,
240+ getUpdatedDataElement (
241+ [ ] ,
242+ true ,
243+ 'EMAIL' ,
244+ hashedValue ,
245+ TEST_WORKSPACE_ID ,
246+ TEST_DESTINATION_ID ,
247+ ) ,
239248 ) . toThrow (
240249 'Hashing is enabled but the value for field EMAIL appears to already be hashed. Either disable hashing or send unhashed data.' ,
241250 ) ;
242- expect ( mockStatsIncrement ) . toHaveBeenCalledWith (
243- 'fb_custom_audience_hashing_inconsistency' ,
244- {
245- propertyName : 'EMAIL' ,
246- type : 'hashed_when_hash_enabled' ,
247- workspaceId : 'ws-1' ,
248- destinationId : 'dest-1' ,
249- } ,
250- ) ;
251+ expect ( mockStatsIncrement ) . toHaveBeenCalledWith ( 'audience_hashing_inconsistency' , {
252+ propertyName : 'EMAIL' ,
253+ type : 'hashed_when_hash_enabled' ,
254+ workspaceId : 'ws-1' ,
255+ destinationId : 'dest-1' ,
256+ destType : 'fb_custom_audience' ,
257+ } ) ;
251258 } ) ;
252259
253260 it ( 'Hashing ON + plaintext value → no error, no metric' , ( ) => {
254261 expect ( ( ) =>
255- getUpdatedDataElement ( [ ] , true , 'EMAIL' , plaintextEmail , 'ws-1' , 'dest-1' ) ,
262+ getUpdatedDataElement (
263+ [ ] ,
264+ true ,
265+ 'EMAIL' ,
266+ plaintextEmail ,
267+ TEST_WORKSPACE_ID ,
268+ TEST_DESTINATION_ID ,
269+ ) ,
256270 ) . not . toThrow ( ) ;
257271 expect ( mockStatsIncrement ) . not . toHaveBeenCalled ( ) ;
258272 } ) ;
259273
260274 it ( 'Hashing OFF + plaintext value → emits metric and throws when validation enabled' , ( ) => {
261- process . env . FB_CUSTOM_AUDIENCE_HASHING_VALIDATION_ENABLED = 'true' ;
275+ process . env . AUDIENCE_HASHING_VALIDATION_ENABLED = 'true' ;
262276 expect ( ( ) =>
263- getUpdatedDataElement ( [ ] , false , 'EMAIL' , plaintextEmail , 'ws-1' , 'dest-1' ) ,
277+ getUpdatedDataElement (
278+ [ ] ,
279+ false ,
280+ 'EMAIL' ,
281+ plaintextEmail ,
282+ TEST_WORKSPACE_ID ,
283+ TEST_DESTINATION_ID ,
284+ ) ,
264285 ) . toThrow (
265286 'Hashing is disabled but the value for field EMAIL appears to be unhashed. Either enable hashing or send pre-hashed data.' ,
266287 ) ;
267- expect ( mockStatsIncrement ) . toHaveBeenCalledWith (
268- 'fb_custom_audience_hashing_inconsistency' ,
269- {
270- propertyName : 'EMAIL' ,
271- type : 'unhashed_when_hash_disabled' ,
272- workspaceId : 'ws-1' ,
273- destinationId : 'dest-1' ,
274- } ,
275- ) ;
288+ expect ( mockStatsIncrement ) . toHaveBeenCalledWith ( 'audience_hashing_inconsistency' , {
289+ propertyName : 'EMAIL' ,
290+ type : 'unhashed_when_hash_disabled' ,
291+ workspaceId : 'ws-1' ,
292+ destinationId : 'dest-1' ,
293+ destType : 'fb_custom_audience' ,
294+ } ) ;
276295 } ) ;
277296
278297 it ( 'Hashing OFF + 64-char hex value → no error, no metric' , ( ) => {
279298 expect ( ( ) =>
280- getUpdatedDataElement ( [ ] , false , 'EMAIL' , hashedValue , 'ws-1' , 'dest-1' ) ,
299+ getUpdatedDataElement (
300+ [ ] ,
301+ false ,
302+ 'EMAIL' ,
303+ hashedValue ,
304+ TEST_WORKSPACE_ID ,
305+ TEST_DESTINATION_ID ,
306+ ) ,
281307 ) . not . toThrow ( ) ;
282308 expect ( mockStatsIncrement ) . not . toHaveBeenCalled ( ) ;
283309 } ) ;
284310
285311 it ( 'Validation disabled (default) + hashing ON + pre-hashed value → emits metric but no throw' , ( ) => {
286312 expect ( ( ) =>
287- getUpdatedDataElement ( [ ] , true , 'EMAIL' , hashedValue , 'ws-1' , 'dest-1' ) ,
313+ getUpdatedDataElement (
314+ [ ] ,
315+ true ,
316+ 'EMAIL' ,
317+ hashedValue ,
318+ TEST_WORKSPACE_ID ,
319+ TEST_DESTINATION_ID ,
320+ ) ,
288321 ) . not . toThrow ( ) ;
289- expect ( mockStatsIncrement ) . toHaveBeenCalledWith (
290- 'fb_custom_audience_hashing_inconsistency' ,
291- {
292- propertyName : 'EMAIL' ,
293- type : 'hashed_when_hash_enabled' ,
294- workspaceId : 'ws-1' ,
295- destinationId : 'dest-1' ,
296- } ,
297- ) ;
322+ expect ( mockStatsIncrement ) . toHaveBeenCalledWith ( 'audience_hashing_inconsistency' , {
323+ propertyName : 'EMAIL' ,
324+ type : 'hashed_when_hash_enabled' ,
325+ workspaceId : 'ws-1' ,
326+ destinationId : 'dest-1' ,
327+ destType : 'fb_custom_audience' ,
328+ } ) ;
298329 } ) ;
299330
300331 it ( 'Validation disabled (default) + hashing OFF + plaintext value → emits metric but no throw' , ( ) => {
301332 expect ( ( ) =>
302- getUpdatedDataElement ( [ ] , false , 'EMAIL' , plaintextEmail , 'ws-1' , 'dest-1' ) ,
333+ getUpdatedDataElement (
334+ [ ] ,
335+ false ,
336+ 'EMAIL' ,
337+ plaintextEmail ,
338+ TEST_WORKSPACE_ID ,
339+ TEST_DESTINATION_ID ,
340+ ) ,
303341 ) . not . toThrow ( ) ;
304- expect ( mockStatsIncrement ) . toHaveBeenCalledWith (
305- 'fb_custom_audience_hashing_inconsistency' ,
306- {
307- propertyName : 'EMAIL' ,
308- type : 'unhashed_when_hash_disabled' ,
309- workspaceId : 'ws-1' ,
310- destinationId : 'dest-1' ,
311- } ,
312- ) ;
342+ expect ( mockStatsIncrement ) . toHaveBeenCalledWith ( 'audience_hashing_inconsistency' , {
343+ propertyName : 'EMAIL' ,
344+ type : 'unhashed_when_hash_disabled' ,
345+ workspaceId : 'ws-1' ,
346+ destinationId : 'dest-1' ,
347+ destType : 'fb_custom_audience' ,
348+ } ) ;
313349 } ) ;
314350 } ) ;
315351 } ) ;
0 commit comments