@amedia/user 0.13.6 → 0.13.8

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/src/lib/cookie.ts CHANGED
@@ -107,3 +107,15 @@ export function setCookie(
107
107
  export function removeCookie(name: string): void {
108
108
  setCookie(name);
109
109
  }
110
+
111
+ /**
112
+ * This function should only be used in tests, as it will remove all cookies a user has on the domain.
113
+ */
114
+ export function removeAllCookies() {
115
+ const cookies = document.cookie.split(';');
116
+
117
+ cookies.forEach((cookieToDelete) => {
118
+ const eqPos = cookieToDelete.indexOf('=');
119
+ removeCookie(eqPos > -1 ? cookieToDelete.substr(0, eqPos) : cookieToDelete);
120
+ });
121
+ }
package/testSetup.js ADDED
@@ -0,0 +1 @@
1
+ require('jest-extended');
@@ -1 +0,0 @@
1
- export {};
@@ -1,71 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import store from '../store';
5
- import { UserDataRequest } from '../index';
6
- import { listenForUserAttributeRequests } from '../eventHandlers/userAttributes';
7
- import { listenForStateRequests } from '../eventHandlers/state';
8
- import { listenForStorageRequests } from '../eventHandlers/storage';
9
- import { setRootElement } from '../utils/customEventWrapper';
10
- import * as europa from '../clients/europa';
11
-
12
- beforeEach(() => {
13
- // We cannot use window as our event root during testing
14
- // since tests are executed in parallel.
15
- setRootElement(new Document());
16
-
17
- store.clear();
18
-
19
- // Also, since we keep creating new root elements, we also
20
- // need to attach to these new roots.
21
- listenForUserAttributeRequests();
22
- listenForStateRequests();
23
- listenForStorageRequests();
24
- });
25
-
26
- describe('UserDataRequest', () => {
27
- describe('when fetching', () => {
28
- describe('and is logged in', () => {
29
- beforeEach(() => {
30
- store.set('state', { isLoggedIn: true });
31
- store.set('userAttributes', {
32
- name: 'Donald Duck',
33
- });
34
- });
35
-
36
- describe('and already have all requested attributes', () => {
37
- let response;
38
- beforeEach(async () => {
39
- response = await new UserDataRequest()
40
- .withAttributes(['name'])
41
- .fetch();
42
- });
43
-
44
- it('should have resolved to include name', () => {
45
- expect(response.attributes).toEqual({ name: 'Donald Duck' });
46
- });
47
-
48
- it('should be logged in', () => {
49
- expect(response.state).toEqual({ isLoggedIn: true });
50
- });
51
- });
52
- });
53
-
54
- describe('and not logged in', () => {
55
- beforeEach(() => {
56
- store.set('state', { isLoggedIn: false });
57
- });
58
-
59
- describe('when getting storage', () => {
60
- beforeEach(async () => {
61
- spyOn(europa, 'getNamespaces');
62
- await new UserDataRequest().withStorage(['euucp']).fetch();
63
- });
64
-
65
- it('should not request data', () => {
66
- expect(europa.getNamespaces).not.toHaveBeenCalled();
67
- });
68
- });
69
- });
70
- });
71
- });