Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Nov 15, 2023
1 parent 3c6a2a4 commit 8f2b46f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 25 deletions.
88 changes: 63 additions & 25 deletions test/Contacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,75 @@ describe('Contacts', () => {
})

it('should retrieve consent state', async () => {
await aliceClient.contacts.deny([bob.address])
await aliceClient.contacts.allow([carol.address])
await aliceClient.contacts.allow([bob.address])
await aliceClient.contacts.deny([carol.address])
await aliceClient.contacts.deny([bob.address])
await aliceClient.contacts.allow([carol.address])
const entries = await bobClient.contacts.refreshConsentList()

expect(aliceClient.contacts.consentState(bob.address)).toBe('denied')
expect(aliceClient.contacts.isAllowed(bob.address)).toBe(false)
expect(aliceClient.contacts.isDenied(bob.address)).toBe(true)
expect(entries.length).toBe(0)

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

aliceClient = await Client.create(alice, {
env: 'local',
})
await bobClient.contacts.deny([alice.address])
await bobClient.contacts.allow([carol.address])
await bobClient.contacts.allow([alice.address])
await bobClient.contacts.deny([carol.address])
await bobClient.contacts.deny([alice.address])
await bobClient.contacts.allow([carol.address])

expect(aliceClient.contacts.consentState(bob.address)).toBe('unknown')
expect(aliceClient.contacts.consentState(carol.address)).toBe('unknown')
expect(bobClient.contacts.consentState(alice.address)).toBe('denied')
expect(bobClient.contacts.isAllowed(alice.address)).toBe(false)
expect(bobClient.contacts.isDenied(alice.address)).toBe(true)

await aliceClient.contacts.refreshConsentList()
expect(bobClient.contacts.consentState(carol.address)).toBe('allowed')
expect(bobClient.contacts.isAllowed(carol.address)).toBe(true)
expect(bobClient.contacts.isDenied(carol.address)).toBe(false)

expect(aliceClient.contacts.consentState(bob.address)).toBe('denied')
expect(aliceClient.contacts.isAllowed(bob.address)).toBe(false)
expect(aliceClient.contacts.isDenied(bob.address)).toBe(true)
bobClient = await Client.create(bob, {
env: 'local',
})

expect(aliceClient.contacts.consentState(carol.address)).toBe('allowed')
expect(aliceClient.contacts.isAllowed(carol.address)).toBe(true)
expect(aliceClient.contacts.isDenied(carol.address)).toBe(false)
expect(bobClient.contacts.consentState(alice.address)).toBe('unknown')
expect(bobClient.contacts.consentState(carol.address)).toBe('unknown')

const latestEntries = await bobClient.contacts.refreshConsentList()

expect(latestEntries.length).toBe(6)
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,
},
])

expect(bobClient.contacts.consentState(alice.address)).toBe('denied')
expect(bobClient.contacts.isAllowed(alice.address)).toBe(false)
expect(bobClient.contacts.isDenied(alice.address)).toBe(true)

expect(bobClient.contacts.consentState(carol.address)).toBe('allowed')
expect(bobClient.contacts.isAllowed(carol.address)).toBe(true)
expect(bobClient.contacts.isDenied(carol.address)).toBe(false)
})

it('should stream consent updates', async () => {
Expand Down
19 changes: 19 additions & 0 deletions test/conversations/JobRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,23 @@ describe('JobRunner', () => {
})
).rejects.toThrow('foo')
})

it('resets the last run time', async () => {
const ppppRunner = new JobRunner('pppp', keystore)
await ppppRunner.run(async () => {})

const { lastRunNs: ppppLastRunNs } = await keystore.getRefreshJob({
jobType: keystoreProto.JobType.JOB_TYPE_REFRESH_PPPP,
})

expect(ppppLastRunNs.gt(0)).toBeTruthy()

await ppppRunner.resetLastRunTime()

const { lastRunNs: ppppLastRunNs2 } = await keystore.getRefreshJob({
jobType: keystoreProto.JobType.JOB_TYPE_REFRESH_PPPP,
})

expect(ppppLastRunNs2.eq(0)).toBeTruthy()
})
})

0 comments on commit 8f2b46f

Please sign in to comment.