@amedia/user 0.13.32 → 0.13.34

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.
Files changed (64) hide show
  1. package/build.js +3 -2
  2. package/dist/actions/authentication.spec.d.ts +0 -3
  3. package/dist/autologin/index.spec.d.ts +0 -3
  4. package/dist/cache/index.spec.d.ts +0 -3
  5. package/dist/clients/mercury.spec.d.ts +0 -3
  6. package/dist/clients/mercuryLog.spec.d.ts +0 -3
  7. package/dist/eventHandlers/state.spec.d.ts +0 -3
  8. package/dist/eventHandlers/storage.spec.d.ts +0 -3
  9. package/dist/eventHandlers/userAttributes.spec.d.ts +0 -3
  10. package/dist/index-authentcation.spec.d.ts +0 -3
  11. package/dist/index-storage.spec.d.ts +0 -3
  12. package/dist/index-subscription.spec.d.ts +0 -3
  13. package/dist/index.d.ts +13 -42
  14. package/dist/index.esm.js +1 -1
  15. package/dist/index.esm.js.map +3 -3
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +3 -3
  18. package/dist/janitor/index.spec.d.ts +1 -0
  19. package/dist/janitor/jobs/accessCookieRefresher.spec.d.ts +0 -3
  20. package/dist/janitor/jobs/daxsubCookie.spec.d.ts +0 -3
  21. package/dist/lib/PaywallUnlockRequest.spec.d.ts +0 -3
  22. package/dist/utils/expectBootLogs.d.ts +2 -0
  23. package/dist/utils/localhostCheck.d.ts +1 -0
  24. package/eik.json +1 -1
  25. package/jest.config.js +3 -2
  26. package/package.json +10 -3
  27. package/setupJest.js +0 -5
  28. package/src/actions/authentication.spec.ts +0 -6
  29. package/src/actions/authorization.spec.ts +0 -4
  30. package/src/actions/preferences.spec.ts +0 -1
  31. package/src/actions/userData.spec.ts +0 -6
  32. package/src/autologin/index.spec.ts +1 -11
  33. package/src/autologin/thirdPartyCookie.spec.ts +0 -5
  34. package/src/cache/index.spec.ts +0 -6
  35. package/src/clients/europa.spec.ts +0 -3
  36. package/src/clients/jupiter.spec.ts +0 -3
  37. package/src/clients/mercury.spec.ts +0 -10
  38. package/src/clients/mercuryLog.spec.ts +0 -10
  39. package/src/clients/nebula.spec.ts +0 -3
  40. package/src/clients/pluto.spec.ts +0 -3
  41. package/src/eventHandlers/activation.ts +5 -1
  42. package/src/eventHandlers/state.spec.ts +1 -12
  43. package/src/eventHandlers/storage.spec.ts +1 -12
  44. package/src/eventHandlers/userAttributes.spec.ts +1 -12
  45. package/src/index-authentcation.spec.ts +0 -14
  46. package/src/index-storage.spec.ts +1 -15
  47. package/src/index-subscription.spec.ts +1 -15
  48. package/src/index.ts +7 -4
  49. package/src/janitor/index.spec.ts +18 -0
  50. package/src/janitor/index.ts +9 -0
  51. package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -8
  52. package/src/janitor/jobs/daxsubCookie.spec.ts +1 -15
  53. package/src/janitor/jobs/removeUserStorage.spec.ts +0 -5
  54. package/src/lib/PaywallUnlockRequest.spec.ts +17 -14
  55. package/src/lib/PaywallUnlockRequest.ts +6 -0
  56. package/src/lib/UserDataRequest.spec.ts +16 -11
  57. package/src/lib/UserDataRequest.ts +9 -1
  58. package/src/utils/debouncer.spec.ts +0 -5
  59. package/src/utils/expectBootLogs.ts +9 -0
  60. package/src/utils/getOrUpdate.spec.ts +0 -2
  61. package/src/utils/localhostCheck.ts +9 -0
  62. package/src/utils/log.spec.ts +0 -5
  63. package/testSetup.js +18 -0
  64. /package/{checkVersion.js → checkVersion.cjs} +0 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
1
  export {};
@@ -1,4 +1 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
1
  export {};
@@ -1,4 +1 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
1
  export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: () => void;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export declare const isRunningOnLocalhost: () => boolean;
package/eik.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amedia/user",
3
- "version": "0.13.32",
3
+ "version": "0.13.34",
4
4
  "server": "https://assets.acdn.no",
