@magento/experience-platform-connector 1.0.0-alpha.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.
Files changed (56) hide show
  1. package/intercept.js +24 -0
  2. package/package.json +30 -0
  3. package/src/__tests__/__snapshots__/utils.spec.js.snap +137 -0
  4. package/src/__tests__/utils.spec.js +52 -0
  5. package/src/config.js +31 -0
  6. package/src/handleEvent.js +9 -0
  7. package/src/handlers/__tests__/__mocks__/cartAddItem.js +36 -0
  8. package/src/handlers/__tests__/__mocks__/cartPageView.js +880 -0
  9. package/src/handlers/__tests__/__mocks__/categoryPageView.js +9 -0
  10. package/src/handlers/__tests__/__mocks__/checkoutPageView.js +138 -0
  11. package/src/handlers/__tests__/__mocks__/completeCheckout.js +156 -0
  12. package/src/handlers/__tests__/__mocks__/createAccount.js +9 -0
  13. package/src/handlers/__tests__/__mocks__/editAccount.js +9 -0
  14. package/src/handlers/__tests__/__mocks__/miniCartView.js +846 -0
  15. package/src/handlers/__tests__/__mocks__/orderConfirmationPageView.js +67 -0
  16. package/src/handlers/__tests__/__mocks__/pageView.js +7 -0
  17. package/src/handlers/__tests__/__mocks__/placeOrderButtonClicked.js +161 -0
  18. package/src/handlers/__tests__/__mocks__/productPageView.js +15 -0
  19. package/src/handlers/__tests__/__mocks__/searchPageRequest.js +22 -0
  20. package/src/handlers/__tests__/__mocks__/searchRequestSent.js +34 -0
  21. package/src/handlers/__tests__/__mocks__/searchResponseReceived.js +106 -0
  22. package/src/handlers/__tests__/__snapshots__/shoppingMiniCartView.spec.js.snap +137 -0
  23. package/src/handlers/__tests__/addToCart.spec.js +73 -0
  24. package/src/handlers/__tests__/categoryPageView.spec.js +55 -0
  25. package/src/handlers/__tests__/completeCheckout.spec.js +70 -0
  26. package/src/handlers/__tests__/createAccount.spec.js +43 -0
  27. package/src/handlers/__tests__/editAccount.spec.js +43 -0
  28. package/src/handlers/__tests__/pageView.spec.js +46 -0
  29. package/src/handlers/__tests__/placeOrder.spec.js +55 -0
  30. package/src/handlers/__tests__/productPageView.spec.js +64 -0
  31. package/src/handlers/__tests__/searchRequestSent.spec.js +119 -0
  32. package/src/handlers/__tests__/searchResponseReceived.spec.js +143 -0
  33. package/src/handlers/__tests__/shoppingCartPageView.spec.js +198 -0
  34. package/src/handlers/__tests__/shoppingMiniCartView.spec.js +36 -0
  35. package/src/handlers/__tests__/signIn.spec.js +73 -0
  36. package/src/handlers/__tests__/startCheckout.spec.js +193 -0
  37. package/src/handlers/addToCart.js +60 -0
  38. package/src/handlers/categoryPageView.js +34 -0
  39. package/src/handlers/completeCheckout.js +49 -0
  40. package/src/handlers/createAccount.js +25 -0
  41. package/src/handlers/editAccount.js +25 -0
  42. package/src/handlers/pageView.js +26 -0
  43. package/src/handlers/placeOrder.js +32 -0
  44. package/src/handlers/productPageView.js +41 -0
  45. package/src/handlers/searchRequestSent.js +38 -0
  46. package/src/handlers/searchResponseReceived.js +39 -0
  47. package/src/handlers/shoppingCartPageView.js +45 -0
  48. package/src/handlers/shoppingMiniCartView.js +31 -0
  49. package/src/handlers/signIn.js +29 -0
  50. package/src/handlers/startCheckout.js +45 -0
  51. package/src/hooks/useExtensionContext.js +21 -0
  52. package/src/main.js +116 -0
  53. package/src/queries/getExtensionContext.js +31 -0
  54. package/src/utils.js +101 -0
  55. package/src/wrappers/wrapUseAccountMenu.js +29 -0
  56. package/src/wrappers/wrapUseAutocomplete.js +48 -0
