@@ -11,6 +11,7 @@ import {
1111import { IExecWeb3mail , WorkflowError } from '../../src/index.js' ;
1212import {
1313 MAX_EXPECTED_BLOCKTIME ,
14+ MAX_EXPECTED_SUBGRAPH_INDEXING_TIME ,
1415 MAX_EXPECTED_WEB2_SERVICES_TIME ,
1516 getTestConfig ,
1617 waitSubgraphIndexing ,
@@ -247,4 +248,123 @@ describe('web3mail.fetchMyContacts()', () => {
247248 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
248249 ) ;
249250 } ) ;
251+
252+ describe ( 'bulkOnly parameter' , ( ) => {
253+ let protectedDataWithBulk : ProtectedDataWithSecretProps ;
254+ let protectedDataWithoutBulk : ProtectedDataWithSecretProps ;
255+ let userWithAccess : string ;
256+
257+ beforeAll (
258+ async ( ) => {
259+ userWithAccess = Wallet . createRandom ( ) . address ;
260+ protectedDataWithBulk = await dataProtector . protectData ( {
261+ data :
{ email :
'[email protected] ' } , 262+ name : 'test bulk access user' ,
263+ } ) ;
264+ protectedDataWithoutBulk = await dataProtector . protectData ( {
265+ data :
{ email :
'[email protected] ' } , 266+ name : 'test no bulk access user' ,
267+ } ) ;
268+ await waitSubgraphIndexing ( ) ;
269+ } ,
270+ 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
271+ ) ;
272+
273+ it (
274+ 'should return only contacts with bulk access when bulkOnly is true' ,
275+ async ( ) => {
276+ const defaultConfig = getChainDefaultConfig ( DEFAULT_CHAIN_ID ) ;
277+ expect ( defaultConfig ) . not . toBeNull ( ) ;
278+
279+ // Grant access with allowBulk: true
280+ await dataProtector . grantAccess ( {
281+ authorizedApp : defaultConfig ! . dappAddress ,
282+ protectedData : protectedDataWithBulk . address ,
283+ authorizedUser : userWithAccess ,
284+ allowBulk : true ,
285+ } ) ;
286+
287+ // Grant access with allowBulk: false (or default)
288+ await dataProtector . grantAccess ( {
289+ authorizedApp : defaultConfig ! . dappAddress ,
290+ protectedData : protectedDataWithoutBulk . address ,
291+ authorizedUser : userWithAccess ,
292+ allowBulk : false ,
293+ } ) ;
294+
295+ await waitSubgraphIndexing ( ) ;
296+
297+ // Fetch contacts with bulkOnly: true
298+ const contactsWithBulkOnly = await web3mail . fetchUserContacts ( {
299+ userAddress : userWithAccess ,
300+ bulkOnly : true ,
301+ } ) ;
302+
303+ // Should only include the contact with bulk access
304+ const bulkContact = contactsWithBulkOnly . find (
305+ ( contact ) =>
306+ contact . address === protectedDataWithBulk . address . toLowerCase ( )
307+ ) ;
308+ const noBulkContact = contactsWithBulkOnly . find (
309+ ( contact ) =>
310+ contact . address === protectedDataWithoutBulk . address . toLowerCase ( )
311+ ) ;
312+
313+ expect ( bulkContact ) . toBeDefined ( ) ;
314+ expect ( noBulkContact ) . toBeUndefined ( ) ;
315+ } ,
316+ MAX_EXPECTED_BLOCKTIME +
317+ MAX_EXPECTED_SUBGRAPH_INDEXING_TIME +
318+ MAX_EXPECTED_WEB2_SERVICES_TIME
319+ ) ;
320+
321+ it (
322+ 'should return all contacts when bulkOnly is false' ,
323+ async ( ) => {
324+ // Fetch contacts with bulkOnly: false
325+ const contactsWithoutBulkOnly = await web3mail . fetchUserContacts ( {
326+ userAddress : userWithAccess ,
327+ bulkOnly : false ,
328+ } ) ;
329+
330+ // Should include both contacts
331+ const bulkContact = contactsWithoutBulkOnly . find (
332+ ( contact ) =>
333+ contact . address === protectedDataWithBulk . address . toLowerCase ( )
334+ ) ;
335+ const noBulkContact = contactsWithoutBulkOnly . find (
336+ ( contact ) =>
337+ contact . address === protectedDataWithoutBulk . address . toLowerCase ( )
338+ ) ;
339+
340+ expect ( bulkContact ) . toBeDefined ( ) ;
341+ expect ( noBulkContact ) . toBeDefined ( ) ;
342+ } ,
343+ MAX_EXPECTED_WEB2_SERVICES_TIME
344+ ) ;
345+
346+ it (
347+ 'should return all contacts when bulkOnly is not specified (default)' ,
348+ async ( ) => {
349+ // Fetch contacts without specifying bulkOnly (defaults to false)
350+ const contactsDefault = await web3mail . fetchUserContacts ( {
351+ userAddress : userWithAccess ,
352+ } ) ;
353+
354+ // Should include both contacts
355+ const bulkContact = contactsDefault . find (
356+ ( contact ) =>
357+ contact . address === protectedDataWithBulk . address . toLowerCase ( )
358+ ) ;
359+ const noBulkContact = contactsDefault . find (
360+ ( contact ) =>
361+ contact . address === protectedDataWithoutBulk . address . toLowerCase ( )
362+ ) ;
363+
364+ expect ( bulkContact ) . toBeDefined ( ) ;
365+ expect ( noBulkContact ) . toBeDefined ( ) ;
366+ } ,
367+ MAX_EXPECTED_WEB2_SERVICES_TIME
368+ ) ;
369+ } ) ;
250370} ) ;
0 commit comments