workarea-segment_analytics 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc +35 -0
  3. data/.gitignore +19 -0
  4. data/.rubocop.yml +8 -0
  5. data/CHANGELOG.md +47 -0
  6. data/Gemfile +16 -0
  7. data/README.md +91 -0
  8. data/Rakefile +60 -0
  9. data/app/assets/javascripts/workarea/storefront/segment_analytics/dependencies/analytics.js.erb +3 -0
  10. data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/login_events.js +40 -0
  11. data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/segment_analytics.js +47 -0
  12. data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/segment_analytics_adapter.js +235 -0
  13. data/app/assets/stylesheets/segment_analytics/.keep +0 -0
  14. data/app/helpers/.keep +0 -0
  15. data/app/helpers/workarea/storefront/segment_analytics_analytics_helper.rb +40 -0
  16. data/app/views/.keep +0 -0
  17. data/app/views/workarea/storefront/users/_current_user_segment_analytics.json.jbuilder +6 -0
  18. data/bin/rails +20 -0
  19. data/config/initializers/appends.rb +18 -0
  20. data/config/initializers/workarea.rb +1 -0
  21. data/config/routes.rb +2 -0
  22. data/lib/tasks/segment_analytics_tasks.rake +4 -0
  23. data/lib/workarea/segment_analytics.rb +23 -0
  24. data/lib/workarea/segment_analytics/engine.rb +14 -0
  25. data/lib/workarea/segment_analytics/version.rb +5 -0
  26. data/script/admin_ci +9 -0
  27. data/script/ci +11 -0
  28. data/script/core_ci +9 -0
  29. data/script/plugins_ci +9 -0
  30. data/script/storefront_ci +9 -0
  31. data/test/dummy/Rakefile +6 -0
  32. data/test/dummy/app/assets/config/manifest.js +4 -0
  33. data/test/dummy/app/assets/images/.keep +0 -0
  34. data/test/dummy/app/assets/javascripts/application.js +13 -0
  35. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  36. data/test/dummy/app/controllers/application_controller.rb +3 -0
  37. data/test/dummy/app/controllers/concerns/.keep +0 -0
  38. data/test/dummy/app/helpers/application_helper.rb +2 -0
  39. data/test/dummy/app/jobs/application_job.rb +2 -0
  40. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  41. data/test/dummy/app/models/concerns/.keep +0 -0
  42. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  43. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  44. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  45. data/test/dummy/bin/bundle +3 -0
  46. data/test/dummy/bin/rails +4 -0
  47. data/test/dummy/bin/rake +4 -0
  48. data/test/dummy/bin/setup +38 -0
  49. data/test/dummy/bin/update +29 -0
  50. data/test/dummy/bin/yarn +11 -0
  51. data/test/dummy/config.ru +5 -0
  52. data/test/dummy/config/application.rb +29 -0
  53. data/test/dummy/config/boot.rb +5 -0
  54. data/test/dummy/config/cable.yml +10 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +54 -0
  57. data/test/dummy/config/environments/production.rb +91 -0
  58. data/test/dummy/config/environments/test.rb +44 -0
  59. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  60. data/test/dummy/config/initializers/assets.rb +14 -0
  61. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  63. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/test/dummy/config/initializers/inflections.rb +16 -0
  65. data/test/dummy/config/initializers/mime_types.rb +4 -0
  66. data/test/dummy/config/initializers/workarea.rb +5 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/test/dummy/config/locales/en.yml +33 -0
  69. data/test/dummy/config/puma.rb +56 -0
  70. data/test/dummy/config/routes.rb +5 -0
  71. data/test/dummy/config/secrets.yml +32 -0
  72. data/test/dummy/config/spring.rb +6 -0
  73. data/test/dummy/db/seeds.rb +2 -0
  74. data/test/dummy/lib/assets/.keep +0 -0
  75. data/test/dummy/log/.keep +0 -0
  76. data/test/dummy/package.json +5 -0
  77. data/test/javascripts/fixtures/payloads.js +232 -0
  78. data/test/javascripts/fixtures/stubs.js +56 -0
  79. data/test/javascripts/segment_analytics_spec.js +311 -0
  80. data/test/javascripts/spec_helper.js +12 -0
  81. data/test/teaspoon_env.rb +6 -0
  82. data/test/test_helper.rb +10 -0
  83. data/workarea-segment_analytics.gemspec +19 -0
  84. metadata +138 -0
