Skip to content

Commit d0fb138

Browse files
test(e2e): add bulkOnly parameter e2e tests
- Add bulkOnly parameter tests to fetchMyContacts e2e suite - Add bulkOnly parameter tests to fetchUserContacts e2e suite - Test bulk access filtering and default behavior - Match web3telegram e2e test patterns
1 parent 26c3386 commit d0fb138

File tree

2 files changed

+229
-0
lines changed

2 files changed

+229
-0
lines changed

tests/e2e/fetchMyContacts.test.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { NULL_ADDRESS } from 'iexec/utils';
88
import { IExecWeb3mail } from '../../src/index.js';
99
import {
1010
MAX_EXPECTED_BLOCKTIME,
11+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME,
1112
MAX_EXPECTED_WEB2_SERVICES_TIME,
1213
deployRandomDataset,
1314
getTestConfig,
@@ -144,4 +145,112 @@ describe('web3mail.fetchMyContacts()', () => {
144145
},
145146
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
146147
);
148+
149+
describe('bulkOnly parameter', () => {
150+
let protectedDataWithBulk: any;
151+
let protectedDataWithoutBulk: any;
152+
const defaultConfig = getChainDefaultConfig(DEFAULT_CHAIN_ID);
153+
154+
beforeAll(async () => {
155+
protectedDataWithBulk = await dataProtector.protectData({
156+
data: { email: '[email protected]' },
157+
name: 'test bulk access',
158+
});
159+
protectedDataWithoutBulk = await dataProtector.protectData({
160+
data: { email: '[email protected]' },
161+
name: 'test no bulk access',
162+
});
163+
await waitSubgraphIndexing();
164+
}, 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME);
165+
166+
it(
167+
'should return only contacts with bulk access when bulkOnly is true',
168+
async () => {
169+
// Grant access with allowBulk: true
170+
await dataProtector.grantAccess({
171+
authorizedApp: defaultConfig.dappAddress,
172+
protectedData: protectedDataWithBulk.address,
173+
authorizedUser: wallet.address,
174+
allowBulk: true,
175+
});
176+
177+
// Grant access with allowBulk: false (or default)
178+
await dataProtector.grantAccess({
179+
authorizedApp: defaultConfig.dappAddress,
180+
protectedData: protectedDataWithoutBulk.address,
181+
authorizedUser: wallet.address,
182+
allowBulk: false,
183+
});
184+
185+
await waitSubgraphIndexing();
186+
187+
// Fetch contacts with bulkOnly: true
188+
const contactsWithBulkOnly = await web3mail.fetchMyContacts({
189+
bulkOnly: true,
190+
});
191+
192+
// Should only include the contact with bulk access
193+
const bulkContact = contactsWithBulkOnly.find(
194+
(contact) =>
195+
contact.address === protectedDataWithBulk.address.toLowerCase()
196+
);
197+
const noBulkContact = contactsWithBulkOnly.find(
198+
(contact) =>
199+
contact.address === protectedDataWithoutBulk.address.toLowerCase()
200+
);
201+
202+
expect(bulkContact).toBeDefined();
203+
expect(noBulkContact).toBeUndefined();
204+
},
205+
MAX_EXPECTED_BLOCKTIME +
206+
MAX_EXPECTED_SUBGRAPH_INDEXING_TIME +
207+
MAX_EXPECTED_WEB2_SERVICES_TIME
208+
);
209+
210+
it(
211+
'should return all contacts when bulkOnly is false',
212+
async () => {
213+
// Fetch contacts with bulkOnly: false (default)
214+
const contactsWithoutBulkOnly = await web3mail.fetchMyContacts({
215+
bulkOnly: false,
216+
});
217+
218+
// Should include both contacts
219+
const bulkContact = contactsWithoutBulkOnly.find(
220+
(contact) =>
221+
contact.address === protectedDataWithBulk.address.toLowerCase()
222+
);
223+
const noBulkContact = contactsWithoutBulkOnly.find(
224+
(contact) =>
225+
contact.address === protectedDataWithoutBulk.address.toLowerCase()
226+
);
227+
228+
expect(bulkContact).toBeDefined();
229+
expect(noBulkContact).toBeDefined();
230+
},
231+
MAX_EXPECTED_WEB2_SERVICES_TIME
232+
);
233+
234+
it(
235+
'should return all contacts when bulkOnly is not specified (default)',
236+
async () => {
237+
// Fetch contacts without specifying bulkOnly (defaults to false)
238+
const contactsDefault = await web3mail.fetchMyContacts();
239+
240+
// Should include both contacts
241+
const bulkContact = contactsDefault.find(
242+
(contact) =>
243+
contact.address === protectedDataWithBulk.address.toLowerCase()
244+
);
245+
const noBulkContact = contactsDefault.find(
246+
(contact) =>
247+
contact.address === protectedDataWithoutBulk.address.toLowerCase()
248+
);
249+
250+
expect(bulkContact).toBeDefined();
251+
expect(noBulkContact).toBeDefined();
252+
},
253+
MAX_EXPECTED_WEB2_SERVICES_TIME
254+
);
255+
});
147256
});

tests/e2e/fetchUserContacts.test.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { IExecWeb3mail, WorkflowError } from '../../src/index.js';
1212
import {
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

Comments
 (0)