5
5
  "files": {
6
6
  "user.js": "./dist/index.esm.js",
package/jest.config.js CHANGED
@@ -1,6 +1,7 @@
1
- module.exports = {
1
+ export default {
2
2
  preset: 'ts-jest',
3
- testEnvironment: 'node',
3
+ testEnvironment: 'jsdom',
4
+ restoreMocks: true,
4
5
  setupFilesAfterEnv: ['./testSetup.js'],
5
6
  setupFiles: ['./setupJest.js'],
6
7
  };
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "@amedia/user",
3
- "version": "0.13.32",
3
+ "version": "0.13.34",
4
4
  "description": "Client lib for working with aID user and associated data",
5
5
  "repository": "https://github.com/amedia/amedia-user-js",
6
6
  "author": "Amedia Utvikling (ID og data)",
7
+ "type": "module",
7
8
  "main": "dist/index.js",
8
9
  "module": "dist/index.esm.js",
10
+ "exports": {
11
+ ".": {
12
+ "require": "./dist/index.js",
13
+ "import": "./dist/index.esm.js"
14
+ }
15
+ },
9
16
  "typings": "dist/index.d.ts",
10
17
  "scripts": {
11
18
  "test": "jest --coverage",
@@ -13,7 +20,7 @@
13
20
  "build": "npm install && node build.js",
14
21
  "typings": "tsc",
15
22
  "eik:package": "run-p typings lint && npm run test && npm run build && eik package",
16
- "prepublishOnly": "node checkVersion.js && run-p typings lint && npm run test && npm run build",
23
+ "prepublishOnly": "node checkVersion.cjs && run-p typings lint && npm run test && npm run build",
17
24
  "postpublish": "eik package"
18
25
  },
19
26
  "dependencies": {
@@ -25,7 +32,7 @@
25
32
  "devDependencies": {
26
33
  "@amedia/eslint-config-base": "^4.0.7",
27
34
  "@amedia/eslint-config-typescript": "^4.0.10",
28
- "@eik/cli": "^1.8.42",
35
+ "@eik/cli": "^2.0.5",
29
36
  "@types/convict": "^6.1.1",
30
37
  "@types/dexie": "^1.3.1",
31
38
  "@types/jest": "^26.0.24",
package/setupJest.js CHANGED
@@ -1,6 +1 @@
1
- const { setLogger } = require('./src/utils/log');
2
- require('jest-fetch-mock').enableMocks();
3
-
4
1
  self = global || window;
5
-
6
- setLogger(console);
@@ -1,14 +1,8 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import * as url from '../utils/url';
6
2
  import * as location from '../utils/location';
7
3
  import { login } from './authentication';
8
- import restoreAllMocks = jest.restoreAllMocks;
9
4
 
10
5
  beforeEach(() => {
11
- restoreAllMocks();
12
6
  spyOn(url, 'getCurrentUrl').and.returnValue('https://www.telen.no/artikkel/');
13
7
  spyOn(url, 'getCurrentPublicationDomain').and.returnValue('www.telen.no');
14
8
  spyOn(location, 'navigateTo');
@@ -17,16 +17,12 @@ import * as cookie from '../lib/cookie';
17
17
  import * as url from '../utils/url';
18
18
  import * as mercury from '../clients/mercury';
19
19
  import * as authentication from './authentication';
20
- import { setRootElement } from '../utils/customEventWrapper';
21
20
  import { removeAllCookies } from '../lib/cookie';
22
- import restoreAllMocks = jest.restoreAllMocks;
23
21
  import { AccessFeatures } from '../clients/jupiter';
24
22
 
25
23
  const publicationDomain = 'www.avisnavn.no';
26
24
 
27
25
  beforeEach(() => {
28
- setRootElement(new Document().createElement('div'));
29
- restoreAllMocks();
30
26
  removeAllCookies();
31
27
  jest.spyOn(cookie, 'setCookie');
32
28
  });
@@ -3,7 +3,6 @@ import cache from '../cache';
3
3
  import { getPrivacyPreferences } from './preferences';
4
4
 
5
5
  beforeEach(async () => {
6
- fetch.resetMocks();
7
6
  await cache.clear();
8
7
  });
9
8
 
@@ -1,6 +1,3 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
1
  import fetch, { FetchMock } from 'jest-fetch-mock';
5
2
  import cache from '../cache';
6
3
  import store from '../store';
@@ -8,15 +5,12 @@ import { requestAttributes } from './userData';
8
5
  import * as preferences from './preferences';
9
6
  import * as nebula from '../clients/nebula';
10
7
  import * as pluto from '../clients/pluto';
11
- import restoreAllMocks = jest.restoreAllMocks;
12
8
  import useRealTimers = jest.useRealTimers;
13
9
  import useFakeTimers = jest.useFakeTimers;
14
10
 
15
11
  describe('when fetching userData', () => {
16
12
  let plutoFetchMock: FetchMock;
17
13
  beforeEach(() => {
18
- restoreAllMocks();
19
- fetch.resetMocks();
20
14
  plutoFetchMock = fetch.doMockIf('/api/pluto/v1/sessions/current');
21
15
  cache.clear();
22
16
  store.clear();
@@ -1,9 +1,4 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import store from '../store';
6
-
7
2
  import * as thirdPartyCookie from './thirdPartyCookie';
8
3
  import {
9
4
  attemptAutoLoginJob,
@@ -14,10 +9,6 @@ import * as location from '../utils/location';
14
9
  import * as url from '../utils/url';
15
10
  import * as cookie from '../lib/cookie';
16
11
  import UserDataRequest from '../lib/UserDataRequest';
17
- import restoreAllMocks = jest.restoreAllMocks;
18
- import resetAllMocks = jest.resetAllMocks;
19
-
20
- jest.mock('./thirdPartyCookie');
21
12
 
22
13
  function itShouldNotNavigateAway() {
23
14
  it('should not navigate away', () => {
@@ -42,8 +33,7 @@ function itShouldNavigateToAutoLogin(context: string) {
42
33
  let getCookieSpy: jasmine.Spy;
43
34
 
44
35
  beforeEach(() => {
45
- restoreAllMocks();
46
- resetAllMocks();
36
+ jest.mock('./thirdPartyCookie');
47
37
  spyOn(location, 'navigateTo');
48
38
  spyOn(url, 'getAidDomain').and.returnValue('www.aid.no');
49
39
  spyOn(url, 'getCurrentUrl').and.returnValue(
@@ -3,14 +3,9 @@ import cache from '../cache';
3
3
  import thirdPartyCookie, { CACHE_KEY, CACHE_TTL } from './thirdPartyCookie';
4
4
  import * as location from '../utils/location';
5
5
  import * as url from '../utils/url';
6
- import restoreAllMocks = jest.restoreAllMocks;
7
6
 
8
7
  let shouldRedirectToAutoLogin = false;
9
8
 
10
- beforeEach(() => {
11
- restoreAllMocks();
12
- });
13
-
14
9
  function itShouldSetAlreadyTriedCache() {
15
10
  it('should set already tried cache', () => {
16
11
  expect(cache.set).toHaveBeenCalledWith(CACHE_KEY, true, CACHE_TTL);
@@ -1,12 +1,7 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import { Record, String } from 'runtypes';
6
2
  import * as MockDate from 'mockdate';
7
3
  import cache, { setCacheEngine } from '.';
8
4
  import { setLogger } from '../utils/log';
9
- import restoreAllMocks = jest.restoreAllMocks;
10
5
 
11
6
  const TestDataSchema = Record({
12
7
  test: String,
@@ -15,7 +10,6 @@ const TestDataSchema = Record({
15
10
  let log: any;
16
11
  let mockEngine: any;
17
12
  beforeEach(() => {
18
- restoreAllMocks();
19
13
  MockDate.reset();
20
14
  // @ts-ignore
21
15
  mockEngine = {
@@ -9,11 +9,8 @@ import {
9
9
  getNamespaces,
10
10
  getAllNamespaces,
11
11
  } from './europa';
12
- import restoreAllMocks = jest.restoreAllMocks;
13
12
 
14
13
  beforeEach(() => {
15
- restoreAllMocks();
16
- fetch.resetMocks();
17
14
  cache.clear();
18
15
  });
19
16
 
@@ -11,11 +11,8 @@ import {
11
11
  getNonUserAccess,
12
12
  } from './jupiter';
13
13
  import anything = jasmine.anything;
14
- import restoreAllMocks = jest.restoreAllMocks;
15
14
 
16
15
  beforeEach(async () => {
17
- restoreAllMocks();
18
- fetch.resetMocks();
19
16
  await cache.clear();
20
17
  });
21
18
 
@@ -1,15 +1,5 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import fetch from 'jest-fetch-mock';
6
2
  import { activateSubscription, UserDeactivatedError } from './mercury';
7
- import restoreAllMocks = jest.restoreAllMocks;
8
-
9
- beforeEach(() => {
10
- restoreAllMocks();
11
- fetch.resetMocks();
12
- });
13
3
 
14
4
  describe('activateSubscription()', () => {
15
5
  it('should throw error if user is deactivated', async () => {
@@ -1,15 +1,5 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import fetch from 'jest-fetch-mock';
6
2
  import backendLog from './mercuryLog';
7
- import restoreAllMocks = jest.restoreAllMocks;
8
-
9
- beforeEach(() => {
10
- restoreAllMocks();
11
- fetch.resetMocks();
12
- });
13
3
 
14
4
  describe('Mercury backendlog', () => {
15
5
  it('should include level in url', () => {
@@ -2,12 +2,9 @@ import fetch from 'jest-fetch-mock';
2
2
  import cache from '../cache';
3
3
  import log from '../utils/log';
4
4
  import { getInfo } from './nebula';
5
- import restoreAllMocks = jest.restoreAllMocks;
6
5
 
7
6
  describe('nebula service', () => {
8
7
  beforeEach(async () => {
9
- restoreAllMocks();
10
- fetch.resetMocks();
11
8
  await cache.clear();
12
9
  });
13
10
 
@@ -3,12 +3,9 @@ import cache from '../cache';
3
3
  import store from '../store';
4
4
  import { getCurrentSession, removeSession } from './pluto';
5
5
  import { Logger, setLogger } from '../utils/log';
6
- import restoreAllMocks = jest.restoreAllMocks;
7
6
  import { UserAttributes } from '../types';
8
7
 
9
8
  beforeEach(async () => {
10
- restoreAllMocks();
11
- fetch.resetMocks();
12
9
  await cache.clear();
13
10
  });
14
11
 
@@ -28,4 +28,8 @@ export const listenForActivationRequests = () => {
28
28
  });
29
29
  });
30
30
  };
31
- listenForActivationRequests();
31
+
32
+ // @ts-ignore
33
+ if (!globalThis.amediaUserTestMode) {
34
+ listenForActivationRequests();
35
+ }
@@ -1,20 +1,9 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
- import {
6
- dispatch,
7
- listenForAllEvents,
8
- setRootElement,
9
- } from '../utils/customEventWrapper';
1
+ import { dispatch, listenForAllEvents } from '../utils/customEventWrapper';
10
2
  import store from '../store';
11
3
  import { AmediaUserEvents } from './eventMap';
12
4
  import { listenForStateRequests } from './state';
13
- import restoreAllMocks = jest.restoreAllMocks;
14
5
 
15
6
  beforeEach(() => {
16
- setRootElement(new Document().createElement('div'));
17
- restoreAllMocks();
18
7
  store.clear();
19
8
  });
20
9
 
@@ -1,22 +1,11 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
- import {
6
- dispatch,
7
- listenForAllEvents,
8
- setRootElement,
9
- } from '../utils/customEventWrapper';
1
+ import { dispatch, listenForAllEvents } from '../utils/customEventWrapper';
10
2
  import * as userData from '../actions/userData';
11
3
  import * as storage from '../actions/storage';
12
4
  import store from '../store';
13
5
  import { listenForStorageRequests } from './storage';
14
6
  import { AmediaUserEvents } from './eventMap';
15
- import restoreAllMocks = jest.restoreAllMocks;
16
7
 
17
8
  beforeEach(() => {
18
- setRootElement(new Document().createElement('div'));
19
- restoreAllMocks();
20
9
  store.clear();
21
10
  });
22
11
 
@@ -1,21 +1,10 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
- import {
6
- dispatch,
7
- listenForAllEvents,
8
- setRootElement,
9
- } from '../utils/customEventWrapper';
1
+ import { dispatch, listenForAllEvents } from '../utils/customEventWrapper';
10
2
  import { listenForUserAttributeRequests } from './userAttributes';
11
3
  import * as userData from '../actions/userData';
12
4
  import store from '../store';
13
5
  import { AmediaUserEvents } from './eventMap';
14
- import restoreAllMocks = jest.restoreAllMocks;
15
6
 
16
7
  beforeEach(() => {
17
- setRootElement(new Document().createElement('div'));
18
- restoreAllMocks();
19
8
  store.clear();
20
9
  });
21
10
 
@@ -1,22 +1,8 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import { goToLoginPage, logout } from './index';
6
- import { setRootElement } from './utils/customEventWrapper';
7
2
  import * as authentication from './actions/authentication';
8
3
  import { listenForAuthenticationRequests } from './eventHandlers/authentication';
9
- import restoreAllMocks = jest.restoreAllMocks;
10
4
 
11
5
  beforeEach(() => {
12
- restoreAllMocks();
13
-
14
- // We cannot use window as our event root during testing
15
- // since tests are executed in parallel.
16
- setRootElement(new Document().createElement('div'));
17
-
18
- // Also, since we keep creating new root elements, we also
19
- // need to attach to these new roots.
20
6
  listenForAuthenticationRequests();
21
7
  });
22
8
 
@@ -1,28 +1,14 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import * as europa from './clients/europa';
6
2
  import { saveStorage, updateStorage } from './index';
7
3
  import store from './store';
8
4
  import UserDataRequest from './lib/UserDataRequest';
9
- import { setRootElement } from './utils/customEventWrapper';
10
5
  import { listenForStorageRequests } from './eventHandlers/storage';
11
6
  import { listenForStateRequests } from './eventHandlers/state';
12
- import restoreAllMocks = jest.restoreAllMocks;
13
7
 
14
8
  beforeEach(() => {
15
- restoreAllMocks();
16
-
17
- // We cannot use window as our event root during testing
18
- // since tests are executed in parallel.
19
- setRootElement(new Document().createElement('div'));
20
-
21
- // Store must be cleared before we re-listen for user attribute requests
9
+ // Store must be cleared before we listen for user attribute requests
22
10
  store.clear();
23
11
 
24
- // Also, since we keep creating new root elements, we also
25
- // need to attach to these new roots.
26
12
  listenForStateRequests();
27
13
  listenForStorageRequests();
28
14
  });
@@ -1,27 +1,13 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import UserDataRequest from './lib/UserDataRequest';
6
2
  import * as userData from './actions/userData';
7
- import { setRootElement } from './utils/customEventWrapper';
8
3
  import { listenForUserAttributeRequests } from './eventHandlers/userAttributes';
9
4
  import store from './store';
10
5
  import { listenForStateRequests } from './eventHandlers/state';
11
- import restoreAllMocks = jest.restoreAllMocks;
12
6
 
13
7
  beforeEach(() => {
14
- restoreAllMocks();
15
-
16
- // We cannot use window as our event root during testing
17
- // since tests are executed in parallel.
18
- setRootElement(new Document().createElement('div'));
19
-
20
- // Store must be cleared before we re-listen for user attribute requests
8
+ // Store must be cleared before we listen for user attribute requests
21
9
  store.clear();
22
10
 
23
- // Also, since we keep creating new root elements, we also
24
- // need to attach to these new roots.
25
11
  listenForUserAttributeRequests();
26
12
  listenForStateRequests();
27
13
  });
package/src/index.ts CHANGED
@@ -50,7 +50,10 @@ export const saveStorage = (storage: { [index: string]: Object }) => {
50
50
  dispatch(new CustomEvent(AmediaUserEvents.SAVE_STORAGE, { detail: storage }));
51
51
  };
52
52
 
53
- listenForStateRequests();
54
- listenForUserAttributeRequests();
55
- listenForStorageRequests();
56
- runJanitor();
53
+ // @ts-ignore
54
+ if (!globalThis.amediaUserTestMode) {
55
+ listenForStateRequests();
56
+ listenForUserAttributeRequests();
57
+ listenForStorageRequests();
58
+ runJanitor();
59
+ }
@@ -0,0 +1,18 @@
1
+ import * as localhostCheck from '../utils/localhostCheck';
2
+ import { runJanitor } from './index';
3
+ import log from '../utils/log';
4
+
5
+ describe('when janitor is started on localhost', () => {
6
+ let logWarnSpy: jest.SpyInstance;
7
+ beforeEach(() => {
8
+ jest.spyOn(localhostCheck, 'isRunningOnLocalhost').mockReturnValue(true);
9
+ logWarnSpy = jest.spyOn(log, 'warn').mockImplementation();
10
+ runJanitor();
11
+ });
12
+
13
+ it('should log a warning', () => {
14
+ expect(logWarnSpy).toBeCalledWith(
15
+ '@amedia/user started on localhost. In this scenario we have no way to resolve any login-, access- or userdata. Expect errors and/or redirects if you try.'
16
+ );
17
+ });
18
+ });
@@ -3,6 +3,7 @@ import { removeUserStorage } from './jobs/removeUserStorage';
3
3
  import { dispatch, listenWithExclusivity } from '../utils/customEventWrapper';
4
4
  import { attemptAutoLoginJob } from '../autologin';
5
5
  import daxSubCookieHandler from './jobs/daxsubCookie';
6
+ import log from '../utils/log';
6
7
 
7
8
  const jobs = [
8
9
  attemptAutoLoginJob,
@@ -16,6 +17,14 @@ async function performJobs() {
16
17
  // None of our current jobs make any sense to run in a web worker or other settings without a window object.
17
18
  return;
18
19
  }
20
+ if (globalThis?.location?.hostname === 'localhost') {
21
+ // Neither if we're running on localhost as this will never be able to resolve any data
22
+ // eslint-disable-next-line no-console
23
+ log.warn(
24
+ '@amedia/user started on localhost. In this scenario we have no way to resolve any login-, access- or userdata. Expect errors and/or redirects if you try.'
25
+ );
26
+ return;
27
+ }
19
28
  // eslint-disable-next-line no-restricted-syntax
20
29
  for (const job of jobs) {
21
30
  // eslint-disable-next-line no-await-in-loop
@@ -1,23 +1,15 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
1
  import accessCookieRefresher from './accessCookieRefresher';
6
2
  import * as url from '../../utils/url';
7
3
  import UserDataRequest from '../../lib/UserDataRequest';
8
4
  import * as cookie from '../../lib/cookie';
9
5
  import * as authorization from '../../actions/authorization';
10
- import { setRootElement } from '../../utils/customEventWrapper';
11
6
  import store from '../../store';
12
- import restoreAllMocks = jest.restoreAllMocks;
13
7
  import spyOn = jest.spyOn;
14
8
  import { AccessFeatures } from '../../clients/jupiter';
15
9
 
16
10
  const mockUuid = '3-1-33-7';
17
11
 
18
12
  beforeEach(() => {
19
- setRootElement(new Document().createElement('div'));
20
- restoreAllMocks();
21
13
  spyOn(url, 'getCurrentPublicationDomain').mockReturnValue('www.avisnavn.no');
22
14
  url.setCurrentHostname('www.avisnavn.no');
23
15
  jest
@@ -1,12 +1,6 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
- import fetch from 'jest-fetch-mock';
6
1
  import daxSubCookieHandler from './daxsubCookie';
7
2
  import * as cookie from '../../lib/cookie';
8
3
  import store from '../../store';
9
- import { setRootElement } from '../../utils/customEventWrapper';
10
4
  import { listenForStateRequests } from '../../eventHandlers/state';
11
5
  import { listenForUserAttributeRequests } from '../../eventHandlers/userAttributes';
12
6
  import UserDataRequest from '../../lib/UserDataRequest';
@@ -15,22 +9,14 @@ import log from '../../utils/log';
15
9
  describe('daxSubCookieHandler', () => {
16
10
  beforeEach(() => {
17
11
  store.clear();
18
- jest.restoreAllMocks();
19
12
  spyOn(cookie, 'setCookie');
20
13
  spyOn(cookie, 'removeCookie');
21
- fetch.resetMocks();
22
-
23
- // We cannot use window as our event root during testing
24
- // since tests are executed in parallel.
25
- setRootElement(new Document().createElement('div'));
26
14
 
27
- // Also, since we keep creating new root elements, we also
28
- // need to attach to these new roots.
29
15
  listenForStateRequests();
30
16
  listenForUserAttributeRequests();
31
17
  });
32
18
 
33
- describe('when fetching user data failes', () => {
19
+ describe('when fetching user data fails', () => {
34
20
  beforeEach(async () => {
35
21
  spyOn(UserDataRequest.prototype, 'fetch').and.returnValue(
36
22
  Promise.reject(new Error('Could not fetch'))
@@ -1,14 +1,9 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
1
  import store from '../../store';
5
2
  import { removeUserStorage } from './removeUserStorage';
6
3
  import { listenForStateRequests } from '../../eventHandlers/state';
7
- import restoreAllMocks = jest.restoreAllMocks;
8
4
 
9
5
  describe('removeUserStorage', () => {
10
6
  beforeEach(() => {
11
- restoreAllMocks();
12
7
  store.clear();
13
8
  spyOn(store, 'set').and.callThrough();
14
9
  listenForStateRequests();