diff --git a/packages/js-sdk/src/Contacts.ts b/packages/js-sdk/src/Contacts.ts index 0299fa172..1bbe68c6a 100644 --- a/packages/js-sdk/src/Contacts.ts +++ b/packages/js-sdk/src/Contacts.ts @@ -168,33 +168,30 @@ export class ConsentList { * Process actions and update internal consent list */ processActions(actionsMap: ActionsMap) { - const entries: ConsentListEntry[] = [] // actions to process const actions = Array.from(actionsMap.values()) // update the consent list actions.forEach((action) => { action.allowAddress?.walletAddresses.forEach((address) => { - entries.push(this.allow(address)) + this.allow(address) }) action.denyAddress?.walletAddresses.forEach((address) => { - entries.push(this.deny(address)) + this.deny(address) }) action.allowGroup?.groupIds.forEach((groupId) => { - entries.push(this.allowGroup(groupId)) + this.allowGroup(groupId) }) action.denyGroup?.groupIds.forEach((groupId) => { - entries.push(this.denyGroup(groupId)) + this.denyGroup(groupId) }) action.allowInboxId?.inboxIds.forEach((inboxId) => { - entries.push(this.allowInboxId(inboxId)) + this.allowInboxId(inboxId) }) action.denyInboxId?.inboxIds.forEach((inboxId) => { - entries.push(this.denyInboxId(inboxId)) + this.denyInboxId(inboxId) }) }) - - return entries } async stream(onConnectionLost?: OnConnectionLostCallback) { @@ -261,7 +258,9 @@ export class ConsentList { this.reset() // process actions and update consent list - return this.processActions(actionsMap) + this.processActions(actionsMap) + + return this.entries } async publish(entries: ConsentListEntry[]) { diff --git a/packages/js-sdk/test/Contacts.test.ts b/packages/js-sdk/test/Contacts.test.ts index b768a5deb..0dda58231 100644 --- a/packages/js-sdk/test/Contacts.test.ts +++ b/packages/js-sdk/test/Contacts.test.ts @@ -132,7 +132,7 @@ describe('Contacts', () => { it('should retrieve consent state', async () => { const entries = await bobClient.contacts.refreshConsentList() - expect(entries.length).toBe(0) + expect(entries.size).toBe(0) await bobClient.contacts.deny([alice.address]) await bobClient.contacts.allow([carol.address]) @@ -143,6 +143,7 @@ describe('Contacts', () => { await bobClient.contacts.allowGroups(['foo', 'bar']) await bobClient.contacts.denyGroups(['foo']) await bobClient.contacts.allowGroups(['foo']) + await bobClient.contacts.denyGroups(['bar']) await bobClient.contacts.allowInboxes(['baz', 'qux']) await bobClient.contacts.denyInboxes(['baz']) await bobClient.contacts.allowInboxes(['baz']) @@ -158,86 +159,24 @@ describe('Contacts', () => { expect(bobClient.contacts.inboxConsentState('baz')).toBe('unknown') expect(bobClient.contacts.inboxConsentState('qux')).toBe('unknown') - const latestEntries = await bobClient.contacts.refreshConsentList() - - expect(latestEntries.length).toBe(14) - expect(latestEntries).toEqual([ - { - entryType: 'address', - permissionType: 'denied', - value: alice.address, - }, - { - entryType: 'address', - permissionType: 'allowed', - value: carol.address, - }, - { - entryType: 'address', - permissionType: 'allowed', - value: alice.address, - }, - { - entryType: 'address', - permissionType: 'denied', - value: carol.address, - }, - { - entryType: 'address', - permissionType: 'denied', - value: alice.address, - }, - { - entryType: 'address', - permissionType: 'allowed', - value: carol.address, - }, - { - entryType: 'groupId', - permissionType: 'allowed', - value: 'foo', - }, - { - entryType: 'groupId', - permissionType: 'allowed', - value: 'bar', - }, - { - entryType: 'groupId', - permissionType: 'denied', - value: 'foo', - }, - { - entryType: 'groupId', - permissionType: 'allowed', - value: 'foo', - }, - { - entryType: 'inboxId', - permissionType: 'allowed', - value: 'baz', - }, - { - entryType: 'inboxId', - permissionType: 'allowed', - value: 'qux', - }, - { - entryType: 'inboxId', - permissionType: 'denied', - value: 'baz', - }, - { - entryType: 'inboxId', - permissionType: 'allowed', - value: 'baz', - }, - ]) + const latestEntries = await bobClient.contacts.loadConsentList() + + expect(latestEntries.size).toBe(6) + expect(latestEntries).toEqual( + new Map([ + [`address-${alice.address}`, 'denied'], + [`address-${carol.address}`, 'allowed'], + [`groupId-foo`, 'allowed'], + [`groupId-bar`, 'denied'], + [`inboxId-baz`, 'allowed'], + [`inboxId-qux`, 'allowed'], + ]) + ) expect(bobClient.contacts.consentState(alice.address)).toBe('denied') expect(bobClient.contacts.consentState(carol.address)).toBe('allowed') expect(bobClient.contacts.groupConsentState('foo')).toBe('allowed') - expect(bobClient.contacts.groupConsentState('bar')).toBe('allowed') + expect(bobClient.contacts.groupConsentState('bar')).toBe('denied') expect(bobClient.contacts.inboxConsentState('baz')).toBe('allowed') expect(bobClient.contacts.inboxConsentState('qux')).toBe('allowed') })