add test for unverify during verify
This commit is contained in:
parent
bae579da86
commit
0df23134a1
@ -826,7 +826,7 @@ describe('fetchAndVerifyIfNeeded tests', () => {
|
|||||||
expect(verifyFunc).toHaveBeenCalledTimes(1);
|
expect(verifyFunc).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('primary null, unverify during first trusted, then trusted with value - cache miss, unverify, return from server', async () => {
|
test('primary null, unverify during first trusted fetch, second trusted with value - cache miss, unverify during fetch, return from server', async () => {
|
||||||
const {
|
const {
|
||||||
nextPrimary, nextTrusted, nextVerify,
|
nextPrimary, nextTrusted, nextVerify,
|
||||||
primaryFunc, trustedFunc, verifyFunc
|
primaryFunc, trustedFunc, verifyFunc
|
||||||
@ -896,6 +896,66 @@ describe('fetchAndVerifyIfNeeded tests', () => {
|
|||||||
expect(verifyFunc).toHaveBeenCalledTimes(1);
|
expect(verifyFunc).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('primary null, unverify during verify, result is original trusted - cache miss, unverify during verify, return from server', async () => {
|
||||||
|
const {
|
||||||
|
nextPrimary, nextTrusted, nextVerify,
|
||||||
|
primaryFunc, trustedFunc, verifyFunc
|
||||||
|
} = getManualsAndMocks();
|
||||||
|
|
||||||
|
const primary = nextPrimary();
|
||||||
|
const trusted = nextTrusted();
|
||||||
|
const verify = nextVerify();
|
||||||
|
|
||||||
|
const av = new AutoVerifier(primaryFunc, trustedFunc, 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).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
primary.resolve(null);
|
||||||
|
await disjoint();
|
||||||
|
|
||||||
|
expect(av.primaryPromise).toBe(null);
|
||||||
|
expect(av.trustedPromise).toBe(trusted.promise);
|
||||||
|
expect(av.trustedStatus).toBe('verifying');
|
||||||
|
|
||||||
|
expect(verifyFunc).toHaveBeenCalledTimes(0);
|
||||||
|
trusted.resolve(new BasicWE(2));
|
||||||
|
await disjoint();
|
||||||
|
|
||||||
|
expect(verifyFunc).toHaveBeenCalledWith(null, new BasicWE(2));
|
||||||
|
expect(av.primaryPromise).toBe(null);
|
||||||
|
expect(av.trustedPromise).toBe(trusted.promise);
|
||||||
|
expect(av.trustedStatus).toBe('verifying');
|
||||||
|
|
||||||
|
av.unverify(); // effectively during the verify function call
|
||||||
|
|
||||||
|
expect(av.primaryPromise).toBe(null);
|
||||||
|
expect(av.trustedPromise).toBe(null);
|
||||||
|
expect(av.trustedStatus).toBe('none');
|
||||||
|
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
verify.resolve(true);
|
||||||
|
await disjoint();
|
||||||
|
|
||||||
|
// result is the value of the trusted promise, but the trusted will be re-called on next fetch
|
||||||
|
expect(result).toEqual(new BasicWE(2));
|
||||||
|
expect(av.primaryPromise).toBe(null);
|
||||||
|
expect(av.trustedPromise).toBe(null);
|
||||||
|
expect(av.trustedStatus).toBe('none');
|
||||||
|
|
||||||
|
await disjoint(); // sanity check
|
||||||
|
|
||||||
|
expect(primaryFunc).toHaveBeenCalledTimes(1);
|
||||||
|
expect(trustedFunc).toHaveBeenCalledTimes(1);
|
||||||
|
expect(verifyFunc).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
// Make sure to do try/catch errors/rejections, verification failures, unverifies in the middle
|
// Make sure to do try/catch errors/rejections, verification failures, unverifies in the middle
|
||||||
// Multiple tryResolveTrustedPromises - multiple fetchAndVerifyIfNeeded at the same time
|
// Multiple tryResolveTrustedPromises - multiple fetchAndVerifyIfNeeded at the same time
|
||||||
// Trusted resolves *BEFORE* ensureTrustedFuncReady
|
// Trusted resolves *BEFORE* ensureTrustedFuncReady
|
||||||
|
Loading…
Reference in New Issue
Block a user