Skip to content

Commit 7a8b5cf

Browse files
committed
test
1 parent 5305182 commit 7a8b5cf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/vuidManager.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { VuidManager } from '../lib/plugins/vuid_manager';
2020
import PersistentKeyValueCache from '../lib/plugins/key_value_cache/persistentKeyValueCache';
2121
import { anyString, anything, instance, mock, resetCalls, verify, when } from 'ts-mockito';
2222
import { LogHandler } from '../lib/modules/logging/models';
23+
import { resolvablePromise } from '../lib/utils/promise/resolvablePromise';
2324

2425
describe('VuidManager', () => {
2526
let mockCache: PersistentKeyValueCache<string>;
@@ -93,4 +94,31 @@ describe('VuidManager', () => {
9394
verify(mockCache.remove(anyString())).once();
9495
expect(manager.vuid).toBeUndefined();
9596
});
97+
98+
it('should sequence configure calls', async() => {
99+
const mockCache = mock<PersistentKeyValueCache>();
100+
when(mockCache.contains(anyString())).thenResolve(true);
101+
when(mockCache.get(anyString())).thenResolve('');
102+
103+
const removePromise = resolvablePromise<boolean>();
104+
when(mockCache.remove(anyString())).thenReturn(removePromise.promise);
105+
when(mockCache.set(anyString(), anything())).thenResolve();
106+
107+
const manager = new VuidManager(instance(mockCache));
108+
109+
// this should try to remove vuid, which should stay pending
110+
manager.configure({ enableVuid: false });
111+
112+
// this should try to get the vuid from store
113+
manager.configure({ enableVuid: true });
114+
verify(mockCache.get(anyString())).never();
115+
116+
removePromise.resolve(true);
117+
//ensure micro task queue is exhaused
118+
for(let i = 0; i < 100; i++) {
119+
await Promise.resolve();
120+
}
121+
122+
verify(mockCache.get(anyString())).once()
123+
});
96124
});

0 commit comments

Comments
 (0)