From 8f2b46fba4a13997616d7ed51816d6c1b7261eae Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 15 Nov 2023 14:29:11 -0600 Subject: [PATCH] test: update tests --- test/Contacts.test.ts | 88 ++++++++++++++++++++-------- test/conversations/JobRunner.test.ts | 19 ++++++ 2 files changed, 82 insertions(+), 25 deletions(-) diff --git a/test/Contacts.test.ts b/test/Contacts.test.ts index 2f28369f1..26285bf80 100644 --- a/test/Contacts.test.ts +++ b/test/Contacts.test.ts @@ -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 () => { diff --git a/test/conversations/JobRunner.test.ts b/test/conversations/JobRunner.test.ts index cfdd6a904..0703ba616 100644 --- a/test/conversations/JobRunner.test.ts +++ b/test/conversations/JobRunner.test.ts @@ -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() + }) })