cozy-client 60.28.0 → 60.28.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3126,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
3126
3126
  CozyClient.hooks = CozyClient.hooks || {};
3127
3127
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3128
3128
 
3129
- CozyClient.version = "60.28.0";
3129
+ CozyClient.version = "60.28.2";
3130
3130
 
3131
3131
  _microee.default.mixin(CozyClient);
3132
3132
 
package/dist/policies.js CHANGED
@@ -25,12 +25,18 @@ var fetchPolicies = {
25
25
  */
26
26
  olderThan: function olderThan(delay) {
27
27
  return function (queryState) {
28
- if (!queryState || !queryState.lastUpdate) {
28
+ if (!queryState) {
29
29
  return true;
30
- } else {
31
- var elapsed = Date.now() - queryState.lastUpdate;
32
- return elapsed > delay;
33
30
  }
31
+
32
+ var lastFetch = Math.max(queryState.lastUpdate || 0, queryState.lastErrorUpdate || 0);
33
+
34
+ if (!lastFetch) {
35
+ return true;
36
+ }
37
+
38
+ var elapsed = Date.now() - lastFetch;
39
+ return elapsed > delay;
34
40
  };
35
41
  },
36
42
 
@@ -0,0 +1,65 @@
1
+ import fetchPolicies from './policies'
2
+
3
+ describe('fetchPolicies.olderThan', () => {
4
+ const NOW = 1600000000000
5
+ const delay = 30 * 1000
6
+ const policy = fetchPolicies.olderThan(delay)
7
+
8
+ beforeEach(() => {
9
+ jest.spyOn(Date, 'now').mockReturnValue(NOW)
10
+ })
11
+
12
+ afterEach(() => {
13
+ jest.restoreAllMocks()
14
+ })
15
+
16
+ it('refetches when there is no query state', () => {
17
+ expect(policy(undefined)).toBe(true)
18
+ })
19
+
20
+ it('refetches when the query has never been fetched nor errored', () => {
21
+ expect(policy({ lastUpdate: null, lastErrorUpdate: null })).toBe(true)
22
+ })
23
+
24
+ it('does not refetch a recent successful query', () => {
25
+ expect(policy({ lastUpdate: NOW - 1000, lastErrorUpdate: null })).toBe(
26
+ false
27
+ )
28
+ })
29
+
30
+ it('refetches a stale successful query', () => {
31
+ expect(policy({ lastUpdate: NOW - delay - 1, lastErrorUpdate: null })).toBe(
32
+ true
33
+ )
34
+ })
35
+
36
+ it('does not refetch right after a recent error (prevents infinite refetch loop on 500)', () => {
37
+ expect(policy({ lastUpdate: null, lastErrorUpdate: NOW - 1000 })).toBe(
38
+ false
39
+ )
40
+ })
41
+
42
+ it('refetches again once the error is older than the delay', () => {
43
+ expect(policy({ lastUpdate: null, lastErrorUpdate: NOW - delay - 1 })).toBe(
44
+ true
45
+ )
46
+ })
47
+
48
+ it('backs off on a recent error even when the last success is stale', () => {
49
+ expect(
50
+ policy({ lastUpdate: NOW - delay - 1, lastErrorUpdate: NOW - 1000 })
51
+ ).toBe(false)
52
+ })
53
+
54
+ it('stays fresh from a recent success even when the last error is stale', () => {
55
+ expect(
56
+ policy({ lastUpdate: NOW - 1000, lastErrorUpdate: NOW - delay - 1 })
57
+ ).toBe(false)
58
+ })
59
+ })
60
+
61
+ describe('fetchPolicies.noFetch', () => {
62
+ it('never fetches', () => {
63
+ expect(fetchPolicies.noFetch()).toBe(false)
64
+ })
65
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "60.28.0",
3
+ "version": "60.28.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -74,5 +74,5 @@
74
74
  "react-native-ios11-devicecheck": "^0.0.3"
75
75
  },
76
76
  "sideEffects": false,
77
- "gitHead": "8eeb721eca10bdd9e48d537b82b5092a81dc2dd3"
77
+ "gitHead": "272fde3c9e8dc4a4472744513ace8b71a8b2c417"
78
78
  }