@@ -11,6 +11,7 @@ import { NULL_ADDRESS } from 'iexec/utils';
1111import {
1212 MAX_EXPECTED_BLOCKTIME ,
1313 MAX_EXPECTED_WEB2_SERVICES_TIME ,
14+ MAX_EXPECTED_SUBGRAPH_INDEXING_TIME ,
1415 deployRandomDataset ,
1516 getTestWeb3SignerProvider ,
1617 getTestIExecOption ,
@@ -49,11 +50,11 @@ describe('web3telegram.fetchMyContacts()', () => {
4950 } ) ;
5051 expect (
5152 foundContactForASpecificRequester &&
52- foundContactForASpecificRequester . address
53+ foundContactForASpecificRequester . address
5354 ) . toBeDefined ( ) ;
5455 expect (
5556 foundContactForASpecificRequester &&
56- foundContactForASpecificRequester . address
57+ foundContactForASpecificRequester . address
5758 ) . toBe ( protectedData . address . toLocaleLowerCase ( ) ) ;
5859 } ,
5960 MAX_EXPECTED_WEB2_SERVICES_TIME
@@ -141,4 +142,103 @@ describe('web3telegram.fetchMyContacts()', () => {
141142 } ,
142143 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
143144 ) ;
145+
146+ describe ( 'bulkOnly parameter' , ( ) => {
147+ let protectedDataWithBulk : any ;
148+ let protectedDataWithoutBulk : any ;
149+
150+ beforeAll ( async ( ) => {
151+ protectedDataWithBulk = await dataProtector . core . protectData ( {
152+ data : { telegram_chatId : 'bulk123' } ,
153+ name : 'test bulk access' ,
154+ } ) ;
155+ protectedDataWithoutBulk = await dataProtector . core . protectData ( {
156+ data : { telegram_chatId : 'nobulk456' } ,
157+ name : 'test no bulk access' ,
158+ } ) ;
159+ await waitSubgraphIndexing ( ) ;
160+ } , 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME ) ;
161+
162+ it (
163+ 'should return only contacts with bulk access when bulkOnly is true' ,
164+ async ( ) => {
165+ // Grant access with allowBulk: true
166+ await dataProtector . core . grantAccess ( {
167+ authorizedApp : defaultConfig . dappAddress ,
168+ protectedData : protectedDataWithBulk . address ,
169+ authorizedUser : wallet . address ,
170+ allowBulk : true ,
171+ } ) ;
172+
173+ // Grant access with allowBulk: false (or default)
174+ await dataProtector . core . grantAccess ( {
175+ authorizedApp : defaultConfig . dappAddress ,
176+ protectedData : protectedDataWithoutBulk . address ,
177+ authorizedUser : wallet . address ,
178+ allowBulk : false ,
179+ } ) ;
180+
181+ await waitSubgraphIndexing ( ) ;
182+
183+ // Fetch contacts with bulkOnly: true
184+ const contactsWithBulkOnly = await web3telegram . fetchMyContacts ( {
185+ bulkOnly : true ,
186+ } ) ;
187+
188+ // Should only include the contact with bulk access
189+ const bulkContact = contactsWithBulkOnly . find (
190+ ( contact ) => contact . address === protectedDataWithBulk . address . toLowerCase ( )
191+ ) ;
192+ const noBulkContact = contactsWithBulkOnly . find (
193+ ( contact ) => contact . address === protectedDataWithoutBulk . address . toLowerCase ( )
194+ ) ;
195+
196+ expect ( bulkContact ) . toBeDefined ( ) ;
197+ expect ( noBulkContact ) . toBeUndefined ( ) ;
198+ } ,
199+ MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_SUBGRAPH_INDEXING_TIME + MAX_EXPECTED_WEB2_SERVICES_TIME
200+ ) ;
201+
202+ it (
203+ 'should return all contacts when bulkOnly is false' ,
204+ async ( ) => {
205+ // Fetch contacts with bulkOnly: false (default)
206+ const contactsWithoutBulkOnly = await web3telegram . fetchMyContacts ( {
207+ bulkOnly : false ,
208+ } ) ;
209+
210+ // Should include both contacts
211+ const bulkContact = contactsWithoutBulkOnly . find (
212+ ( contact ) => contact . address === protectedDataWithBulk . address . toLowerCase ( )
213+ ) ;
214+ const noBulkContact = contactsWithoutBulkOnly . find (
215+ ( contact ) => contact . address === protectedDataWithoutBulk . address . toLowerCase ( )
216+ ) ;
217+
218+ expect ( bulkContact ) . toBeDefined ( ) ;
219+ expect ( noBulkContact ) . toBeDefined ( ) ;
220+ } ,
221+ MAX_EXPECTED_WEB2_SERVICES_TIME
222+ ) ;
223+
224+ it (
225+ 'should return all contacts when bulkOnly is not specified (default)' ,
226+ async ( ) => {
227+ // Fetch contacts without specifying bulkOnly (defaults to false)
228+ const contactsDefault = await web3telegram . fetchMyContacts ( ) ;
229+
230+ // Should include both contacts
231+ const bulkContact = contactsDefault . find (
232+ ( contact ) => contact . address === protectedDataWithBulk . address . toLowerCase ( )
233+ ) ;
234+ const noBulkContact = contactsDefault . find (
235+ ( contact ) => contact . address === protectedDataWithoutBulk . address . toLowerCase ( )
236+ ) ;
237+
238+ expect ( bulkContact ) . toBeDefined ( ) ;
239+ expect ( noBulkContact ) . toBeDefined ( ) ;
240+ } ,
241+ MAX_EXPECTED_WEB2_SERVICES_TIME
242+ ) ;
243+ } ) ;
144244} ) ;
0 commit comments