@@ -0,0 +1,6 @@
1
+ %w(
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ).each { |path| Spring.watch(path) }
@@ -0,0 +1,2 @@
1
+ require 'workarea/seeds'
2
+ Workarea::Seeds.run
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "dummy",
3
+ "private": true,
4
+ "dependencies": {}
5
+ }
@@ -0,0 +1,232 @@
1
+ /*eslint no-unused-vars: 0 */
2
+ function productListPayload() {
3
+ return {
4
+ "name": "Electronics",
5
+ "page": 1,
6
+ "per_page": 20,
7
+ "impressions": [
8
+ {
9
+ "id": "4AF99AB7C8",
10
+ "name": "Heavy Duty Iron Bag",
11
+ "sku": "288457637-1",
12
+ "sale": false,
13
+ "price": 19.77,
14
+ "category": "Automotive",
15
+ "position": 0
16
+ },
17
+ {
18
+ "id": "A77BE95FD8",
19
+ "name": "Gorgeous Linen Computer",
20
+ "sku": "087096987-0",
21
+ "sale": false,
22
+ "price": 0.42,
23
+ "category": "Automotive",
24
+ "position": 1
25
+ },
26
+ {
27
+ "id": "CD2B8085BE",
28
+ "name": "Sleek Linen Gloves",
29
+ "sku": "441641257-6",
30
+ "sale": false,
31
+ "price": 18.67,
32
+ "category": "Automotive",
33
+ "position": 2
34
+ },
35
+ {
36
+ "id": "3034884ECA",
37
+ "name": "Durable Wool Hat",
38
+ "sku": "610796205-0",
39
+ "sale": false,
40
+ "price": 63.16,
41
+ "category": "Automotive",
42
+ "position": 3
43
+ },
44
+ {
45
+ "id": "3B35A19DFF",
46
+ "name": "Lightweight Rubber Coat",
47
+ "sku": "124560496-1",
48
+ "sale": false,
49
+ "price": 13.15,
50
+ "category": "Automotive",
51
+ "position": 4
52
+ },
53
+ {
54
+ "id": "F7BBD9B1D2",
55
+ "name": "Rustic Paper Keyboard",
56
+ "sku": "243345833-1",
57
+ "sale": false,
58
+ "price": 7.77,
59
+ "category": "Automotive",
60
+ "position": 5
61
+ },
62
+ {
63
+ "id": "5286E1F9EA",
64
+ "name": "Incredible Cotton Shirt",
65
+ "sku": "873666584-3",
66
+ "sale": false,
67
+ "price": 45.11,
68
+ "category": "Automotive",
69
+ "position": 6
70
+ },
71
+ {
72
+ "id": "E538866CFC",
73
+ "name": "Small Bronze Hat",
74
+ "sku": "710835615-5",
75
+ "sale": false,
76
+ "price": 12.34,
77
+ "category": "Automotive",
78
+ "position": 7
79
+ },
80
+ {
81
+ "id": "952B3D844B",
82
+ "name": "Aerodynamic Paper Clock",
83
+ "sku": "392558208-8",
84
+ "sale": false,
85
+ "price": 22.59,
86
+ "category": "Automotive",
87
+ "position": 8
88
+ },
89
+ {
90
+ "id": "B6BD620005",
91
+ "name": "Durable Iron Table",
92
+ "sku": "795417242-2",
93
+ "sale": false,
94
+ "price": 23.07,
95
+ "category": "Automotive",
96
+ "position": 9
97
+ },
98
+ {
99
+ "id": "546CB731CB",
100
+ "name": "Fantastic Leather Hat",
101
+ "sku": "857899444-2",
102
+ "sale": false,
103
+ "price": 29.59,
104
+ "category": "Automotive",
105
+ "position": 10
106
+ },
107
+ {
108
+ "id": "9FF7028768",
109
+ "name": "Gorgeous Leather Knife",
110
+ "sku": "887139418-6",
111
+ "sale": false,
112
+ "price": 42.41,
113
+ "category": "Automotive",
114
+ "position": 11
115
+ },
116
+ {
117
+ "id": "9F729D69C6",
118
+ "name": "Synergistic Copper Coat",
119
+ "sku": "423424193-8",
120
+ "sale": false,
121
+ "price": 29.59,
122
+ "category": "Automotive",
123
+ "position": 12
124
+ },
125
+ {
126
+ "id": "4011335B6B",
127
+ "name": "Intelligent Wool Clock",
128
+ "sku": "464990513-3",
129
+ "sale": false,
130
+ "price": 31.2,
131
+ "category": "Automotive",
132
+ "position": 13
133
+ },
134
+ {
135
+ "id": "B28798CDAD",
136
+ "name": "Durable Bronze Bag",
137
+ "sku": "547390027-5",
138
+ "sale": false,
139
+ "price": 12.46,
140
+ "category": "Automotive",
141
+ "position": 14
142
+ },
143
+ {
144
+ "id": "84EACAB9F7",
145
+ "name": "Lightweight Leather Bottle",
146
+ "sku": "027837187-6",
147
+ "sale": false,
148
+ "price": 17.47,
149
+ "category": "Automotive",
150
+ "position": 15
151
+ },
152
+ {
153
+ "id": "C02747F6C6",
154
+ "name": "Practical Wooden Coat",
155
+ "sku": "181342040-8",
156
+ "sale": false,
157
+ "price": 42.33,
158
+ "category": "Automotive",
159
+ "position": 16
160
+ },
161
+ {
162
+ "id": "44459088C3",
163
+ "name": "Gorgeous Linen Computer",
164
+ "sku": "226387489-5",
165
+ "sale": false,
166
+ "price": 24.9,
167
+ "category": "Automotive",
168
+ "position": 17
169
+ },
170
+ {
171
+ "id": "F1EDB5846B",
172
+ "name": "Mediocre Bronze Chair",
173
+ "sku": "380482668-7",
174
+ "sale": false,
175
+ "price": 20.55,
176
+ "category": "Automotive",
177
+ "position": 18
178
+ },
179
+ {
180
+ "id": "1A05D231CB",
181
+ "name": "Incredible Rubber Bag",
182
+ "sku": "050606049-7",
183
+ "sale": false,
184
+ "price": 10.02,
185
+ "category": "Automotive",
186
+ "position": 19
187
+ }
188
+ ]
189
+ };
190
+ }
191
+
192
+ function orderPayload() {
193
+ return {
194
+ "site_name": "Dummy App",
195
+ "id": "6705E78231",
196
+ "promo_codes": ['promo_1', 'promo_2'],
197
+ "shipping_service": "Ground",
198
+ "shipping_total": 7.0,
199
+ "tax_total": 1.0,
200
+ "total_price": 152.92,
201
+ "tenders": 'Visa',
202
+ "email": 'test@weblinc.com',
203
+ "items": [
204
+ {
205
+ "id": "5964ef7d9d1fa2f1d0626c86",
206
+ "product_id": "4AF99AB7C8",
207
+ "product_name": "Heavy Duty Iron Bag",
208
+ "sku": "288457637-1",
209
+ "options": {
210
+ "Size": "Medium",
211
+ "Color": "Silver"
212
+ },
213
+ "price": 80.76,
214
+ "quantity": 1,
215
+ "category": "Automotive"
216
+ },
217
+ {
218
+ "id": "595fbf819d1fa2b3a0c4bd00",
219
+ "product_id": "F7BBD9B1D2",
220
+ "product_name": "Rustic Paper Keyboard",
221
+ "sku": "517371131-0",
222
+ "options": {
223
+ "Size": "Small",
224
+ "Color": "Fuchsia"
225
+ },
226
+ "price": 65.16,
227
+ "quantity": 1,
228
+ "category": "Automotive"
229
+ }
230
+ ]
231
+ };
232
+ }
@@ -0,0 +1,56 @@
1
+ //= require workarea/storefront/spec_helper
2
+ /*eslint no-unused-vars: 0 */
3
+
4
+ var gettingUserData = WORKAREA.currentUser.gettingUserData;
5
+
6
+ function stubSegmentMethods() {
7
+ // This is an aweful idea, but since WORKAREA.currentUser.gettingUserData
8
+ // is a promise, not a function it can't be stubbed with sinon.
9
+ var userData = {
10
+ "logged_in":true,
11
+ "cart_quantity":0,
12
+ "admin":true,
13
+ "user_id":"59b2f28fc254291234daf27b",
14
+ "checkout_id":"E2E1096C6A",
15
+ "user_name":"Ben Crouse",
16
+ "user_email":"user@workarea.com"
17
+ };
18
+
19
+ WORKAREA.currentUser.gettingUserData = $.Deferred().resolve(userData);
20
+
21
+ sinon.stub(WORKAREA.segmentAnalytics, 'page', function(payload) {
22
+ window.testData.push({
23
+ eventType: 'page',
24
+ data: payload
25
+ });
26
+ });
27
+
28
+ sinon.stub(WORKAREA.segmentAnalytics, 'track', function(eventType, data) {
29
+ window.testData.push({
30
+ eventType: eventType,
31
+ data: data
32
+ });
33
+ });
34
+
35
+ sinon.stub(WORKAREA.segmentAnalytics, 'identify', function(userId, data) {
36
+ window.testData.push({
37
+ eventType: 'identify',
38
+ userId: userId,
39
+ data: data
40
+ });
41
+ });
42
+
43
+ sinon.stub(WORKAREA.segmentAnalytics, 'reset', function() {
44
+ window.testData.push({
45
+ eventType: 'reset'
46
+ });
47
+ });
48
+ }
49
+
50
+ function resetStubs() {
51
+ WORKAREA.segmentAnalytics.page.reset();
52
+ WORKAREA.segmentAnalytics.track.reset();
53
+ WORKAREA.segmentAnalytics.identify.reset();
54
+ WORKAREA.segmentAnalytics.reset.reset();
55
+ WORKAREA.currentUser.gettingUserData = gettingUserData;
56
+ }
@@ -0,0 +1,311 @@
1
+ //= require workarea/storefront/spec_helper
2
+
3
+ /*global
4
+ orderPayload productListPayload
5
+ stubSegmentMethods resetStubs
6
+ */
7
+
8
+ (function () {
9
+ 'use strict';
10
+
11
+ before(function(){
12
+ window.testData = [];
13
+ });
14
+
15
+ function teardown() {
16
+ window.testData = [];
17
+ }
18
+
19
+ afterEach(teardown);
20
+
21
+ after(resetStubs);
22
+
23
+ describe('WORKAREA.segmentAnalyticsAdapter', function () {
24
+ stubSegmentMethods();
25
+
26
+ describe.skip('categoryView', function () {
27
+ beforeEach(function(){
28
+ WORKAREA.analytics.fireCallback('categoryView',
29
+ {
30
+ "name" : "Games",
31
+ "sort" : "top_sellers",
32
+ "page" : 1,
33
+ "filters" : {}
34
+ }
35
+ );
36
+ });
37
+
38
+ it('creates a page view event', function () {
39
+ //This should be true if isTest worked
40
+ expect(window.testData[0].eventType).to.eq('page');
41
+ });
42
+
43
+ it('adds the payload to segment', function () {
44
+ expect(window.testData[1].data.name).to.eq('Games');
45
+ expect(window.testData[1].data.sort).to.eq('top_sellers');
46
+ expect(window.testData[1].data.page).to.eq(1);
47
+ });
48
+ });
49
+
50
+ describe('justLoggedOut', function () {
51
+ before(function(){
52
+ WORKAREA.analytics.fireCallback('justLoggedOut');
53
+ });
54
+
55
+ it('fires the reset event', function () {
56
+ //This should be true if isTest worked
57
+ expect(window.testData[0].eventType).to.eq('reset');
58
+ });
59
+ });
60
+
61
+ describe('productList', function () {
62
+ before(function(){
63
+ WORKAREA.analytics.fireCallback('productList', productListPayload());
64
+ });
65
+
66
+ it('tacks a Product List Viewed event in segment', function () {
67
+ var payload = window.testData[0].data;
68
+ expect(window.testData[0].eventType).to.eq('Product List Viewed');
69
+ expect(payload.list_id).to.eq('Electronics');
70
+ expect(payload.products.length).to.eq(20);
71
+ });
72
+ });
73
+
74
+ describe('productClick', function () {
75
+ before(function(){
76
+ WORKAREA.analytics.fireCallback('productClick',
77
+ {
78
+ 'category' : "Automotive",
79
+ 'id' : "4AF99AB7C8",
80
+ 'list' : "Movies & Shoes",
81
+ 'name' : "Heavy Duty Iron Bag",
82
+ 'position' : 0,
83
+ 'price' : 19.77,
84
+ 'sale' : false,
85
+ 'sku' : "288457637-1"
86
+ }
87
+ );
88
+ });
89
+
90
+ it('announces a product click event to segment', function () {
91
+ var payload = window.testData[0].data;
92
+ expect(window.testData[0].eventType).to.eq('Product Clicked');
93
+
94
+ expect(payload.category).to.eq('Automotive');
95
+ expect(payload.name).to.eq('Heavy Duty Iron Bag');
96
+ expect(payload.position).to.eq(0);
97
+ expect(payload.price).to.eq(19.77);
98
+ expect(payload.product_id).to.eq('4AF99AB7C8');
99
+ expect(payload.variant).to.eq('288457637-1');
100
+
101
+ expect(window.testData[0].data.quantity).to.be.an('undefined');
102
+ });
103
+ });
104
+
105
+ describe('searchResultsView', function () {
106
+ before(function(){
107
+ WORKAREA.analytics.fireCallback('searchResultsView',
108
+ {
109
+ "terms" : "query string",
110
+ "sort" : "relevance",
111
+ "page" : 1,
112
+ }
113
+ );
114
+ });
115
+
116
+ it('tracks a Products Searched event in segment', function () {
117
+ expect(window.testData[0].eventType).to.eq('Products Searched');
118
+ expect(window.testData[0].data.query).to.eq('query string');
119
+ });
120
+ });
121
+
122
+ describe.skip('productView', function () {
123
+ before(function(){
124
+ WORKAREA.analytics.fireCallback('productView',
125
+ {
126
+ 'category' : 'Automotive',
127
+ 'id' : '4AF99AB7C8',
128
+ 'name' : 'Heavy Duty Iron Bag',
129
+ 'price' : 80.76,
130
+ 'quantity' : '1',
131
+ 'sale' : false,
132
+ 'sku' : '288457637-1'
133
+ }
134
+ );
135
+ });
136
+
137
+ it('creates a page view event', function () {
138
+ //This should be true if isTest worked
139
+ expect(window.testData[0].eventType).to.eq('page');
140
+ });
141
+
142
+ it('announces the products details in the ecommerce event', function () {
143
+ var product = window.testData[1].data;
144
+ expect(product.name).to.eq('Heavy Duty Iron Bag');
145
+ expect(product.product_id).to.eq('4AF99AB7C8');
146
+ expect(product.price).to.eq(80.76);
147
+ expect(product.category).to.eq('Automotive');
148
+ expect(product.variant).to.eq('288457637-1');
149
+ });
150
+ });
151
+
152
+ describe('addToCart', function () {
153
+ before(function(){
154
+ WORKAREA.analytics.fireCallback('addToCart',
155
+ {
156
+ 'category' : 'Automotive',
157
+ 'id' : '4AF99AB7C8',
158
+ 'name' : 'Heavy Duty Iron Bag',
159
+ 'price' : 80.76,
160
+ 'quantity' : '1',
161
+ 'sale' : false,
162
+ 'sku' : '288457637-1'
163
+ }
164
+ );
165
+ });
166
+
167
+ it('tracks the product added event in segment', function () {
168
+ var product = window.testData[0].data;
169
+ expect(window.testData[0].eventType).to.eq('Product Added');
170
+
171
+ expect(product.category).to.eq('Automotive');
172
+ expect(product.name).to.eq('Heavy Duty Iron Bag');
173
+ expect(product.product_id).to.eq('4AF99AB7C8');
174
+ expect(product.price).to.eq(80.76);
175
+ expect(product.quantity).to.eq('1');
176
+ expect(product.variant).to.eq('288457637-1');
177
+ });
178
+ });
179
+
180
+ describe('removeFromCart', function () {
181
+ before(function(){
182
+ WORKAREA.analytics.fireCallback('removeFromCart',
183
+ {
184
+ 'category' : 'Automotive',
185
+ 'id' : '4AF99AB7C8',
186
+ 'name' : 'Heavy Duty Iron Bag',
187
+ 'price' : 80.76,
188
+ 'quantity' : '1',
189
+ 'sale' : false,
190
+ 'sku' : '288457637-1'
191
+ }
192
+ );
193
+ });
194
+
195
+ it('tracks the Product Removed event in segment', function () {
196
+ var product = window.testData[0].data;
197
+ expect(window.testData[0].eventType).to.eq('Product Removed');
198
+
199
+ expect(product.category).to.eq('Automotive');
200
+ expect(product.name).to.eq('Heavy Duty Iron Bag');
201
+ expect(product.product_id).to.eq('4AF99AB7C8');
202
+ expect(product.price).to.eq(80.76);
203
+ expect(product.quantity).to.eq('1');
204
+ expect(product.variant).to.eq('288457637-1');
205
+ });
206
+ });
207
+
208
+ describe('cartView', function () {
209
+ beforeEach(function(){
210
+ WORKAREA.analytics.fireCallback('cartView', orderPayload());
211
+ });
212
+
213
+ it('tracks a Cart Viewed event in segment', function () {
214
+ expect(window.testData[0].eventType).to.eq('Cart Viewed');
215
+ });
216
+
217
+ it('tracks a Checkout step 1 event in segment', function () {
218
+ var payload = window.testData[1].data;
219
+ expect(window.testData[1].eventType).to.eq('Viewed Checkout Step');
220
+ expect(payload.step).to.eq(1);
221
+ });
222
+ });
223
+
224
+ describe('checkoutAddressesView', function () {
225
+ beforeEach(function(){
226
+ WORKAREA.analytics.fireCallback('checkoutAddressesView', orderPayload());
227
+ });
228
+
229
+ it('tracks a Checkout Step Completed event in segment', function () {
230
+ expect(window.testData[0].eventType).to.eq('Checkout Step Completed');
231
+ expect(window.testData[0].data.step).to.eq(1);
232
+ });
233
+
234
+ it('tracks step 2 of checkout in segment', function () {
235
+ expect(window.testData[1].eventType).to.eq('Checkout Step Viewed');
236
+ expect(window.testData[1].data.step).to.eq(2);
237
+ });
238
+ });
239
+
240
+ describe('checkoutShippingView', function () {
241
+ beforeEach(function(){
242
+ WORKAREA.analytics.fireCallback('checkoutShippingView', orderPayload());
243
+ });
244
+
245
+ it('tracks Checkout Step 2 Completed event in segment', function () {
246
+ expect(window.testData[0].eventType).to.eq('Checkout Step Completed');
247
+ expect(window.testData[0].data.step).to.eq(2);
248
+ });
249
+
250
+ it('announces step 3 of checkout in segment', function () {
251
+ expect(window.testData[1].eventType).to.eq('Checkout Step Viewed');
252
+ expect(window.testData[1].data.step).to.eq(3);
253
+ });
254
+ });
255
+
256
+ describe('checkoutPaymentView', function() {
257
+ beforeEach(function(){
258
+ WORKAREA.analytics.fireCallback('checkoutPaymentView',orderPayload());
259
+ });
260
+
261
+ it('tracks Checkout Step 3 Completed event in segment', function () {
262
+ expect(window.testData[0].eventType).to.eq('Checkout Step Completed');
263
+ expect(window.testData[0].data.step).to.eq(3);
264
+ });
265
+
266
+ it('announces step 4 of checkout in segment', function () {
267
+ expect(window.testData[1].eventType).to.eq('Checkout Step Viewed');
268
+ expect(window.testData[1].data.step).to.eq(4);
269
+ });
270
+ });
271
+
272
+ describe('checkoutPaymentSelected', function () {
273
+ before(function(){
274
+ WORKAREA.analytics.fireCallback('checkoutPaymentSelected',
275
+ {
276
+ "type" : "new_card"
277
+ }
278
+ );
279
+ });
280
+
281
+ it('announces a Payment Info Entered event in segment', function () {
282
+ expect(window.testData[0].eventType).to.eq('Payment Info Entered');
283
+ expect(window.testData[0].data.step).to.eq(4);
284
+ });
285
+ });
286
+
287
+ describe('checkoutOrderPlaced', function () {
288
+ beforeEach(function(){
289
+ WORKAREA.analytics.fireCallback('checkoutOrderPlaced', orderPayload());
290
+ });
291
+
292
+ it('tracks Checkout Step 4 Completed event in segment', function () {
293
+ expect(window.testData[0].eventType).to.eq('Checkout Step Completed');
294
+ expect(window.testData[0].data.step).to.eq(4);
295
+ });
296
+
297
+ it('tracks Order Completed event in segment', function() {
298
+ var payload = window.testData[1].data;
299
+ expect(window.testData[1].eventType).to.eq('Order Completed');
300
+
301
+ expect(payload.affiliation).to.eq('Dummy App');
302
+ expect(payload.checkout_id).to.eq('6705E78231');
303
+ expect(payload.discount).to.eq('promo_1,promo_2');
304
+ expect(payload.payment_method).to.eq('Visa');
305
+ expect(payload.revenue).to.eq(152.92);
306
+ expect(payload.shipping).to.eq(7.00);
307
+ expect(payload.tax).to.eq(1.00);
308
+ });
309
+ });
310
+ });
311
+ }());