Skip to content

Commit

Permalink
test: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Oct 26, 2023
1 parent a06ce53 commit 79a3dc0
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions test/Contacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let bobClient: Client
let carolClient: Client

describe('Contacts', () => {
beforeAll(async () => {
beforeEach(async () => {
aliceClient = await Client.create(alice, {
env: 'local',
enableConsentList: true,
Expand All @@ -38,18 +38,56 @@ describe('Contacts', () => {
expect(aliceClient.contacts.isAllowed(bob.address)).toBe(true)
expect(aliceClient.contacts.isBlocked(bob.address)).toBe(false)

await aliceClient.contacts.block([carol.address])
expect(aliceClient.contacts.consentState(carol.address)).toBe('blocked')
expect(aliceClient.contacts.isAllowed(carol.address)).toBe(false)
expect(aliceClient.contacts.isBlocked(carol.address)).toBe(true)

await aliceClient.contacts.block([bob.address])
expect(aliceClient.contacts.consentState(bob.address)).toBe('blocked')
expect(aliceClient.contacts.isAllowed(bob.address)).toBe(false)
expect(aliceClient.contacts.isBlocked(bob.address)).toBe(true)
})

it('should allow an address when a conversation is started', async () => {
const conversation = await aliceClient.conversations.newConversation(
carol.address
)

expect(aliceClient.contacts.consentState(carol.address)).toBe('allowed')
expect(aliceClient.contacts.isAllowed(carol.address)).toBe(true)
expect(aliceClient.contacts.isBlocked(carol.address)).toBe(false)

expect(conversation.isAllowed).toBe(true)
expect(conversation.isBlocked).toBe(false)
expect(conversation.consentState).toBe('allowed')
})

it('should allow or block an address from a conversation', async () => {
const conversation = await aliceClient.conversations.newConversation(
carol.address
)

await conversation.block()

expect(aliceClient.contacts.consentState(carol.address)).toBe('blocked')
expect(aliceClient.contacts.isAllowed(carol.address)).toBe(false)
expect(aliceClient.contacts.isBlocked(carol.address)).toBe(true)

expect(conversation.isAllowed).toBe(false)
expect(conversation.isBlocked).toBe(true)
expect(conversation.consentState).toBe('blocked')

await conversation.allow()

expect(aliceClient.contacts.consentState(carol.address)).toBe('allowed')
expect(aliceClient.contacts.isAllowed(carol.address)).toBe(true)
expect(aliceClient.contacts.isBlocked(carol.address)).toBe(false)

expect(conversation.isAllowed).toBe(true)
expect(conversation.isBlocked).toBe(false)
expect(conversation.consentState).toBe('allowed')
})

it('should retrieve consent state', async () => {
await aliceClient.contacts.block([bob.address])
await aliceClient.contacts.allow([carol.address])

aliceClient = await Client.create(alice, {
env: 'local',
enableConsentList: true,
Expand All @@ -60,11 +98,12 @@ describe('Contacts', () => {

await aliceClient.contacts.refreshConsentList()

expect(aliceClient.contacts.consentState(carol.address)).toBe('blocked')
expect(aliceClient.contacts.isAllowed(carol.address)).toBe(false)
expect(aliceClient.contacts.isBlocked(carol.address)).toBe(true)
expect(aliceClient.contacts.consentState(bob.address)).toBe('blocked')
expect(aliceClient.contacts.isAllowed(bob.address)).toBe(false)
expect(aliceClient.contacts.isBlocked(bob.address)).toBe(true)

expect(aliceClient.contacts.consentState(carol.address)).toBe('allowed')
expect(aliceClient.contacts.isAllowed(carol.address)).toBe(true)
expect(aliceClient.contacts.isBlocked(carol.address)).toBe(false)
})
})

0 comments on commit 79a3dc0

Please sign in to comment.