@@ -0,0 +1,70 @@
1
+ import handler from '../completeCheckout';
2
+ import completeCheckoutEvent from './__mocks__/completeCheckout';
3
+
4
+ describe('canHandle()', () => {
5
+ it('returns true for the correct event type', () => {
6
+ expect(handler.canHandle(completeCheckoutEvent)).toBeTruthy();
7
+ });
8
+
9
+ it('returns false for non supported event types', () => {
10
+ const mockEvent = {
11
+ type: 'USER_SIGN_OUT',
12
+ payload: {}
13
+ };
14
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
15
+ });
16
+ });
17
+
18
+ describe('handle()', () => {
19
+ it('calls the correct sdk functions with the correct context value', () => {
20
+ const mockSdk = {
21
+ context: {
22
+ setOrder: jest.fn(),
23
+ setPage: jest.fn()
24
+ },
25
+ publish: {
26
+ placeOrder: jest.fn(),
27
+ pageView: jest.fn()
28
+ }
29
+ };
30
+
31
+ handler.handle(mockSdk, completeCheckoutEvent);
32
+
33
+ expect(mockSdk.context.setOrder).toHaveBeenCalledTimes(1);
34
+ expect(mockSdk.context.setOrder.mock.calls[0][0])
35
+ .toMatchInlineSnapshot(`
36
+ Object {
37
+ "grandTotal": 40,
38
+ "orderId": "001",
39
+ "orderType": "checkout",
40
+ "payments": Array [
41
+ Object {
42
+ "paymentMethodCode": "Visa",
43
+ "paymentMethodName": "Visa",
44
+ "total": 40,
45
+ },
46
+ ],
47
+ "shipping": Object {
48
+ "shippingAmount": 13,
49
+ "shippingMethod": "method",
50
+ },
51
+ }
52
+ `);
53
+
54
+ expect(mockSdk.context.setPage).toHaveBeenCalledTimes(1);
55
+ expect(mockSdk.context.setPage.mock.calls[0][0]).toMatchInlineSnapshot(`
56
+ Object {
57
+ "eventType": "visibilityHidden",
58
+ "maxXOffset": 0,
59
+ "maxYOffset": 0,
60
+ "minXOffset": 0,
61
+ "minYOffset": 0,
62
+ "pageName": "Order Confirmation",
63
+ "pageType": "Order Confirmation Page",
64
+ }
65
+ `);
66
+
67
+ expect(mockSdk.publish.pageView).toHaveBeenCalledTimes(1);
68
+ expect(mockSdk.publish.placeOrder).toHaveBeenCalledTimes(1);
69
+ });
70
+ });
@@ -0,0 +1,43 @@
1
+ import handler from '../createAccount';
2
+ import createAccountEvent from './__mocks__/createAccount';
3
+
4
+ describe('canHandle()', () => {
5
+ it('returns true for the correct event type', () => {
6
+ expect(handler.canHandle(createAccountEvent)).toBeTruthy();
7
+ });
8
+
9
+ it('returns false for non supported event types', () => {
10
+ const mockEvent = {
11
+ type: 'USER_SIGN_OUT',
12
+ payload: {}
13
+ };
14
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
15
+ });
16
+ });
17
+
18
+ describe('handle()', () => {
19
+ it('calls the correct sdk functions with the correct context value', () => {
20
+ const mockSdk = {
21
+ context: {
22
+ setAccount: jest.fn()
23
+ },
24
+ publish: {
25
+ createAccount: jest.fn()
26
+ }
27
+ };
28
+
29
+ handler.handle(mockSdk, createAccountEvent);
30
+
31
+ expect(mockSdk.context.setAccount).toHaveBeenCalledTimes(1);
32
+ expect(mockSdk.context.setAccount.mock.calls[0][0])
33
+ .toMatchInlineSnapshot(`
34
+ Object {
35
+ "emailAddress": "Stephen.Strange@fake.email",
36
+ "firstName": "Stephen",
37
+ "lastName": "Strange",
38
+ }
39
+ `);
40
+
41
+ expect(mockSdk.publish.createAccount).toHaveBeenCalledTimes(1);
42
+ });
43
+ });
@@ -0,0 +1,43 @@
1
+ import handler from '../editAccount';
2
+ import editAccountEvent from './__mocks__/editAccount';
3
+
4
+ describe('canHandle()', () => {
5
+ it('returns true for the correct event type', () => {
6
+ expect(handler.canHandle(editAccountEvent)).toBeTruthy();
7
+ });
8
+
9
+ it('returns false for non supported event types', () => {
10
+ const mockEvent = {
11
+ type: 'USER_SIGN_OUT',
12
+ payload: {}
13
+ };
14
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
15
+ });
16
+ });
17
+
18
+ describe('handle()', () => {
19
+ it('calls the correct sdk functions with the correct context value', () => {
20
+ const mockSdk = {
21
+ context: {
22
+ setAccount: jest.fn()
23
+ },
24
+ publish: {
25
+ editAccount: jest.fn()
26
+ }
27
+ };
28
+
29
+ handler.handle(mockSdk, editAccountEvent);
30
+
31
+ expect(mockSdk.context.setAccount).toHaveBeenCalledTimes(1);
32
+ expect(mockSdk.context.setAccount.mock.calls[0][0])
33
+ .toMatchInlineSnapshot(`
34
+ Object {
35
+ "emailAddress": "Stephen.Strange@fake.email",
36
+ "firstName": "Stephen",
37
+ "lastName": "Strange",
38
+ }
39
+ `);
40
+
41
+ expect(mockSdk.publish.editAccount).toHaveBeenCalledTimes(1);
42
+ });
43
+ });
@@ -0,0 +1,46 @@
1
+ import handler from '../pageView';
2
+ import cmsPageViewEvent from './__mocks__/pageView';
3
+
4
+ describe('canHandle()', () => {
5
+ it('returns true for the correct event type', () => {
6
+ expect(handler.canHandle(cmsPageViewEvent)).toBeTruthy();
7
+ });
8
+
9
+ it('returns false for non supported event types', () => {
10
+ const mockEvent = {
11
+ type: 'USER_SIGN_OUT',
12
+ payload: {}
13
+ };
14
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
15
+ });
16
+ });
17
+
18
+ describe('handle()', () => {
19
+ it('calls the correct sdk functions with the correct context value', () => {
20
+ const mockSdk = {
21
+ context: {
22
+ setPage: jest.fn()
23
+ },
24
+ publish: {
25
+ pageView: jest.fn()
26
+ }
27
+ };
28
+
29
+ handler.handle(mockSdk, cmsPageViewEvent);
30
+
31
+ expect(mockSdk.context.setPage).toHaveBeenCalledTimes(1);
32
+ expect(mockSdk.context.setPage.mock.calls[0][0]).toMatchInlineSnapshot(`
33
+ Object {
34
+ "eventType": "visibilityHidden",
35
+ "maxXOffset": 0,
36
+ "maxYOffset": 0,
37
+ "minXOffset": 0,
38
+ "minYOffset": 0,
39
+ "pageName": "Home Page - Venia",
40
+ "pageType": "CMS",
41
+ }
42
+ `);
43
+
44
+ expect(mockSdk.publish.pageView).toHaveBeenCalledTimes(1);
45
+ });
46
+ });
@@ -0,0 +1,55 @@
1
+ import handler from '../placeOrder';
2
+ import placeOrderEvent from './__mocks__/placeOrderButtonClicked';
3
+
4
+ describe('canHandle()', () => {
5
+ it('returns true for the correct event type', () => {
6
+ expect(handler.canHandle(placeOrderEvent)).toBeTruthy();
7
+ });
8
+
9
+ it('returns false for non supported event types', () => {
10
+ const mockEvent = {
11
+ type: 'USER_SIGN_OUT',
12
+ payload: {}
13
+ };
14
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
15
+ });
16
+ });
17
+
18
+ describe('handle()', () => {
19
+ it('calls the correct sdk functions with the correct context value', () => {
20
+ const mockSdk = {
21
+ context: {
22
+ setOrder: jest.fn()
23
+ },
24
+ publish: {
25
+ placeOrder: jest.fn()
26
+ }
27
+ };
28
+
29
+ handler.handle(mockSdk, placeOrderEvent);
30
+
31
+ expect(mockSdk.context.setOrder).toHaveBeenCalledTimes(1);
32
+ expect(mockSdk.context.setOrder.mock.calls[0][0])
33
+ .toMatchInlineSnapshot(`
34
+ Object {
35
+ "grandTotal": 466.01,
36
+ "orderType": "checkout",
37
+ "payments": Array [
38
+ Object {
39
+ "paymentMethodCode": "Credit Card",
40
+ "paymentMethodName": "Credit Card",
41
+ "total": 466.01,
42
+ },
43
+ ],
44
+ "shipping": Object {
45
+ "shippingAmount": 0,
46
+ "shippingMethod": "Free",
47
+ },
48
+ }
49
+ `);
50
+
51
+ // Since we're sending this event after loading the order confirmation page,
52
+ // We don't need to send it here since we don't have an order number anyways.
53
+ expect(mockSdk.publish.placeOrder).toHaveBeenCalledTimes(0);
54
+ });
55
+ });
@@ -0,0 +1,64 @@
1
+ import handler from '../productPageView';
2
+ import productPageViewEvent from './__mocks__/productPageView';
3
+
4
+ describe('canHandle()', () => {
5
+ it('returns true for the correct event type', () => {
6
+ expect(handler.canHandle(productPageViewEvent)).toBeTruthy();
7
+ });
8
+
9
+ it('returns false for non supported event types', () => {
10
+ const mockEvent = {
11
+ type: 'USER_SIGN_OUT',
12
+ payload: {}
13
+ };
14
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
15
+ });
16
+ });
17
+
18
+ describe('handle()', () => {
19
+ it('calls the correct sdk functions with the correct context value', () => {
20
+ const mockSdk = {
21
+ context: {
22
+ setPage: jest.fn(),
23
+ setProduct: jest.fn()
24
+ },
25
+ publish: {
26
+ pageView: jest.fn(),
27
+ productPageView: jest.fn()
28
+ }
29
+ };
30
+
31
+ handler.handle(mockSdk, productPageViewEvent);
32
+
33
+ expect(mockSdk.context.setProduct).toHaveBeenCalledTimes(1);
34
+ expect(mockSdk.context.setProduct.mock.calls[0][0])
35
+ .toMatchInlineSnapshot(`
36
+ Object {
37
+ "canonicalUrl": "selena-pants",
38
+ "name": "Selena Pants",
39
+ "pricing": Object {
40
+ "currencyCode": "USD",
41
+ "maximalPrice": 40,
42
+ },
43
+ "productId": "234d",
44
+ "sku": "343g3434t",
45
+ }
46
+ `);
47
+
48
+ expect(mockSdk.context.setPage).toHaveBeenCalledTimes(1);
49
+ expect(mockSdk.context.setPage.mock.calls[0][0]).toMatchInlineSnapshot(`
50
+ Object {
51
+ "eventType": "visibilityHidden",
52
+ "maxXOffset": 0,
53
+ "maxYOffset": 0,
54
+ "minXOffset": 0,
55
+ "minYOffset": 0,
56
+ "pageName": "Selena Pants",
57
+ "pageType": "PDP",
58
+ }
59
+ `);
60
+
61
+ expect(mockSdk.publish.productPageView).toHaveBeenCalledTimes(1);
62
+ expect(mockSdk.publish.pageView).toHaveBeenCalledTimes(1);
63
+ });
64
+ });
@@ -0,0 +1,119 @@
1
+ import handler from '../searchRequestSent';
2
+ import {
3
+ searchRequestEvent,
4
+ searchbarRequestEvent
5
+ } from './__mocks__/searchRequestSent';
6
+
7
+ describe('canHandle()', () => {
8
+ it('returns true for the correct event type', () => {
9
+ expect(handler.canHandle(searchRequestEvent)).toBeTruthy();
10
+ });
11
+
12
+ it('returns true for the correct event type', () => {
13
+ expect(handler.canHandle(searchbarRequestEvent)).toBeTruthy();
14
+ });
15
+
16
+ it('returns false for non supported event types', () => {
17
+ const mockEvent = {
18
+ type: 'USER_SIGN_OUT',
19
+ payload: {}
20
+ };
21
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
22
+ });
23
+ });
24
+
25
+ describe('handle()', () => {
26
+ it('calls the correct sdk functions with the correct context value', () => {
27
+ const mockSdk = {
28
+ context: {
29
+ setSearchInput: jest.fn()
30
+ },
31
+ publish: {
32
+ searchRequestSent: jest.fn()
33
+ }
34
+ };
35
+
36
+ handler.handle(mockSdk, searchRequestEvent);
37
+
38
+ expect(mockSdk.context.setSearchInput).toHaveBeenCalledTimes(1);
39
+ expect(mockSdk.context.setSearchInput.mock.calls[0][0])
40
+ .toMatchInlineSnapshot(`
41
+ Object {
42
+ "units": Array [
43
+ Object {
44
+ "currentPage": 1,
45
+ "filter": Array [
46
+ Object {
47
+ "attribute": "category_id",
48
+ "in": Array [
49
+ "Bottoms,11",
50
+ ],
51
+ },
52
+ Object {
53
+ "attribute": "fashion_color",
54
+ "in": Array [
55
+ "Rain,34",
56
+ "Mint,25",
57
+ ],
58
+ },
59
+ ],
60
+ "pageSize": 12,
61
+ "phrase": "selena",
62
+ "queryTypes": Array [
63
+ "products",
64
+ ],
65
+ "searchUnitId": "productPage",
66
+ "sort": Array [
67
+ Object {
68
+ "attribute": "relevance",
69
+ "direction": "DESC",
70
+ },
71
+ ],
72
+ },
73
+ ],
74
+ }
75
+ `);
76
+
77
+ expect(mockSdk.publish.searchRequestSent).toHaveBeenCalledTimes(1);
78
+ });
79
+
80
+ it('calls the correct sdk functions with the correct context value', () => {
81
+ const mockSdk = {
82
+ context: {
83
+ setSearchInput: jest.fn()
84
+ },
85
+ publish: {
86
+ searchRequestSent: jest.fn()
87
+ }
88
+ };
89
+
90
+ handler.handle(mockSdk, searchbarRequestEvent);
91
+
92
+ expect(mockSdk.context.setSearchInput).toHaveBeenCalledTimes(1);
93
+ expect(mockSdk.context.setSearchInput.mock.calls[0][0])
94
+ .toMatchInlineSnapshot(`
95
+ Object {
96
+ "units": Array [
97
+ Object {
98
+ "currentPage": 1,
99
+ "filter": Array [],
100
+ "pageSize": 3,
101
+ "phrase": "selena",
102
+ "queryTypes": Array [
103
+ "products",
104
+ ],
105
+ "searchUnitId": "productPage",
106
+ "sort": Array [
107
+ Object {
108
+ "attribute": undefined,
109
+ "direction": undefined,
110
+ },
111
+ ],
112
+ },
113
+ ],
114
+ }
115
+ `);
116
+
117
+ expect(mockSdk.publish.searchRequestSent).toHaveBeenCalledTimes(1);
118
+ });
119
+ });
@@ -0,0 +1,143 @@
1
+ import handler from '../searchResponseReceived';
2
+ import { searchResponseEvent } from './__mocks__/searchResponseReceived';
3
+
4
+ describe('canHandle()', () => {
5
+ it('returns true for the correct event type', () => {
6
+ expect(handler.canHandle(searchResponseEvent)).toBeTruthy();
7
+ });
8
+
9
+ it('returns false for non supported event types', () => {
10
+ const mockEvent = {
11
+ type: 'USER_SIGN_OUT',
12
+ payload: {}
13
+ };
14
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
15
+ });
16
+ });
17
+
18
+ describe('handle()', () => {
19
+ it('calls the correct sdk functions with the correct context value', () => {
20
+ const mockSdk = {
21
+ context: {
22
+ setSearchResults: jest.fn()
23
+ },
24
+ publish: {
25
+ searchResponseReceived: jest.fn()
26
+ }
27
+ };
28
+
29
+ handler.handle(mockSdk, searchResponseEvent);
30
+
31
+ expect(mockSdk.context.setSearchResults).toHaveBeenCalledTimes(1);
32
+ expect(mockSdk.context.setSearchResults.mock.calls[0][0])
33
+ .toMatchInlineSnapshot(`
34
+ Object {
35
+ "units": Array [
36
+ Object {
37
+ "categories": Array [
38
+ Object {
39
+ "__typename": "AggregationOption",
40
+ "label": "Bottoms",
41
+ "value": "11",
42
+ },
43
+ Object {
44
+ "__typename": "AggregationOption",
45
+ "label": "Pants & Shorts",
46
+ "value": "12",
47
+ },
48
+ ],
49
+ "facets": Array [],
50
+ "page": 1,
51
+ "perPage": 3,
52
+ "products": Array [
53
+ Object {
54
+ "__typename": "ConfigurableProduct",
55
+ "id": 1144,
56
+ "name": "Selena Pants",
57
+ "price": Object {
58
+ "__typename": "ProductPrices",
59
+ "regularPrice": Object {
60
+ "__typename": "Price",
61
+ "amount": Object {
62
+ "__typename": "Money",
63
+ "currency": "USD",
64
+ "value": 108,
65
+ },
66
+ },
67
+ },
68
+ "price_range": Object {
69
+ "__typename": "PriceRange",
70
+ "maximum_price": Object {
71
+ "__typename": "ProductPrice",
72
+ "discount": Object {
73
+ "__typename": "ProductDiscount",
74
+ "amount_off": 0,
75
+ },
76
+ "final_price": Object {
77
+ "__typename": "Money",
78
+ "currency": "USD",
79
+ "value": 108,
80
+ },
81
+ },
82
+ },
83
+ "sku": "VP01",
84
+ "small_image": Object {
85
+ "__typename": "ProductImage",
86
+ "url": "https://beacon-rjroszy-vzsrtettsztvg.us-4.magentosite.cloud/media/catalog/product/cache/37f3b100da589f62b6681aad6ae5936f/v/p/vp01-ll_main_2.jpg",
87
+ },
88
+ "uid": "MTE0NA==",
89
+ "url_key": "selena-pants",
90
+ "url_suffix": ".html",
91
+ },
92
+ ],
93
+ "searchRequestId": "selena",
94
+ "searchUnitId": "search-bar",
95
+ "suggestions": Array [
96
+ Object {
97
+ "__typename": "ConfigurableProduct",
98
+ "id": 1144,
99
+ "name": "Selena Pants",
100
+ "price": Object {
101
+ "__typename": "ProductPrices",
102
+ "regularPrice": Object {
103
+ "__typename": "Price",
104
+ "amount": Object {
105
+ "__typename": "Money",
106
+ "currency": "USD",
107
+ "value": 108,
108
+ },
109
+ },
110
+ },
111
+ "price_range": Object {
112
+ "__typename": "PriceRange",
113
+ "maximum_price": Object {
114
+ "__typename": "ProductPrice",
115
+ "discount": Object {
116
+ "__typename": "ProductDiscount",
117
+ "amount_off": 0,
118
+ },
119
+ "final_price": Object {
120
+ "__typename": "Money",
121
+ "currency": "USD",
122
+ "value": 108,
123
+ },
124
+ },
125
+ },
126
+ "sku": "VP01",
127
+ "small_image": Object {
128
+ "__typename": "ProductImage",
129
+ "url": "https://beacon-rjroszy-vzsrtettsztvg.us-4.magentosite.cloud/media/catalog/product/cache/37f3b100da589f62b6681aad6ae5936f/v/p/vp01-ll_main_2.jpg",
130
+ },
131
+ "uid": "MTE0NA==",
132
+ "url_key": "selena-pants",
133
+ "url_suffix": ".html",
134
+ },
135
+ ],
136
+ },
137
+ ],
138
+ }
139
+ `);
140
+
141
+ expect(mockSdk.publish.searchResponseReceived).toHaveBeenCalledTimes(1);
142
+ });
143
+ });