@edx/frontend-platform 3.6.1 → 4.0.1

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.
@@ -23,22 +23,47 @@ var MockAnalyticsService = /*#__PURE__*/_createClass(function MockAnalyticsServi
23
23
  _this.loggingService.logError('Identify must be called before other tracking events.');
24
24
  }
25
25
  }));
26
+ /**
27
+ * Returns a resolved promise.
28
+ *
29
+ * @returns {Promise} The promise returned by HttpClient.post.
30
+ */
26
31
  _defineProperty(this, "sendTrackingLogEvent", jest.fn(function () {
27
32
  return Promise.resolve();
28
33
  }));
34
+ /**
35
+ * No-op, but records that identify has been called.
36
+ *
37
+ * @param {string} userId
38
+ * @throws {Error} If userId argument is not supplied.
39
+ */
29
40
  _defineProperty(this, "identifyAuthenticatedUser", jest.fn(function (userId) {
30
41
  if (!userId) {
31
42
  throw new Error('UserId is required for identifyAuthenticatedUser.');
32
43
  }
33
44
  _this.hasIdentifyBeenCalled = true;
34
45
  }));
46
+ /**
47
+ * No-op, but records that it has been called to prevent double-identification.
48
+ * @returns {Promise} A resolved promise.
49
+ */
35
50
  _defineProperty(this, "identifyAnonymousUser", jest.fn(function () {
36
51
  _this.hasIdentifyBeenCalled = true;
37
52
  return Promise.resolve();
38
53
  }));
54
+ /**
55
+ * Logs the event to the console.
56
+ *
57
+ * Checks whether identify has been called, logging an error to the logging service if not.
58
+ */
39
59
  _defineProperty(this, "sendTrackEvent", jest.fn(function () {
40
60
  _this.checkIdentifyCalled();
41
61
  }));
