Add test for cacheTime w release buffer
@@ -72,7 +72,9 @@ beforeEach(() => {
});
});
environment = new Environment({
- store: new Store(new RecordSource()),
+ store: new Store(new RecordSource(), {
+ gcReleaseBufferSize: 1,
+ }),
network: Network.create(fetch),
});
const environmentCheck = environment.check;
@@ -257,6 +259,31 @@ describe('store-or-network', () => {
expect(preloaded.source).toBe(null);
});
+ it('resolves from cache with cacheTime if data and query are available and operation is in the release buffer', () => {
+ const disposable = environment.retain(operation);
+ disposable.dispose();
+ const fetchTime = Date.now();
+ jest.spyOn(global.Date, 'now').mockImplementation(() => fetchTime);
+ environment.commitPayload(operation, response.data);
+ expect(environment.check(operation)).toEqual({
+ status: 'available',
+ fetchTime,
+ });
+ check.mockClear();
+ PreloadableQueryRegistry.set(query.params.id, query);
+
+ const preloaded = preloadQuery_DEPRECATED(environment, params, variables);
+ expect(preloaded.source).toBe(null);
+ expect(preloaded.status).toEqual({
+ cacheConfig: {force: true},
+ source: 'cache',
+ cacheTime: fetchTime,
+ });
+ expect(check).toBeCalledTimes(1);
+ expect(fetch).toBeCalledTimes(0);
+ expect(preloaded.source).toBe(null);
+ });
+
it('resolves from cache if data is available with a concrete query', () => {
environment.commitPayload(operation, response.data);
expect(environment.check(operation)).toEqual({
