@commercetools-frontend/sdk 22.2.1 → 22.3.0

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.
@@ -7,49 +7,47 @@ import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
7
7
  import { deepEqual } from 'fast-equals';
8
8
  import { v4 } from 'uuid';
9
9
 
10
+ /**
11
+ * START -->
12
+ * Remove once `@commercetools/sdk-client` exposes proper types.
13
+ */
14
+
15
+ /* <-- END */
16
+
10
17
  const serialize = data => {
11
18
  const undefinedPlaceholder = v4();
12
19
  const placeholderRegexp = new RegExp("\"".concat(undefinedPlaceholder, "\""), 'g');
13
-
14
20
  const mapUndefinedValues = (_k, v) => v === undefined ? undefinedPlaceholder : v;
15
-
16
21
  const withPlaceholders = _JSON$stringify(data, mapUndefinedValues, 2);
17
-
18
22
  return withPlaceholders.replace(placeholderRegexp, 'undefined');
19
23
  };
20
-
21
24
  const throwIfNoMocksArePassed = mocks => {
22
25
  if (!mocks || !_Array$isArray(mocks) || mocks.length === 0) {
23
26
  throw new Error('Missing or invalid argument for `mocks`. Expected an array of mocked actions.');
24
27
  }
25
28
  };
26
-
27
29
  const isSdkAction = action => action.type === 'SDK';
28
-
29
30
  const isSdkMockSuccess = mock => mock.response !== undefined;
30
-
31
31
  const createTestMiddleware = mocks => {
32
- throwIfNoMocksArePassed(mocks); // We clone the mocks so we can keep the user-provided mocks around for
32
+ throwIfNoMocksArePassed(mocks);
33
+
34
+ // We clone the mocks so we can keep the user-provided mocks around for
33
35
  // the debugging message. The mocksStack gets mutated, while mocks
34
36
  // should never be mutated.
35
-
36
37
  const mocksStack = [...mocks];
37
38
  return () => next => action => {
38
39
  var _context;
39
-
40
40
  if (!isSdkAction(action)) {
41
41
  return next(action);
42
42
  }
43
-
44
43
  const index = _findIndexInstanceProperty(mocksStack).call(mocksStack, item => deepEqual(item.action, action));
45
-
46
44
  if (index === -1) throw new Error(_concatInstanceProperty(_context = "Could not find any more mocks for action ".concat(serialize(action), " in ")).call(_context, serialize(mocks)));
47
- const mock = mocksStack[index]; // Mocks should only be used once, so we remove it from the stack.
45
+ const mock = mocksStack[index];
48
46
 
47
+ // Mocks should only be used once, so we remove it from the stack.
49
48
  _spliceInstanceProperty(mocksStack).call(mocksStack, index, 1);
50
-
51
49
  return isSdkMockSuccess(mock) ? _Promise.resolve(mock.response) : _Promise.reject(mock.error);
52
50
  };
53
- }; // eslint-disable-next-line import/prefer-default-export
51
+ };
54
52
 
55
53
  export { createTestMiddleware };