@amedia/user 0.14.12 → 0.14.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amedia/user",
3
- "version": "0.14.12",
3
+ "version": "0.14.14",
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)",
@@ -44,6 +44,8 @@
44
44
  "@types/dexie": "^1.3.1",
45
45
  "@types/jest": "^26.0.24",
46
46
  "@typescript-eslint/eslint-plugin": "^4.29.1",
47
+ "express": "^4.17.1",
48
+ "cors": "^2.8.5",
47
49
  "esbuild": "^0.12.19",
48
50
  "eslint": "^7.32.0",
49
51
  "eslint-config-airbnb-typescript": "^12.3.1",
@@ -121,7 +121,7 @@ describe('attemptAutoLoginJob', () => {
121
121
  });
122
122
  describe('when no strategy triggers auto login', () => {
123
123
  beforeEach(async () => {
124
- attemptAutoLoginJob();
124
+ await attemptAutoLoginJob();
125
125
  });
126
126
 
127
127
  itShouldCallThirdPartyCookieStrategy();
@@ -132,7 +132,7 @@ describe('attemptAutoLoginJob', () => {
132
132
  describe('when tried within the last minute', () => {
133
133
  beforeEach(async () => {
134
134
  getCookieSpy.and.returnValue(Date.now());
135
- attemptAutoLoginJob();
135
+ await attemptAutoLoginJob();
136
136
  });
137
137
  itShouldCallThirdPartyCookieStrategy();
138
138
  itShouldNotNavigateAway();
@@ -143,7 +143,7 @@ describe('attemptAutoLoginJob', () => {
143
143
  getCookieSpy.and.returnValue(
144
144
  Date.now() - AUTOLOGIN_COOKIE_TTL - 1000
145
145
  );
146
- attemptAutoLoginJob();
146
+ await attemptAutoLoginJob();
147
147
  });
148
148
  itShouldCallThirdPartyCookieStrategy();
149
149
  itShouldNotNavigateAway();
@@ -157,7 +157,7 @@ describe('attemptAutoLoginJob', () => {
157
157
  store.merge('state', {
158
158
  emergencyMode: ['aid'],
159
159
  });
160
- attemptAutoLoginJob();
160
+ await attemptAutoLoginJob();
161
161
  });
162
162
 
163
163
  it('should not try third party auto login', () => {
@@ -194,7 +194,7 @@ describe('attemptPaywallAutoLogin', () => {
194
194
  });
195
195
  });
196
196
  store.set('state', { isLoggedIn: true });
197
- attemptPaywallAutoLogin();
197
+ await attemptPaywallAutoLogin();
198
198
  });
199
199
  });
200
200
 
@@ -221,7 +221,7 @@ describe('attemptPaywallAutoLogin', () => {
221
221
  delete global.top; // Set window.top to something other than window.self
222
222
  // @ts-ignore
223
223
  global.top = {};
224
- attemptPaywallAutoLogin();
224
+ await attemptPaywallAutoLogin();
225
225
  });
226
226
  afterEach(() => {
227
227
  // @ts-ignore
@@ -244,7 +244,7 @@ describe('attemptPaywallAutoLogin', () => {
244
244
  describe('when tried within the last minute', () => {
245
245
  beforeEach(async () => {
246
246
  getCookieSpy.and.returnValue(Date.now());
247
- attemptPaywallAutoLogin();
247
+ await attemptPaywallAutoLogin();
248
248
  });
249
249
  itShouldNotNavigateAway();
250
250
  });
@@ -85,7 +85,7 @@ const attemptAutologin = async (strategies: Strategies) => {
85
85
  * and will in turn cause flickering and unnecessary (and often aborted) request to
86
86
  * various backends.
87
87
  */
88
- return new Promise(() => {});
88
+ return new Promise<boolean>(() => {});
89
89
  }
90
90
  return true;
91
91
  });
@@ -96,7 +96,7 @@ const attemptAutologin = async (strategies: Strategies) => {
96
96
  }
97
97
  };
98
98
 
99
- export const attemptAutoLoginJob = async () =>
99
+ export const attemptAutoLoginJob = () =>
100
100
  attemptAutologin([
101
101
  {
102
102
  name: 'third_party',
@@ -104,7 +104,7 @@ export const attemptAutoLoginJob = async () =>
104
104
  },
105
105
  ]);
106
106
 
107
- export const attemptPaywallAutoLogin = async () =>
107
+ export const attemptPaywallAutoLogin = () =>
108
108
  attemptAutologin([
109
109
  {
110
110
  name: 'paywall',
@@ -218,9 +218,12 @@ describe('PaywallUnlocker', () => {
218
218
 
219
219
  describe('with redirect requested', () => {
220
220
  beforeEach(async () => {
221
- unlockResponse = await new PaywallUnlockRequest()
221
+ new PaywallUnlockRequest()
222
222
  .redirectOnAccess('https://redirect.pls')
223
- .tryUnlock();
223
+ .tryUnlock()
224
+ .then((res) => {
225
+ unlockResponse = res;
226
+ });
224
227
  });
225
228
 
226
229
  it('should give access with access features', () => {
@@ -231,10 +234,19 @@ describe('PaywallUnlocker', () => {
231
234
  });
232
235
  });
233
236
 
234
- it('should navigate to expected url', () => {
235
- expect(location.replace).toHaveBeenCalledWith(
236
- 'https://redirect.pls'
237
- );
237
+ it('should navigate to expected url', (done) => {
238
+ /**
239
+ * This is not great.
240
+ * Since tryUnlock performs some async actions and we, by design,
241
+ * don't want to resolve tryUnlock when navigating, we have to
242
+ * wait for the next event loop to check location.
243
+ */
244
+ setTimeout(() => {
245
+ expect(location.replace).toHaveBeenCalledWith(
246
+ 'https://redirect.pls'
247
+ );
248
+ done();
249
+ }, 0);
238
250
  });
239
251
 
240
252
  itShouldAttemptActivationWithAccessFeatures(['newspaper']);
@@ -243,9 +255,12 @@ describe('PaywallUnlocker', () => {
243
255
 
244
256
  describe('with reload requested', () => {
245
257
  beforeEach(async () => {
246
- unlockResponse = await new PaywallUnlockRequest()
258
+ new PaywallUnlockRequest()
247
259
  .reloadOnAccess()
248
- .tryUnlock();
260
+ .tryUnlock()
261
+ .then((res) => {
262
+ unlockResponse = res;
263
+ });
249
264
  });
250
265
 
251
266
  it('should give access with access features', () => {
@@ -256,8 +271,11 @@ describe('PaywallUnlocker', () => {
256
271
  });
257
272
  });
258
273
 
259
- it('should reload on access', () => {
260
- expect(location.reload).toHaveBeenCalled();
274
+ it('should reload on access', (done) => {
275
+ setTimeout(() => {
276
+ expect(location.reload).toHaveBeenCalled();
277
+ done();
278
+ }, 0);
261
279
  });
262
280
 
263
281
  itShouldAttemptActivationWithAccessFeatures(['newspaper']);
@@ -134,6 +134,9 @@ class PaywallUnlockRequest {
134
134
  if (this.requestedUrl) {
135
135
  location.replace(this.requestedUrl);
136
136
  }
137
+
138
+ // Don't resolve tryUnlock promise if we're being reloaded/navigated away
139
+ return new Promise(() => {});
137
140
  }
138
141
  return {
139
142
  isLoggedIn: true,