cache miss, server confirms miss test

This commit is contained in:
Michael Peters 2022-10-04 20:56:35 -07:00
parent 9ff09dc8cb
commit aec8184964
2 changed files with 62 additions and 5 deletions

View File

@ -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

View File

@ -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); */