primary with null, trusted rejects test
This commit is contained in:
parent
39042c5e47
commit
61f57875f9
@ -558,7 +558,7 @@ describe('fetchAndVerifyIfNeeded tests', () => {
|
||||
});
|
||||
|
||||
test('primary rejects - cache fail', async () => {
|
||||
// expecting the promise to reject, the server to succeed, but the verify function not to be called
|
||||
// expecting the promise to reject, the server to succeed, but the verify function to never be called
|
||||
const {
|
||||
nextPrimary, nextTrusted,
|
||||
primaryFunc, trustedFunc, ensureTrustedFuncReadyFunc, verifyFunc
|
||||
@ -596,6 +596,63 @@ describe('fetchAndVerifyIfNeeded tests', () => {
|
||||
expect(verifyFunc).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('primary with null, trusted rejects - cache miss, failed to ping server', async () => {
|
||||
// expect the promise to reject, but the verify function to never be called
|
||||
const {
|
||||
nextPrimary, nextTrusted, nextEnsureTrustedFuncReady,
|
||||
primaryFunc, trustedFunc, ensureTrustedFuncReadyFunc, verifyFunc
|
||||
} = getManualsAndMocks();
|
||||
|
||||
const primary = nextPrimary();
|
||||
const trusted = nextTrusted();
|
||||
const ensureTrustedFuncReady = nextEnsureTrustedFuncReady();
|
||||
|
||||
const av = new AutoVerifier(primaryFunc, trustedFunc, ensureTrustedFuncReadyFunc, verifyFunc);
|
||||
const resultPromise = av.fetchAndVerifyIfNeeded();
|
||||
let rejection: Error | undefined = undefined;
|
||||
resultPromise.catch(value => { rejection = 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(rejection).toBeUndefined();
|
||||
jest.spyOn(console, 'warn').mockImplementationOnce(() => {}); // suppress the warning
|
||||
trusted.reject(new Error());
|
||||
await disjoint();
|
||||
|
||||
expect(rejection).toBeDefined();
|
||||
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); // notably, this server response will be thrown out
|
||||
expect(ensureTrustedFuncReadyFunc).toHaveBeenCalledTimes(1);
|
||||
expect(verifyFunc).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
// Make sure to do try/catch errors/rejections, verification failures, unverifies in the middle
|
||||
// Multiple tryResolveTrustedPromises
|
||||
// Multiple fetchAndVerifyIfNeeded at the same time
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user