62
+ /**
63
+ * Logs the event to the console.
64
+ *
65
+ * Checks whether identify has been called, logging an error to the logging service if not.
66
+ */
42
67
  _defineProperty(this, "sendPageEvent", jest.fn(function () {
43
68
  _this.checkIdentifyCalled();
44
69
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"MockAnalyticsService.js","names":["MockAnalyticsService","_createClass","_ref","_this","httpClient","loggingService","_classCallCheck","_defineProperty","jest","fn","hasIdentifyBeenCalled","logError","Promise","resolve","userId","Error","checkIdentifyCalled"],"sources":["../../src/analytics/MockAnalyticsService.js"],"sourcesContent":["/**\n * The MockAnalyticsService implements all functions of AnalyticsService as Jest mocks (jest.fn())).\n * It emulates the behavior of a real analytics service but witohut making any requests. It has no\n * other functionality.\n *\n * @implements {AnalyticsService}\n * @memberof module:Analytics\n */\nclass MockAnalyticsService {\n static hasIdentifyBeenCalled = false;\n\n constructor({ httpClient, loggingService }) {\n this.loggingService = loggingService;\n this.httpClient = httpClient;\n }\n\n checkIdentifyCalled = jest.fn(() => {\n if (!this.hasIdentifyBeenCalled) {\n this.loggingService.logError('Identify must be called before other tracking events.');\n }\n });\n\n /**\n * Returns a resolved promise.\n *\n * @returns {Promise} The promise returned by HttpClient.post.\n */\n sendTrackingLogEvent = jest.fn(() => Promise.resolve());\n\n /**\n * No-op, but records that identify has been called.\n *\n * @param {string} userId\n * @throws {Error} If userId argument is not supplied.\n */\n identifyAuthenticatedUser = jest.fn((userId) => {\n if (!userId) {\n throw new Error('UserId is required for identifyAuthenticatedUser.');\n }\n this.hasIdentifyBeenCalled = true;\n });\n\n /**\n * No-op, but records that it has been called to prevent double-identification.\n * @returns {Promise} A resolved promise.\n */\n identifyAnonymousUser = jest.fn(() => {\n this.hasIdentifyBeenCalled = true;\n return Promise.resolve();\n });\n\n /**\n * Logs the event to the console.\n *\n * Checks whether identify has been called, logging an error to the logging service if not.\n */\n sendTrackEvent = jest.fn(() => {\n this.checkIdentifyCalled();\n });\n\n /**\n * Logs the event to the console.\n *\n * Checks whether identify has been called, logging an error to the logging service if not.\n */\n sendPageEvent = jest.fn(() => {\n this.checkIdentifyCalled();\n });\n}\n\nexport default MockAnalyticsService;\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,IAQMA,oBAAoB,gBAAAC,YAAA,CAGxB,SAAAD,qBAAAE,IAAA,EAA4C;EAAA,IAAAC,KAAA;EAAA,IAA9BC,UAAU,GAAAF,IAAA,CAAVE,UAAU;IAAEC,cAAc,GAAAH,IAAA,CAAdG,cAAc;EAAAC,eAAA,OAAAN,oBAAA;EAAAO,eAAA,8BAKlBC,IAAI,CAACC,EAAE,CAAC,YAAM;IAClC,IAAI,CAACN,KAAI,CAACO,qBAAqB,EAAE;MAC/BP,KAAI,CAACE,cAAc,CAACM,QAAQ,CAAC,uDAAuD,CAAC;IACvF;EACF,CAAC,CAAC;EAAAJ,eAAA,+BAOqBC,IAAI,CAACC,EAAE,CAAC;IAAA,OAAMG,OAAO,CAACC,OAAO,EAAE;EAAA,EAAC;EAAAN,eAAA,oCAQ3BC,IAAI,CAACC,EAAE,CAAC,UAACK,MAAM,EAAK;IAC9C,IAAI,CAACA,MAAM,EAAE;MACX,MAAM,IAAIC,KAAK,CAAC,mDAAmD,CAAC;IACtE;IACAZ,KAAI,CAACO,qBAAqB,GAAG,IAAI;EACnC,CAAC,CAAC;EAAAH,eAAA,gCAMsBC,IAAI,CAACC,EAAE,CAAC,YAAM;IACpCN,KAAI,CAACO,qBAAqB,GAAG,IAAI;IACjC,OAAOE,OAAO,CAACC,OAAO,EAAE;EAC1B,CAAC,CAAC;EAAAN,eAAA,yBAOeC,IAAI,CAACC,EAAE,CAAC,YAAM;IAC7BN,KAAI,CAACa,mBAAmB,EAAE;EAC5B,CAAC,CAAC;EAAAT,eAAA,wBAOcC,IAAI,CAACC,EAAE,CAAC,YAAM;IAC5BN,KAAI,CAACa,mBAAmB,EAAE;EAC5B,CAAC,CAAC;EAvDA,IAAI,CAACX,cAAc,GAAGA,cAAc;EACpC,IAAI,CAACD,UAAU,GAAGA,UAAU;AAC9B,CAAC;AAAAG,eAAA,CANGP,oBAAoB,2BACO,KAAK;AA6DtC,eAAeA,oBAAoB"}
1
+ {"version":3,"file":"MockAnalyticsService.js","names":["MockAnalyticsService","_createClass","_ref","_this","httpClient","loggingService","_classCallCheck","_defineProperty","jest","fn","hasIdentifyBeenCalled","logError","Promise","resolve","userId","Error","checkIdentifyCalled"],"sources":["../../src/analytics/MockAnalyticsService.js"],"sourcesContent":["/**\n * The MockAnalyticsService implements all functions of AnalyticsService as Jest mocks (jest.fn())).\n * It emulates the behavior of a real analytics service but witohut making any requests. It has no\n * other functionality.\n *\n * @implements {AnalyticsService}\n * @memberof module:Analytics\n */\nclass MockAnalyticsService {\n static hasIdentifyBeenCalled = false;\n\n constructor({ httpClient, loggingService }) {\n this.loggingService = loggingService;\n this.httpClient = httpClient;\n }\n\n checkIdentifyCalled = jest.fn(() => {\n if (!this.hasIdentifyBeenCalled) {\n this.loggingService.logError('Identify must be called before other tracking events.');\n }\n });\n\n /**\n * Returns a resolved promise.\n *\n * @returns {Promise} The promise returned by HttpClient.post.\n */\n sendTrackingLogEvent = jest.fn(() => Promise.resolve());\n\n /**\n * No-op, but records that identify has been called.\n *\n * @param {string} userId\n * @throws {Error} If userId argument is not supplied.\n */\n identifyAuthenticatedUser = jest.fn((userId) => {\n if (!userId) {\n throw new Error('UserId is required for identifyAuthenticatedUser.');\n }\n this.hasIdentifyBeenCalled = true;\n });\n\n /**\n * No-op, but records that it has been called to prevent double-identification.\n * @returns {Promise} A resolved promise.\n */\n identifyAnonymousUser = jest.fn(() => {\n this.hasIdentifyBeenCalled = true;\n return Promise.resolve();\n });\n\n /**\n * Logs the event to the console.\n *\n * Checks whether identify has been called, logging an error to the logging service if not.\n */\n sendTrackEvent = jest.fn(() => {\n this.checkIdentifyCalled();\n });\n\n /**\n * Logs the event to the console.\n *\n * Checks whether identify has been called, logging an error to the logging service if not.\n */\n sendPageEvent = jest.fn(() => {\n this.checkIdentifyCalled();\n });\n}\n\nexport default MockAnalyticsService;\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,IAQMA,oBAAoB,gBAAAC,YAAA,CAGxB,SAAAD,qBAAAE,IAAA,EAA4C;EAAA,IAAAC,KAAA;EAAA,IAA9BC,UAAU,GAAAF,IAAA,CAAVE,UAAU;IAAEC,cAAc,GAAAH,IAAA,CAAdG,cAAc;EAAAC,eAAA,OAAAN,oBAAA;EAAAO,eAAA,8BAKlBC,IAAI,CAACC,EAAE,CAAC,YAAM;IAClC,IAAI,CAACN,KAAI,CAACO,qBAAqB,EAAE;MAC/BP,KAAI,CAACE,cAAc,CAACM,QAAQ,CAAC,uDAAuD,CAAC;IACvF;EACF,CAAC,CAAC;EAEF;AACF;AACA;AACA;AACA;EAJEJ,eAAA,+BAKuBC,IAAI,CAACC,EAAE,CAAC;IAAA,OAAMG,OAAO,CAACC,OAAO,EAAE;EAAA,EAAC;EAEvD;AACF;AACA;AACA;AACA;AACA;EALEN,eAAA,oCAM4BC,IAAI,CAACC,EAAE,CAAC,UAACK,MAAM,EAAK;IAC9C,IAAI,CAACA,MAAM,EAAE;MACX,MAAM,IAAIC,KAAK,CAAC,mDAAmD,CAAC;IACtE;IACAZ,KAAI,CAACO,qBAAqB,GAAG,IAAI;EACnC,CAAC,CAAC;EAEF;AACF;AACA;AACA;EAHEH,eAAA,gCAIwBC,IAAI,CAACC,EAAE,CAAC,YAAM;IACpCN,KAAI,CAACO,qBAAqB,GAAG,IAAI;IACjC,OAAOE,OAAO,CAACC,OAAO,EAAE;EAC1B,CAAC,CAAC;EAEF;AACF;AACA;AACA;AACA;EAJEN,eAAA,yBAKiBC,IAAI,CAACC,EAAE,CAAC,YAAM;IAC7BN,KAAI,CAACa,mBAAmB,EAAE;EAC5B,CAAC,CAAC;EAEF;AACF;AACA;AACA;AACA;EAJET,eAAA,wBAKgBC,IAAI,CAACC,EAAE,CAAC,YAAM;IAC5BN,KAAI,CAACa,mBAAmB,EAAE;EAC5B,CAAC,CAAC;EAvDA,IAAI,CAACX,cAAc,GAAGA,cAAc;EACpC,IAAI,CAACD,UAAU,GAAGA,UAAU;AAC9B,CAAC;AAAAG,eAAA,CANGP,oBAAoB,2BACO,KAAK;AA6DtC,eAAeA,oBAAoB"}
@@ -99,39 +99,128 @@ var MockAuthService = /*#__PURE__*/function () {
99
99
  function MockAuthService(options) {
100
100
  var _this = this;
101
101
  _classCallCheck(this, MockAuthService);
102
+ /**
103
+ * A Jest mock function (jest.fn())
104
+ *
105
+ * Gets the authenticated HTTP client instance, which is an axios client wrapped in
106
+ * MockAdapter from axios-mock-adapter.
107
+ *
108
+ * @returns {HttpClient} An HttpClient wrapped in MockAdapter.
109
+ */
102
110
  _defineProperty(this, "getAuthenticatedHttpClient", jest.fn(function () {
103
111
  return _this.authenticatedHttpClient;
104
112
  }));
113
+ /**
114
+ * A Jest mock function (jest.fn())
115
+ *
116
+ * Gets the unauthenticated HTTP client instance, which is an axios client wrapped in
117
+ * MockAdapter from axios-mock-adapter.
118
+ *
119
+ * @returns {HttpClient} An HttpClient wrapped in MockAdapter.
120
+ */
105
121
  _defineProperty(this, "getHttpClient", jest.fn(function () {
106
122
  return _this.httpClient;
107
123
  }));
124
+ /**
125
+ * A Jest mock function (jest.fn())
126
+ *
127
+ * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.
128
+ *
129
+ * ```
130
+ * const url = getLoginRedirectUrl('http://localhost/mypage');
131
+ * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage
132
+ * ```
133
+ *
134
+ * @param {string} redirectUrl The URL the user should be redirected to after logging in.
135
+ */
108
136
  _defineProperty(this, "getLoginRedirectUrl", jest.fn(function () {
109
137
  var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
110
138
  return "".concat(_this.config.LOGIN_URL, "?next=").concat(encodeURIComponent(redirectUrl));
111
139
  }));
140
+ /**
141
+ * A Jest mock function (jest.fn())
142
+ *
143
+ * Redirects the user to the logout page in the real implementation. Is a no-op here.
144
+ *
145
+ * @param {string} redirectUrl The URL the user should be redirected to after logging in.
146
+ */
112
147
  _defineProperty(this, "redirectToLogin", jest.fn(function () {
113
148
  var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
114
149
  // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.
115
150
  _this.getLoginRedirectUrl(redirectUrl);
116
151
  }));
152
+ /**
153
+ * A Jest mock function (jest.fn())
154
+ *
155
+ * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.
156
+ *
157
+ * ```
158
+ * const url = getLogoutRedirectUrl('http://localhost/mypage');
159
+ * console.log(url); // http://localhost/logout?next=http%3A%2F%2Flocalhost%2Fmypage
160
+ * ```
161
+ *
162
+ * @param {string} redirectUrl The URL the user should be redirected to after logging out.
163
+ */
117
164
  _defineProperty(this, "getLogoutRedirectUrl", jest.fn(function () {
118
165
  var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
119
166
  return "".concat(_this.config.LOGOUT_URL, "?redirect_url=").concat(encodeURIComponent(redirectUrl));
120
167
  }));
168
+ /**
169
+ * A Jest mock function (jest.fn())
170
+ *
171
+ * Redirects the user to the logout page in the real implementation. Is a no-op here.
172
+ *
173
+ * @param {string} redirectUrl The URL the user should be redirected to after logging out.
174
+ */
121
175
  _defineProperty(this, "redirectToLogout", jest.fn(function () {
122
176
  var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
123
177
  // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.
124
178
  _this.getLogoutRedirectUrl(redirectUrl);
125
179
  }));
180
+ /**
181
+ * A Jest mock function (jest.fn())
182
+ *
183
+ * If it exists, returns the user data representing the currently authenticated user. If the
184
+ * user is anonymous, returns null.
185
+ *
186
+ * @returns {UserData|null}
187
+ */
126
188
  _defineProperty(this, "getAuthenticatedUser", jest.fn(function () {
127
189
  return _this.authenticatedUser;
128
190
  }));
191
+ /**
192
+ * A Jest mock function (jest.fn())
193
+ *
194
+ * Sets the authenticated user to the provided value.
195
+ *
196
+ * @param {UserData} authUser
197
+ */
129
198
  _defineProperty(this, "setAuthenticatedUser", jest.fn(function (authUser) {
130
199
  _this.authenticatedUser = authUser;
131
200
  }));
201
+ /**
202
+ * A Jest mock function (jest.fn())
203
+ *
204
+ * Returns the current authenticated user details, as supplied in the `authenticatedUser` field
205
+ * of the config options. Resolves to null if the user is unauthenticated / the config option
206
+ * has not been set.
207
+ *
208
+ * @returns {UserData|null} Resolves to the user's access token if they are
209
+ * logged in.
210
+ */
132
211
  _defineProperty(this, "fetchAuthenticatedUser", jest.fn(function () {
133
212
  return _this.getAuthenticatedUser();
134
213
  }));
214
+ /**
215
+ * A Jest mock function (jest.fn())
216
+ *
217
+ * Ensures a user is authenticated. It will redirect to login when not authenticated.
218
+ *
219
+ * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not
220
+ * authenticated.
221
+ * @returns {UserData|null} Resolves to the user's access token if they are
222
+ * logged in.
223
+ */
135
224
  _defineProperty(this, "ensureAuthenticatedUser", jest.fn(function () {
136
225
  var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
137
226
  _this.fetchAuthenticatedUser();
@@ -141,6 +230,22 @@ var MockAuthService = /*#__PURE__*/function () {
141
230
  }
142
231
  return _this.getAuthenticatedUser();
143
232
  }));
233
+ /**
234
+ * A Jest mock function (jest.fn())
235
+ *
236
+ * Adds the user data supplied in the `hydratedAuthenticatedUser` config option into the object
237
+ * returned by `getAuthenticatedUser`. This emulates the behavior of a real auth service which
238
+ * would make a request to fetch this data prior to merging it in.
239
+ *
240
+ * ```
241
+ * console.log(authenticatedUser); // Will be sparse and only contain basic information.
242
+ * await hydrateAuthenticatedUser()
243
+ * const authenticatedUser = getAuthenticatedUser();
244
+ * console.log(authenticatedUser); // Will contain additional user information
245
+ * ```
246
+ *
247
+ * @returns {Promise<null>}
248
+ */
144
249
  _defineProperty(this, "hydrateAuthenticatedUser", jest.fn(function () {
145
250
  var user = _this.getAuthenticatedUser();
146
251
  if (user !== null) {
@@ -183,15 +288,6 @@ var MockAuthService = /*#__PURE__*/function () {
183
288
  throw new Error("Failed to apply middleware: ".concat(error.message, "."));
184
289
  }
185
290
  }
186
-
187
- /**
188
- * A Jest mock function (jest.fn())
189
- *
190
- * Gets the authenticated HTTP client instance, which is an axios client wrapped in
191
- * MockAdapter from axios-mock-adapter.
192
- *
193
- * @returns {HttpClient} An HttpClient wrapped in MockAdapter.
194
- */
195
291
  }]);
196
292
  return MockAuthService;
197
293
  }();
@@ -1 +1 @@
1
- {"version":3,"file":"MockAuthService.js","names":["axios","PropTypes","ensureDefinedConfig","userPropTypes","shape","userId","string","isRequired","username","roles","arrayOf","administrator","optionsPropTypes","config","BASE_URL","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","ACCESS_TOKEN_COOKIE_NAME","CSRF_TOKEN_API_PATH","loggingService","logError","func","logInfo","authenticatedUser","hydratedAuthenticatedUser","MockAuthService","options","_this","_classCallCheck","_defineProperty","jest","fn","authenticatedHttpClient","httpClient","redirectUrl","arguments","length","undefined","concat","encodeURIComponent","getLoginRedirectUrl","getLogoutRedirectUrl","authUser","getAuthenticatedUser","fetchAuthenticatedUser","redirectToLogin","user","setAuthenticatedUser","_objectSpread","checkPropTypes","create","_createClass","key","value","applyMiddleware","middleware","clients","cachedAuthenticatedHttpClient","cachedHttpClient","forEach","middlewareFn","client","error","Error","message"],"sources":["../../src/auth/MockAuthService.js"],"sourcesContent":["import axios from 'axios';\nimport PropTypes from 'prop-types';\nimport { ensureDefinedConfig } from '../utils';\n\nconst userPropTypes = PropTypes.shape({\n userId: PropTypes.string.isRequired,\n username: PropTypes.string.isRequired,\n roles: PropTypes.arrayOf(PropTypes.string),\n administrator: PropTypes.boolean,\n});\n\nconst optionsPropTypes = {\n config: PropTypes.shape({\n BASE_URL: PropTypes.string.isRequired,\n LMS_BASE_URL: PropTypes.string.isRequired,\n LOGIN_URL: PropTypes.string.isRequired,\n LOGOUT_URL: PropTypes.string.isRequired,\n REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,\n ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,\n CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,\n }).isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n logInfo: PropTypes.func.isRequired,\n }).isRequired,\n // The absence of authenticatedUser means the user is anonymous.\n authenticatedUser: userPropTypes,\n // Must be at least a valid user, but may have other fields.\n hydratedAuthenticatedUser: userPropTypes,\n};\n\n/**\n * The MockAuthService class mocks authenticated user-fetching logic and allows for manually\n * setting user data. It is compatible with axios-mock-adapter to wrap its HttpClients so that\n * they can be mocked for testing.\n *\n * It wraps all methods of the service with Jest mock functions (jest.fn()). This allows test code\n * to assert expectations on all functions of the service while preserving sensible behaviors. For\n * instance, the login/logout methods related to redirecting maintain their real behavior.\n *\n * This service is NOT suitable for use in an application itself - only tests. It depends on Jest,\n * which should only be a dev dependency of your project. You don't want to pull the entire suite\n * of test dependencies into your application at runtime, probably even in your dev server.\n *\n * In a test where you would like to mock out API requests - perhaps from a redux-thunk function -\n * you could do the following to set up a MockAuthService for your test:\n *\n * ```\n * import { getConfig, mergeConfig } from '@edx/frontend-platform';\n * import { configure, MockAuthService } from '@edx/frontend-platform/auth';\n * import MockAdapter from 'axios-mock-adapter';\n *\n * const mockLoggingService = {\n * logInfo: jest.fn(),\n * logError: jest.fn(),\n * };\n * mergeConfig({\n * authenticatedUser: {\n * userId: 'abc123',\n * username: 'Mock User',\n * roles: [],\n * administrator: false,\n * },\n * });\n * configure(MockAuthService, { config: getConfig(), loggingService: mockLoggingService });\n * const mockAdapter = new MockAdapter(getAuthenticatedHttpClient());\n * // Mock calls for your tests. This configuration can be done in any sort of test setup.\n * mockAdapter.onGet(...);\n * ```\n *\n * Also see the `initializeMockApp` function which also automatically uses mock services for\n * Logging and Analytics.\n *\n * @implements {AuthService}\n * @memberof module:Auth\n */\nclass MockAuthService {\n /**\n * @param {Object} options\n * @param {Object} options.config\n * @param {string} options.config.BASE_URL\n * @param {string} options.config.LMS_BASE_URL\n * @param {string} options.config.LOGIN_URL\n * @param {string} options.config.LOGOUT_URL\n * @param {string} options.config.REFRESH_ACCESS_TOKEN_ENDPOINT\n * @param {string} options.config.ACCESS_TOKEN_COOKIE_NAME\n * @param {string} options.config.CSRF_TOKEN_API_PATH\n * @param {Object} options.config.hydratedAuthenticatedUser\n * @param {Object} options.config.authenticatedUser\n * @param {Object} options.loggingService requires logError and logInfo methods\n */\n constructor(options) {\n this.authenticatedHttpClient = null;\n this.httpClient = null;\n\n ensureDefinedConfig(options, 'AuthService');\n PropTypes.checkPropTypes(optionsPropTypes, options, 'options', 'AuthService');\n\n this.config = options.config;\n this.loggingService = options.loggingService;\n\n // Mock user\n this.authenticatedUser = this.config.authenticatedUser ? this.config.authenticatedUser : null;\n this.hydratedAuthenticatedUser = this.config.hydratedAuthenticatedUser\n ? this.config.hydratedAuthenticatedUser\n : {};\n\n this.authenticatedHttpClient = axios.create();\n this.httpClient = axios.create();\n }\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Applies middleware to the axios instances in this service.\n *\n * @param {Array} middleware Middleware to apply.\n */\n applyMiddleware(middleware = []) {\n const clients = [\n this.authenticatedHttpClient, this.httpClient,\n this.cachedAuthenticatedHttpClient, this.cachedHttpClient,\n ];\n try {\n (middleware).forEach((middlewareFn) => {\n clients.forEach((client) => client && middlewareFn(client));\n });\n } catch (error) {\n throw new Error(`Failed to apply middleware: ${error.message}.`);\n }\n }\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Gets the authenticated HTTP client instance, which is an axios client wrapped in\n * MockAdapter from axios-mock-adapter.\n *\n * @returns {HttpClient} An HttpClient wrapped in MockAdapter.\n */\n getAuthenticatedHttpClient = jest.fn(() => this.authenticatedHttpClient);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Gets the unauthenticated HTTP client instance, which is an axios client wrapped in\n * MockAdapter from axios-mock-adapter.\n *\n * @returns {HttpClient} An HttpClient wrapped in MockAdapter.\n */\n getHttpClient = jest.fn(() => this.httpClient);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLoginRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\n getLoginRedirectUrl = jest.fn(\n (redirectUrl = this.config.BASE_URL) => `${this.config.LOGIN_URL}?next=${encodeURIComponent(redirectUrl)}`,\n );\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Redirects the user to the logout page in the real implementation. Is a no-op here.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\n redirectToLogin = jest.fn((redirectUrl = this.config.BASE_URL) => {\n // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.\n this.getLoginRedirectUrl(redirectUrl);\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLogoutRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/logout?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\n getLogoutRedirectUrl = jest.fn((redirectUrl = this.config.BASE_URL) => `${this.config.LOGOUT_URL}?redirect_url=${encodeURIComponent(redirectUrl)}`);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Redirects the user to the logout page in the real implementation. Is a no-op here.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\n redirectToLogout = jest.fn((redirectUrl = this.config.BASE_URL) => {\n // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.\n this.getLogoutRedirectUrl(redirectUrl);\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * If it exists, returns the user data representing the currently authenticated user. If the\n * user is anonymous, returns null.\n *\n * @returns {UserData|null}\n */\n getAuthenticatedUser = jest.fn(() => this.authenticatedUser);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n */\n setAuthenticatedUser = jest.fn((authUser) => {\n this.authenticatedUser = authUser;\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Returns the current authenticated user details, as supplied in the `authenticatedUser` field\n * of the config options. Resolves to null if the user is unauthenticated / the config option\n * has not been set.\n *\n * @returns {UserData|null} Resolves to the user's access token if they are\n * logged in.\n */\n fetchAuthenticatedUser = jest.fn(() => this.getAuthenticatedUser());\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Ensures a user is authenticated. It will redirect to login when not authenticated.\n *\n * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not\n * authenticated.\n * @returns {UserData|null} Resolves to the user's access token if they are\n * logged in.\n */\n ensureAuthenticatedUser = jest.fn((redirectUrl = this.config.BASE_URL) => {\n this.fetchAuthenticatedUser();\n\n if (this.getAuthenticatedUser() === null) {\n // The user is not authenticated, send them to the login page.\n this.redirectToLogin(redirectUrl);\n }\n\n return this.getAuthenticatedUser();\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Adds the user data supplied in the `hydratedAuthenticatedUser` config option into the object\n * returned by `getAuthenticatedUser`. This emulates the behavior of a real auth service which\n * would make a request to fetch this data prior to merging it in.\n *\n * ```\n * console.log(authenticatedUser); // Will be sparse and only contain basic information.\n * await hydrateAuthenticatedUser()\n * const authenticatedUser = getAuthenticatedUser();\n * console.log(authenticatedUser); // Will contain additional user information\n * ```\n *\n * @returns {Promise<null>}\n */\n hydrateAuthenticatedUser = jest.fn(() => {\n const user = this.getAuthenticatedUser();\n if (user !== null) {\n this.setAuthenticatedUser({ ...user, ...this.hydratedAuthenticatedUser });\n }\n });\n}\n\nexport default MockAuthService;\n"],"mappings":";;;;;;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,mBAAmB,QAAQ,UAAU;AAE9C,IAAMC,aAAa,GAAGF,SAAS,CAACG,KAAK,CAAC;EACpCC,MAAM,EAAEJ,SAAS,CAACK,MAAM,CAACC,UAAU;EACnCC,QAAQ,EAAEP,SAAS,CAACK,MAAM,CAACC,UAAU;EACrCE,KAAK,EAAER,SAAS,CAACS,OAAO,CAACT,SAAS,CAACK,MAAM,CAAC;EAC1CK,aAAa,EAAEV,SAAS;AAC1B,CAAC,CAAC;AAEF,IAAMW,gBAAgB,GAAG;EACvBC,MAAM,EAAEZ,SAAS,CAACG,KAAK,CAAC;IACtBU,QAAQ,EAAEb,SAAS,CAACK,MAAM,CAACC,UAAU;IACrCQ,YAAY,EAAEd,SAAS,CAACK,MAAM,CAACC,UAAU;IACzCS,SAAS,EAAEf,SAAS,CAACK,MAAM,CAACC,UAAU;IACtCU,UAAU,EAAEhB,SAAS,CAACK,MAAM,CAACC,UAAU;IACvCW,6BAA6B,EAAEjB,SAAS,CAACK,MAAM,CAACC,UAAU;IAC1DY,wBAAwB,EAAElB,SAAS,CAACK,MAAM,CAACC,UAAU;IACrDa,mBAAmB,EAAEnB,SAAS,CAACK,MAAM,CAACC;EACxC,CAAC,CAAC,CAACA,UAAU;EACbc,cAAc,EAAEpB,SAAS,CAACG,KAAK,CAAC;IAC9BkB,QAAQ,EAAErB,SAAS,CAACsB,IAAI,CAAChB,UAAU;IACnCiB,OAAO,EAAEvB,SAAS,CAACsB,IAAI,CAAChB;EAC1B,CAAC,CAAC,CAACA,UAAU;EACb;EACAkB,iBAAiB,EAAEtB,aAAa;EAChC;EACAuB,yBAAyB,EAAEvB;AAC7B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA5CA,IA6CMwB,eAAe;EACnB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,S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E;IACF;;IAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EAPE;EAAA,OAAAvC,eAAA;AAAA;AAwJF,eAAeA,eAAe"}
1
+ {"version":3,"file":"MockAuthService.js","names":["axios","PropTypes","ensureDefinedConfig","userPropTypes","shape","userId","string","isRequired","username","roles","arrayOf","administrator","optionsPropTypes","config","BASE_URL","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","ACCESS_TOKEN_COOKIE_NAME","CSRF_TOKEN_API_PATH","loggingService","logError","func","logInfo","authenticatedUser","hydratedAuthenticatedUser","MockAuthService","options","_this","_classCallCheck","_defineProperty","jest","fn","authenticatedHttpClient","httpClient","redirectUrl","arguments","length","undefined","concat","encodeURIComponent","getLoginRedirectUrl","getLogoutRedirectUrl","authUser","getAuthenticatedUser","fetchAuthenticatedUser","redirectToLogin","user","setAuthenticatedUser","_objectSpread","checkPropTypes","create","_createClass","key","value","applyMiddleware","middleware","clients","cachedAuthenticatedHttpClient","cachedHttpClient","forEach","middlewareFn","client","error","Error","message"],"sources":["../../src/auth/MockAuthService.js"],"sourcesContent":["import axios from 'axios';\nimport PropTypes from 'prop-types';\nimport { ensureDefinedConfig } from '../utils';\n\nconst userPropTypes = PropTypes.shape({\n userId: PropTypes.string.isRequired,\n username: PropTypes.string.isRequired,\n roles: PropTypes.arrayOf(PropTypes.string),\n administrator: PropTypes.boolean,\n});\n\nconst optionsPropTypes = {\n config: PropTypes.shape({\n BASE_URL: PropTypes.string.isRequired,\n LMS_BASE_URL: PropTypes.string.isRequired,\n LOGIN_URL: PropTypes.string.isRequired,\n LOGOUT_URL: PropTypes.string.isRequired,\n REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,\n ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,\n CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,\n }).isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n logInfo: PropTypes.func.isRequired,\n }).isRequired,\n // The absence of authenticatedUser means the user is anonymous.\n authenticatedUser: userPropTypes,\n // Must be at least a valid user, but may have other fields.\n hydratedAuthenticatedUser: userPropTypes,\n};\n\n/**\n * The MockAuthService class mocks authenticated user-fetching logic and allows for manually\n * setting user data. It is compatible with axios-mock-adapter to wrap its HttpClients so that\n * they can be mocked for testing.\n *\n * It wraps all methods of the service with Jest mock functions (jest.fn()). This allows test code\n * to assert expectations on all functions of the service while preserving sensible behaviors. For\n * instance, the login/logout methods related to redirecting maintain their real behavior.\n *\n * This service is NOT suitable for use in an application itself - only tests. It depends on Jest,\n * which should only be a dev dependency of your project. You don't want to pull the entire suite\n * of test dependencies into your application at runtime, probably even in your dev server.\n *\n * In a test where you would like to mock out API requests - perhaps from a redux-thunk function -\n * you could do the following to set up a MockAuthService for your test:\n *\n * ```\n * import { getConfig, mergeConfig } from '@edx/frontend-platform';\n * import { configure, MockAuthService } from '@edx/frontend-platform/auth';\n * import MockAdapter from 'axios-mock-adapter';\n *\n * const mockLoggingService = {\n * logInfo: jest.fn(),\n * logError: jest.fn(),\n * };\n * mergeConfig({\n * authenticatedUser: {\n * userId: 'abc123',\n * username: 'Mock User',\n * roles: [],\n * administrator: false,\n * },\n * });\n * configure(MockAuthService, { config: getConfig(), loggingService: mockLoggingService });\n * const mockAdapter = new MockAdapter(getAuthenticatedHttpClient());\n * // Mock calls for your tests. This configuration can be done in any sort of test setup.\n * mockAdapter.onGet(...);\n * ```\n *\n * Also see the `initializeMockApp` function which also automatically uses mock services for\n * Logging and Analytics.\n *\n * @implements {AuthService}\n * @memberof module:Auth\n */\nclass MockAuthService {\n /**\n * @param {Object} options\n * @param {Object} options.config\n * @param {string} options.config.BASE_URL\n * @param {string} options.config.LMS_BASE_URL\n * @param {string} options.config.LOGIN_URL\n * @param {string} options.config.LOGOUT_URL\n * @param {string} options.config.REFRESH_ACCESS_TOKEN_ENDPOINT\n * @param {string} options.config.ACCESS_TOKEN_COOKIE_NAME\n * @param {string} options.config.CSRF_TOKEN_API_PATH\n * @param {Object} options.config.hydratedAuthenticatedUser\n * @param {Object} options.config.authenticatedUser\n * @param {Object} options.loggingService requires logError and logInfo methods\n */\n constructor(options) {\n this.authenticatedHttpClient = null;\n this.httpClient = null;\n\n ensureDefinedConfig(options, 'AuthService');\n PropTypes.checkPropTypes(optionsPropTypes, options, 'options', 'AuthService');\n\n this.config = options.config;\n this.loggingService = options.loggingService;\n\n // Mock user\n this.authenticatedUser = this.config.authenticatedUser ? this.config.authenticatedUser : null;\n this.hydratedAuthenticatedUser = this.config.hydratedAuthenticatedUser\n ? this.config.hydratedAuthenticatedUser\n : {};\n\n this.authenticatedHttpClient = axios.create();\n this.httpClient = axios.create();\n }\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Applies middleware to the axios instances in this service.\n *\n * @param {Array} middleware Middleware to apply.\n */\n applyMiddleware(middleware = []) {\n const clients = [\n this.authenticatedHttpClient, this.httpClient,\n this.cachedAuthenticatedHttpClient, this.cachedHttpClient,\n ];\n try {\n (middleware).forEach((middlewareFn) => {\n clients.forEach((client) => client && middlewareFn(client));\n });\n } catch (error) {\n throw new Error(`Failed to apply middleware: ${error.message}.`);\n }\n }\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Gets the authenticated HTTP client instance, which is an axios client wrapped in\n * MockAdapter from axios-mock-adapter.\n *\n * @returns {HttpClient} An HttpClient wrapped in MockAdapter.\n */\n getAuthenticatedHttpClient = jest.fn(() => this.authenticatedHttpClient);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Gets the unauthenticated HTTP client instance, which is an axios client wrapped in\n * MockAdapter from axios-mock-adapter.\n *\n * @returns {HttpClient} An HttpClient wrapped in MockAdapter.\n */\n getHttpClient = jest.fn(() => this.httpClient);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLoginRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\n getLoginRedirectUrl = jest.fn(\n (redirectUrl = this.config.BASE_URL) => `${this.config.LOGIN_URL}?next=${encodeURIComponent(redirectUrl)}`,\n );\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Redirects the user to the logout page in the real implementation. Is a no-op here.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\n redirectToLogin = jest.fn((redirectUrl = this.config.BASE_URL) => {\n // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.\n this.getLoginRedirectUrl(redirectUrl);\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLogoutRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/logout?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\n getLogoutRedirectUrl = jest.fn((redirectUrl = this.config.BASE_URL) => `${this.config.LOGOUT_URL}?redirect_url=${encodeURIComponent(redirectUrl)}`);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Redirects the user to the logout page in the real implementation. Is a no-op here.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\n redirectToLogout = jest.fn((redirectUrl = this.config.BASE_URL) => {\n // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.\n this.getLogoutRedirectUrl(redirectUrl);\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * If it exists, returns the user data representing the currently authenticated user. If the\n * user is anonymous, returns null.\n *\n * @returns {UserData|null}\n */\n getAuthenticatedUser = jest.fn(() => this.authenticatedUser);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n */\n setAuthenticatedUser = jest.fn((authUser) => {\n this.authenticatedUser = authUser;\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Returns the current authenticated user details, as supplied in the `authenticatedUser` field\n * of the config options. Resolves to null if the user is unauthenticated / the config option\n * has not been set.\n *\n * @returns {UserData|null} Resolves to the user's access token if they are\n * logged in.\n */\n fetchAuthenticatedUser = jest.fn(() => this.getAuthenticatedUser());\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Ensures a user is authenticated. It will redirect to login when not authenticated.\n *\n * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not\n * authenticated.\n * @returns {UserData|null} Resolves to the user's access token if they are\n * logged in.\n */\n ensureAuthenticatedUser = jest.fn((redirectUrl = this.config.BASE_URL) => {\n this.fetchAuthenticatedUser();\n\n if (this.getAuthenticatedUser() === null) {\n // The user is not authenticated, send them to the login page.\n this.redirectToLogin(redirectUrl);\n }\n\n return this.getAuthenticatedUser();\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Adds the user data supplied in the `hydratedAuthenticatedUser` config option into the object\n * returned by `getAuthenticatedUser`. This emulates the behavior of a real auth service which\n * would make a request to fetch this data prior to merging it in.\n *\n * ```\n * console.log(authenticatedUser); // Will be sparse and only contain basic information.\n * await hydrateAuthenticatedUser()\n * const authenticatedUser = getAuthenticatedUser();\n * console.log(authenticatedUser); // Will contain additional user information\n * ```\n *\n * @returns {Promise<null>}\n */\n hydrateAuthenticatedUser = jest.fn(() => {\n const user = this.getAuthenticatedUser();\n if (user !== null) {\n this.setAuthenticatedUser({ ...user, ...this.hydratedAuthenticatedUser });\n }\n });\n}\n\nexport default MockAuthService;\n"],"mappings":";;;;;;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,mBAAmB,QAAQ,UAAU;AAE9C,IAAMC,aAAa,GAAGF,SAAS,CAACG,KAAK,CAAC;EACpCC,MAAM,EAAEJ,SAAS,CAACK,MAAM,CAACC,UAAU;EACnCC,QAAQ,EAAEP,SAAS,CAACK,MAAM,CAACC,UAAU;EACrCE,KAAK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7B,IAAMqB,OAAO,GAAG,CACd,IAAI,CAACxB,uBAAuB,EAAE,IAAI,CAACC,UAAU,EAC7C,IAAI,CAACwB,6BAA6B,EAAE,IAAI,CAACC,gBAAgB,CAC1D;MACD,IAAI;QACDH,UAAU,CAAEI,OAAO,CAAC,UAACC,YAAY,EAAK;UACrCJ,OAAO,CAACG,OAAO,CAAC,UAACE,MAAM;YAAA,OAAKA,MAAM,IAAID,YAAY,CAACC,MAAM,CAAC;UAAA,EAAC;QAC7D,CAAC,CAAC;MACJ,CAAC,CAAC,OAAOC,KAAK,EAAE;QACd,MAAM,IAAIC,KAAK,gCAAAzB,MAAA,CAAgCwB,KAAK,CAACE,OAAO,OAAI;MAClE;IACF;EAAC;EAAA,OAAAvC,eAAA;AAAA;AA0JH,eAAeA,eAAe"}
@@ -14,7 +14,17 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
14
14
  */
15
15
  var MockLoggingService = /*#__PURE__*/_createClass(function MockLoggingService() {
16
16
  _classCallCheck(this, MockLoggingService);
17
+ /**
18
+ * Implemented as a jest.fn()
19
+ *
20
+ * @memberof MockLoggingService
21
+ */
17
22
  _defineProperty(this, "logInfo", jest.fn());
23
+ /**
24
+ * Implemented as a jest.fn()
25
+ *
26
+ * @memberof MockLoggingService
27
+ */
18
28
  _defineProperty(this, "logError", jest.fn());
19
29
  });
20
30
  export default MockLoggingService;
@@ -1 +1 @@
1
- {"version":3,"file":"MockLoggingService.js","names":["MockLoggingService","_createClass","_classCallCheck","_defineProperty","jest","fn"],"sources":["../../src/logging/MockLoggingService.js"],"sourcesContent":["/**\n * The MockLoggingService implements both logInfo and logError as jest mock functions via\n * jest.fn(). It has no other functionality.\n *\n * @implements {LoggingService}\n * @memberof module:Logging\n */\nclass MockLoggingService {\n /**\n * Implemented as a jest.fn()\n *\n * @memberof MockLoggingService\n */\n logInfo = jest.fn();\n\n /**\n * Implemented as a jest.fn()\n *\n * @memberof MockLoggingService\n */\n logError = jest.fn();\n}\n\nexport default MockLoggingService;\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,IAOMA,kBAAkB,gBAAAC,YAAA,UAAAD,mBAAA;EAAAE,eAAA,OAAAF,kBAAA;EAAAG,eAAA,kBAMZC,IAAI,CAACC,EAAE,EAAE;EAAAF,eAAA,mBAORC,IAAI,CAACC,EAAE,EAAE;AAAA;AAGtB,eAAeL,kBAAkB"}
1
+ {"version":3,"file":"MockLoggingService.js","names":["MockLoggingService","_createClass","_classCallCheck","_defineProperty","jest","fn"],"sources":["../../src/logging/MockLoggingService.js"],"sourcesContent":["/**\n * The MockLoggingService implements both logInfo and logError as jest mock functions via\n * jest.fn(). It has no other functionality.\n *\n * @implements {LoggingService}\n * @memberof module:Logging\n */\nclass MockLoggingService {\n /**\n * Implemented as a jest.fn()\n *\n * @memberof MockLoggingService\n */\n logInfo = jest.fn();\n\n /**\n * Implemented as a jest.fn()\n *\n * @memberof MockLoggingService\n */\n logError = jest.fn();\n}\n\nexport default MockLoggingService;\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,IAOMA,kBAAkB,gBAAAC,YAAA,UAAAD,mBAAA;EAAAE,eAAA,OAAAF,kBAAA;EACtB;AACF;AACA;AACA;AACA;EAJEG,eAAA,kBAKUC,IAAI,CAACC,EAAE,EAAE;EAEnB;AACF;AACA;AACA;AACA;EAJEF,eAAA,mBAKWC,IAAI,CAACC,EAAE,EAAE;AAAA;AAGtB,eAAeL,kBAAkB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edx/frontend-platform",
3
- "version": "3.6.1",
3
+ "version": "4.0.1",
4
4
  "description": "Foundational application framework for Open edX micro-frontend applications.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -33,10 +33,10 @@
33
33
  "devDependencies": {
34
34
  "@edx/brand": "npm:@edx/brand-openedx@1.2.0",
35
35
  "@edx/browserslist-config": "1.1.1",
36
- "@edx/frontend-build": "12.6.2",
36
+ "@edx/frontend-build": "12.7.0",
37
37
  "@edx/paragon": "20.28.5",
38
38
  "@testing-library/react-hooks": "^8.0.1",
39
- "axios-mock-adapter": "1.21.2",
39
+ "axios-mock-adapter": "^1.21.3",
40
40
  "core-js": "3.29.1",
41
41
  "enzyme": "3.11.0",
42
42
  "enzyme-adapter-react-16": "1.15.7",