From aec81849641f0654fa6151519ea4bdb2bbe4a6ea Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Tue, 4 Oct 2022 20:56:35 -0700 Subject: [PATCH] cache miss, server confirms miss test --- makefile | 3 +- src/client/tests/webapp/auto-verifier.test.ts | 64 +++++++++++++++++-- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/makefile b/makefile index e6e413d..cee8b56 100644 --- a/makefile +++ b/makefile @@ -19,7 +19,8 @@ build-sass: build: lint build-tsc build-sass test: - npx jest --config src/jest.config.js + npx jest --config src/jest.config.ts + cp ./node_modules/nyc-dark/*.css ./src/coverage/lcov-report/ move: mkdir -p ./dist/client/webapp/font diff --git a/src/client/tests/webapp/auto-verifier.test.ts b/src/client/tests/webapp/auto-verifier.test.ts index 5e4e593..88f6173 100644 --- a/src/client/tests/webapp/auto-verifier.test.ts +++ b/src/client/tests/webapp/auto-verifier.test.ts @@ -304,7 +304,7 @@ describe('fetchAndVerifyIfNeeded tests', () => { expect(av.trustedPromise).toBe(trusted.promise); expect(av.trustedStatus).toBe('fetching'); expect(primaryFunc).toHaveBeenCalled(); - expect(trustedFunc).toHaveBeenCalled(); + expect(trustedFunc).toHaveBeenCalled(); // TODO: Is this the source of the problem? - trustedFunc needs to wait to be called until ensureTrustedFuncReadyFunc is resolved expect(result).toBeUndefined(); expect(ensureTrustedFuncReadyFunc).toHaveBeenCalledTimes(0); @@ -346,9 +346,65 @@ describe('fetchAndVerifyIfNeeded tests', () => { expect(verifyFunc).toHaveBeenCalledTimes(1); }); - /* test('primary null, then trusted with null - cache miss, server confirms miss', async () => { */ - /* expect(false).toBe(true); */ - /* }); */ + test('primary null, then trusted with null - cache miss, server confirms miss', async () => { + const { + nextPrimary, nextTrusted, nextEnsureTrustedFuncReady, nextVerify, + primaryFunc, trustedFunc, ensureTrustedFuncReadyFunc, verifyFunc + } = getManualsAndMocks(); + + const primary = nextPrimary(); + const trusted = nextTrusted(); + const ensureTrustedFuncReady = nextEnsureTrustedFuncReady(); + const verify = nextVerify(); + + const av = new AutoVerifier(primaryFunc, trustedFunc, ensureTrustedFuncReadyFunc, verifyFunc); + const resultPromise = av.fetchAndVerifyIfNeeded(); + let result: BasicWE | null | undefined = undefined; + resultPromise.then(value => { result = value; }); + + expect(av.primaryPromise).toBe(primary.promise); + expect(av.trustedPromise).toBe(trusted.promise); + expect(av.trustedStatus).toBe('fetching'); + expect(primaryFunc).toHaveBeenCalled(); + expect(trustedFunc).toHaveBeenCalled(); + + expect(ensureTrustedFuncReadyFunc).toHaveBeenCalledTimes(0); + primary.resolve(null); + await disjoint(); + + expect(ensureTrustedFuncReadyFunc).toHaveBeenCalled(); + expect(av.primaryPromise).toBe(null); + expect(av.trustedPromise).toBe(trusted.promise); + expect(av.trustedStatus).toBe('verifying'); + + ensureTrustedFuncReady.resolve(); + await disjoint(); + + expect(av.primaryPromise).toBe(null); + expect(av.trustedPromise).toBe(trusted.promise); + expect(av.trustedStatus).toBe('verifying'); + + expect(verifyFunc).toHaveBeenCalledTimes(0); + trusted.resolve(null); + await disjoint(); + + expect(verifyFunc).toHaveBeenCalledWith(null, null); + expect(av.primaryPromise).toBe(null); + expect(av.trustedPromise).toBe(trusted.promise); + expect(av.trustedStatus).toBe('verifying'); + + verify.resolve(true); + await disjoint(); + + expect(av.primaryPromise).toBe(null); + expect(av.trustedPromise).toBe(trusted.promise); + expect(av.trustedStatus).toBe('none'); + + expect(primaryFunc).toHaveBeenCalledTimes(1); + expect(trustedFunc).toHaveBeenCalledTimes(1); + expect(ensureTrustedFuncReadyFunc).toHaveBeenCalledTimes(1); + expect(verifyFunc).toHaveBeenCalledTimes(1); + }); /* test('primary with value, then trusted with null - cache hit, server deleted', async () => { */ /* expect(false).toBe(true); */