evva 0.1.4.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/.rspec +0 -1
  4. data/.rubocop_todo.yml +10 -10
  5. data/.travis.yml +1 -0
  6. data/Gemfile +9 -8
  7. data/Gemfile.lock +7 -11
  8. data/README.md +12 -2
  9. data/Rakefile +9 -0
  10. data/changelog.md +17 -1
  11. data/evva.gemspec +0 -3
  12. data/lib/evva/{mixpanel_enum.rb → analytics_enum.rb} +2 -1
  13. data/lib/evva/analytics_event.rb +17 -0
  14. data/lib/evva/analytics_property.rb +17 -0
  15. data/lib/evva/android_generator.rb +135 -84
  16. data/lib/evva/config.rb +15 -3
  17. data/lib/evva/google_sheet.rb +69 -44
  18. data/lib/evva/swift_generator.rb +91 -81
  19. data/lib/evva/templates/kotlin/base.kt +7 -0
  20. data/lib/evva/templates/kotlin/destinations.kt +5 -0
  21. data/lib/evva/templates/kotlin/event_enum.kt +5 -0
  22. data/lib/evva/templates/kotlin/events.kt +34 -0
  23. data/lib/evva/templates/kotlin/people_properties.kt +24 -0
  24. data/lib/evva/templates/kotlin/people_properties_enum.kt +5 -0
  25. data/lib/evva/templates/kotlin/special_property_enums.kt +10 -0
  26. data/lib/evva/templates/swift/base.swift +7 -0
  27. data/lib/evva/templates/swift/destinations.swift +5 -0
  28. data/lib/evva/templates/swift/events.swift +66 -0
  29. data/lib/evva/templates/swift/people_properties.swift +50 -0
  30. data/lib/evva/templates/swift/special_property_enums.swift +10 -0
  31. data/lib/evva/version.rb +2 -2
  32. data/lib/evva.rb +15 -5
  33. data/spec/evva_spec.rb +3 -5
  34. data/spec/fixtures/sample_public_enums.csv +3 -0
  35. data/spec/fixtures/sample_public_events.csv +4 -0
  36. data/spec/fixtures/sample_public_people_properties.csv +4 -0
  37. data/spec/fixtures/test.yml +9 -5
  38. data/spec/lib/evva/android_generator_spec.rb +131 -57
  39. data/spec/lib/evva/config_spec.rb +12 -6
  40. data/spec/lib/evva/google_sheet_spec.rb +60 -72
  41. data/spec/lib/evva/swift_generator_spec.rb +157 -40
  42. metadata +23 -39
  43. data/evva_config.yml +0 -11
  44. data/lib/evva/mixpanel_event.rb +0 -13
  45. data/spec/fixtures/sample_public_enums.html +0 -1
  46. data/spec/fixtures/sample_public_info.html +0 -1
  47. data/spec/fixtures/sample_public_people_properties.html +0 -1
  48. data/spec/fixtures/sample_public_sheet.html +0 -1
data/lib/evva.rb CHANGED
@@ -5,8 +5,9 @@ require 'evva/logger'
5
5
  require 'evva/google_sheet'
6
6
  require 'evva/config'
7
7
  require 'evva/file_reader'
8
- require 'evva/mixpanel_event'
9
- require 'evva/mixpanel_enum'
8
+ require 'evva/analytics_event'
9
+ require 'evva/analytics_enum'
10
+ require 'evva/analytics_property'
10
11
  require 'evva/object_extension'
11
12
  require 'evva/version'
12
13
  require 'evva/android_generator'
@@ -37,7 +38,7 @@ module Evva
37
38
 
38
39
  def evva_write(bundle, generator, configuration, extension)
39
40
  path = "#{configuration.out_path}/#{configuration.event_file_name}.#{extension}"
40
- write_to_file(path, generator.events(bundle[:events], configuration.event_file_name))
41
+ write_to_file(path, generator.events(bundle[:events], configuration.event_file_name, configuration.event_enum_file_name, configuration.destinations_file_name))
41
42
 
42
43
  unless configuration.type.downcase == 'ios'
43
44
  path = "#{configuration.out_path}/#{configuration.event_enum_file_name}.#{extension}"
@@ -45,22 +46,31 @@ module Evva
45
46
  end
46
47
 
47
48
  path = "#{configuration.out_path}/#{configuration.people_file_name}.#{extension}"
48
- write_to_file(path, generator.people_properties(bundle[:people], configuration.people_file_name))
49
+ write_to_file(path, generator.people_properties(bundle[:people], configuration.people_file_name, configuration.people_enum_file_name, configuration.destinations_file_name))
50
+
51
+ unless configuration.type.downcase == 'ios'
52
+ path = "#{configuration.out_path}/#{configuration.people_enum_file_name}.#{extension}"
53
+ write_to_file(path, generator.people_properties_enum(bundle[:people], configuration.people_enum_file_name))
54
+ end
49
55
 
50
56
  path = "#{configuration.out_path}/#{configuration.special_enum_file_name}.#{extension}"
51
57
  write_to_file(path, generator.special_property_enums(bundle[:enums]))
58
+
59
+ path = "#{configuration.out_path}/#{configuration.destinations_file_name}.#{extension}"
60
+ write_to_file(path, generator.destinations(bundle[:destinations], configuration.destinations_file_name))
52
61
  end
53
62
 
54
63
  def analytics_data(config:)
55
64
  source =
56
65
  case config[:type]
57
66
  when 'google_sheet'
58
- Evva::GoogleSheet.new(config[:sheet_id])
67
+ Evva::GoogleSheet.new(config[:events_url], config[:people_properties_url], config[:enum_classes_url])
59
68
  end
60
69
  events_bundle = {}
61
70
  events_bundle[:events] = source.events
62
71
  events_bundle[:people] = source.people_properties
63
72
  events_bundle[:enums] = source.enum_classes
73
+ events_bundle[:destinations] = source.destinations
64
74
  events_bundle
65
75
  end
66
76
 
data/spec/evva_spec.rb CHANGED
@@ -6,12 +6,10 @@ describe Evva do
6
6
 
7
7
  before do
8
8
  allow_any_instance_of(Evva::FileReader).to receive(:open_file).and_return(file)
9
- allow_any_instance_of(Evva::GoogleSheet).to receive(:events).and_return(
10
- [Evva::MixpanelEvent.new('trackEvent',[])])
11
-
9
+ allow_any_instance_of(Evva::GoogleSheet).to receive(:events).and_return([])
12
10
  allow_any_instance_of(Evva::GoogleSheet).to receive(:people_properties).and_return([])
13
11
  allow_any_instance_of(Evva::GoogleSheet).to receive(:enum_classes).and_return([])
14
-
12
+ allow_any_instance_of(Evva::GoogleSheet).to receive(:destinations).and_return([])
15
13
  allow(Evva).to receive(:write_to_file)
16
14
  end
17
15
 
@@ -37,4 +35,4 @@ describe Evva do
37
35
  .and change { Evva::Logger.summary[:error] }.by(1)
38
36
  end
39
37
  end
40
- end
38
+ end
@@ -0,0 +1,3 @@
1
+ Enum Name,Possible Values
2
+ PageViewSourceScreen,"course_discovery,synced_courses,nearby,deal"
3
+ PremiumClickBuy,"notes,hi_res_maps,whatever"
@@ -0,0 +1,4 @@
1
+ Event Name,Event Properties,Event Destination
2
+ cp_page_view,"course_id:Long,course_name:String","firebase,custom destination"
3
+ nav_feed_tap,,
4
+ cp_view_scorecard,"course_id:Long,course_name:String","custom destination"
@@ -0,0 +1,4 @@
1
+ Property Name,Property Type,Property Destination
2
+ rounds_with_wear,String,"firebase,custom destination"
3
+ total_friends,Int,
4
+ wearable_platform,WearableAppPlatform,firebase
@@ -2,10 +2,14 @@ type: Android
2
2
 
3
3
  data_source:
4
4
  type: google_sheet
5
- sheet_id: 1LaJd68os3g_GFlerogC64grNIlXb2iukMznOvdml7A4
5
+ events_url: https://path-to-csv
6
+ people_properties_url: https://path-to-csv
7
+ enum_classes_url: https://path-to-csv
6
8
 
7
9
  out_path: analytics
8
- event_file_name: MixpanelAnalytics
9
- event_enum_file_name: MixpanelEvent
10
- people_file_name: MixpanelProperties
11
- package_name: com.package.name.analytics
10
+ event_file_name: AnalyticsEvent
11
+ event_enum_file_name: AnalyticsEvents
12
+ people_file_name: AnalyticsProperty
13
+ people_enum_file_name: AnalyticsProperties
14
+ destinations_file_name: AnalyticsDestinations
15
+ package_name: com.package.name.analytics
@@ -2,74 +2,82 @@ describe Evva::AndroidGenerator do
2
2
  let(:generator) { described_class.new("com.hole19golf.hole19.analytics") }
3
3
 
4
4
  describe '#events' do
5
- subject { generator.events(events, "MixpanelAnalytics") }
5
+ subject { generator.events(events, "AnalyticsEvent", "AnalyticsEvents", "AnalyticsDestinations") }
6
6
 
7
7
  let(:events) { [
8
- Evva::MixpanelEvent.new('cp_page_view'),
9
- Evva::MixpanelEvent.new('cp_page_view_a', { course_id: 'Long', course_name: 'String' }),
10
- Evva::MixpanelEvent.new('cp_page_view_b', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource' }),
11
- Evva::MixpanelEvent.new('cp_page_view_c', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource?' }),
12
- Evva::MixpanelEvent.new('cp_page_view_d', { course_id: 'Long?', course_name: 'String' })
8
+ Evva::AnalyticsEvent.new('cp_page_view', {}, []),
9
+ Evva::AnalyticsEvent.new('cp_page_view_2', {}, ["firebase"]),
10
+ Evva::AnalyticsEvent.new('cp_page_view_a', { course_id: 'Long', course_name: 'String' }, ["firebase", "custom destination"]),
11
+ Evva::AnalyticsEvent.new('cp_page_view_b', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource' }, ["firebase"]),
12
+ Evva::AnalyticsEvent.new('cp_page_view_c', { course_id: 'Long', course_name: 'String', from_screen: 'CourseProfileSource?' }, []),
13
+ Evva::AnalyticsEvent.new('cp_page_view_d', { course_id: 'Long?', course_name: 'String' }, []),
13
14
  ] }
14
15
 
15
16
  let(:expected) {
16
17
  <<-Kotlin
17
18
  package com.hole19golf.hole19.analytics
18
19
 
19
- import com.hole19golf.hole19.analytics.Event
20
- import com.hole19golf.hole19.analytics.MixpanelAnalyticsMask
21
- import org.json.JSONObject
22
-
23
20
  /**
24
21
  * This file was automatically generated by evva: https://github.com/hole19/evva
25
22
  */
26
23
 
27
- open class MixpanelAnalytics(private val mask: MixpanelAnalyticsMask) {
24
+ sealed class AnalyticsEvent(event: AnalyticsEvents) {
25
+ val name = event.key
28
26
 
29
- open fun trackCpPageView() {
30
- mask.trackEvent(MixpanelEvent.CP_PAGE_VIEW)
31
- }
27
+ open val properties: Map<String, Any?>? = null
28
+ open val destinations: Array<AnalyticsDestinations> = []
32
29
 
33
- open fun trackCpPageViewA(course_id: Long, course_name: String) {
34
- val properties = JSONObject().apply {
35
- put("course_id", course_id)
36
- put("course_name", course_name)
37
- }
38
- mask.trackEvent(MixpanelEvent.CP_PAGE_VIEW_A, properties)
39
- }
30
+ object CpPageView : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW)
40
31
 
41
- open fun trackCpPageViewB(course_id: Long, course_name: String, from_screen: CourseProfileSource) {
42
- val properties = JSONObject().apply {
43
- put("course_id", course_id)
44
- put("course_name", course_name)
45
- put("from_screen", from_screen.key)
46
- }
47
- mask.trackEvent(MixpanelEvent.CP_PAGE_VIEW_B, properties)
32
+ data class CpPageView2 : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW_2) {
33
+ override val destinations = [
34
+ AnalyticsDestinations.FIREBASE
35
+ ]
48
36
  }
49
37
 
50
- open fun trackCpPageViewC(course_id: Long, course_name: String, from_screen: CourseProfileSource?) {
51
- val properties = JSONObject().apply {
52
- put("course_id", course_id)
53
- put("course_name", course_name)
54
- from_screen?.let { put("from_screen", it.key) }
55
- }
56
- mask.trackEvent(MixpanelEvent.CP_PAGE_VIEW_C, properties)
38
+ data class CpPageViewA(
39
+ val courseId: Long, val courseName: String
40
+ ) : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW_A) {
41
+ override val properties = mapOf(
42
+ "course_id" to courseId,
43
+ "course_name" to courseName
44
+ )
45
+ override val destinations = [
46
+ AnalyticsDestinations.FIREBASE,
47
+ AnalyticsDestinations.CUSTOM_DESTINATION
48
+ ]
57
49
  }
58
50
 
59
- open fun trackCpPageViewD(course_id: Long?, course_name: String) {
60
- val properties = JSONObject().apply {
61
- course_id?.let { put("course_id", it) }
62
- put("course_name", course_name)
63
- }
64
- mask.trackEvent(MixpanelEvent.CP_PAGE_VIEW_D, properties)
51
+ data class CpPageViewB(
52
+ val courseId: Long, val courseName: String, val fromScreen: CourseProfileSource
53
+ ) : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW_B) {
54
+ override val properties = mapOf(
55
+ "course_id" to courseId,
56
+ "course_name" to courseName,
57
+ "from_screen" to fromScreen.key
58
+ )
59
+ override val destinations = [
60
+ AnalyticsDestinations.FIREBASE
61
+ ]
65
62
  }
66
63
 
67
- open fun updateProperties(property: MixpanelProperties, value: Any) {
68
- mask.updateProperties(property.key, value)
64
+ data class CpPageViewC(
65
+ val courseId: Long, val courseName: String, val fromScreen: CourseProfileSource?
66
+ ) : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW_C) {
67
+ override val properties = mapOf(
68
+ "course_id" to courseId,
69
+ "course_name" to courseName,
70
+ "from_screen" to fromScreen?.key
71
+ )
69
72
  }
70
73
 
71
- open fun incrementCounter(property: MixpanelProperties) {
72
- mask.incrementCounter(property.key)
74
+ data class CpPageViewD(
75
+ val courseId: Long?, val courseName: String
76
+ ) : AnalyticsEvent(AnalyticsEvents.CP_PAGE_VIEW_D) {
77
+ override val properties = mapOf(
78
+ "course_id" to courseId,
79
+ "course_name" to courseName
80
+ )
73
81
  }
74
82
  }
75
83
  Kotlin
@@ -81,8 +89,8 @@ Kotlin
81
89
  describe '#special_property_enums' do
82
90
  subject { generator.special_property_enums(enums) }
83
91
  let(:enums) { [
84
- Evva::MixpanelEnum.new('CourseProfileSource', ['course_discovery', 'synced_courses']),
85
- Evva::MixpanelEnum.new('PremiumFrom', ['Course Profile', 'Round Setup'])
92
+ Evva::AnalyticsEnum.new('CourseProfileSource', ['course_discovery', 'synced_courses']),
93
+ Evva::AnalyticsEnum.new('PremiumFrom', ['Course Profile', 'Round Setup']),
86
94
  ] }
87
95
  let(:expected) {
88
96
  <<-Kotlin
@@ -107,22 +115,20 @@ Kotlin
107
115
  end
108
116
 
109
117
  describe '#event_enum' do
110
- subject { generator.event_enum(event_bundle, 'MixpanelEvent') }
118
+ subject { generator.event_enum(event_bundle, 'AnalyticsEvents') }
111
119
  let(:event_bundle) { [
112
- Evva::MixpanelEvent.new('nav_feed_tap', {}),
113
- Evva::MixpanelEvent.new('nav_performance_tap', {})
120
+ Evva::AnalyticsEvent.new('nav_feed_tap', {}, []),
121
+ Evva::AnalyticsEvent.new('nav_performance_tap', {}, []),
114
122
  ] }
115
123
  let(:expected) {
116
124
  <<-Kotlin
117
125
  package com.hole19golf.hole19.analytics
118
126
 
119
- import com.hole19golf.hole19.analytics.Event
120
-
121
127
  /**
122
128
  * This file was automatically generated by evva: https://github.com/hole19/evva
123
129
  */
124
130
 
125
- enum class MixpanelEvent(override val key: String) : Event {
131
+ enum class AnalyticsEvents(val key: String) {
126
132
  NAV_FEED_TAP("nav_feed_tap"),
127
133
  NAV_PERFORMANCE_TAP("nav_performance_tap");
128
134
  }
@@ -132,8 +138,11 @@ Kotlin
132
138
  end
133
139
 
134
140
  describe '#people_properties' do
135
- subject { generator.people_properties(people_bundle, 'MixpanelProperties') }
136
- let(:people_bundle) { ['rounds_with_wear', 'friends_from_facebook'] }
141
+ subject { generator.people_properties(people_bundle, 'AnalyticsProperty', 'AnalyticsProperties', 'AnalyticsDestinations') }
142
+ let(:people_bundle) { [
143
+ Evva::AnalyticsProperty.new('rounds_with_wear', 'String', []),
144
+ Evva::AnalyticsProperty.new('wear_platform', 'WearableAppPlatform', ["firebase", "custom destination"]),
145
+ ] }
137
146
  let(:expected) {
138
147
  <<-Kotlin
139
148
  package com.hole19golf.hole19.analytics
@@ -142,9 +151,74 @@ package com.hole19golf.hole19.analytics
142
151
  * This file was automatically generated by evva: https://github.com/hole19/evva
143
152
  */
144
153
 
145
- enum class MixpanelProperties(val key: String) {
154
+ sealed class AnalyticsProperty(property: AnalyticsProperties) {
155
+ val name = property.key
156
+
157
+ open val value: Any = ""
158
+ open val destinations: Array<AnalyticsDestinations> = []
159
+
160
+ data class RoundsWithWear(
161
+ val value: String
162
+ ) : AnalyticsProperty(AnalyticsProperties.ROUNDS_WITH_WEAR) {
163
+ override val value = value
164
+ }
165
+
166
+ data class WearPlatform(
167
+ val value: WearableAppPlatform
168
+ ) : AnalyticsProperty(AnalyticsProperties.WEAR_PLATFORM) {
169
+ override val value = value.key
170
+ override val destinations = [
171
+ AnalyticsDestinations.FIREBASE,
172
+ AnalyticsDestinations.CUSTOM_DESTINATION
173
+ ]
174
+ }
175
+ }
176
+ Kotlin
177
+ }
178
+
179
+ it { should eq expected }
180
+ end
181
+
182
+ describe '#people_properties_enum' do
183
+ subject { generator.people_properties_enum(people_bundle, 'AnalyticsProperties') }
184
+ let(:people_bundle) { [
185
+ Evva::AnalyticsProperty.new('rounds_with_wear', 'String', ["firebase"]),
186
+ Evva::AnalyticsProperty.new('wear_platform', 'WearableAppPlatform', ["firebase", "custom destination"]),
187
+ ] }
188
+ let(:expected) {
189
+ <<-Kotlin
190
+ package com.hole19golf.hole19.analytics
191
+
192
+ /**
193
+ * This file was automatically generated by evva: https://github.com/hole19/evva
194
+ */
195
+
196
+ enum class AnalyticsProperties(val key: String) {
146
197
  ROUNDS_WITH_WEAR("rounds_with_wear"),
147
- FRIENDS_FROM_FACEBOOK("friends_from_facebook");
198
+ WEAR_PLATFORM("wear_platform");
199
+ }
200
+ Kotlin
201
+ }
202
+ it { should eq expected }
203
+ end
204
+
205
+ describe '#destinations' do
206
+ subject { generator.destinations(destinations_bundle, 'AnalyticsDestinations') }
207
+ let(:destinations_bundle) { [
208
+ 'firebase',
209
+ 'whatever you want really'
210
+ ] }
211
+ let(:expected) {
212
+ <<-Kotlin
213
+ package com.hole19golf.hole19.analytics
214
+
215
+ /**
216
+ * This file was automatically generated by evva: https://github.com/hole19/evva
217
+ */
218
+
219
+ enum class AnalyticsDestinations {
220
+ FIREBASE,
221
+ WHATEVER_YOU_WANT_REALLY;
148
222
  }
149
223
  Kotlin
150
224
  }
@@ -5,14 +5,18 @@ describe Evva::Config do
5
5
  {
6
6
  type: 'EvvaOS',
7
7
  data_source: {
8
- type: 'google_sheet',
9
- sheet_id: 'abc1234567890'
8
+ type: 'google_sheet',
9
+ events_url: 'https://events.csv',
10
+ people_properties_url: 'https://people_properties.csv',
11
+ enum_classes_url: 'https://enum_classes.csv',
10
12
  },
11
13
  out_path: 'clear/path/to/event',
12
14
  event_file_name: 'event/file/name',
13
- people_file_name: 'people/file/name',
14
15
  event_enum_file_name: 'event/enum/file',
15
- package_name: 'com.package.name.analytics'
16
+ people_file_name: 'people/file/name',
17
+ people_enum_file_name: 'people/enum/file/name',
18
+ destinations_file_name: 'destinations/file/name',
19
+ package_name: 'com.package.name.analytics',
16
20
  }
17
21
  end
18
22
 
@@ -25,14 +29,16 @@ describe Evva::Config do
25
29
  its(:type) { should eq('EvvaOS') }
26
30
  its(:out_path) { should eq('clear/path/to/event') }
27
31
  its(:event_file_name) { should eq('event/file/name') }
28
- its(:people_file_name) { should eq('people/file/name') }
29
32
  its(:event_enum_file_name) { should eq 'event/enum/file' }
33
+ its(:people_file_name) { should eq('people/file/name') }
34
+ its(:people_enum_file_name) { should eq('people/enum/file/name') }
35
+ its(:destinations_file_name) { should eq 'destinations/file/name' }
30
36
  its(:package_name) { should eq 'com.package.name.analytics' }
31
37
 
32
38
  describe '#data_source' do
33
39
  subject(:data_source) { config.data_source }
34
40
 
35
- it { should eq(type: 'google_sheet', sheet_id: 'abc1234567890') }
41
+ it { should eq(type: 'google_sheet', events_url: 'https://events.csv', people_properties_url: 'https://people_properties.csv', enum_classes_url: 'https://enum_classes.csv') }
36
42
 
37
43
  context 'when given an unknown type data source' do
38
44
  before { hash[:data_source] = { type: 'i_dunno' } }
@@ -1,107 +1,95 @@
1
1
  describe Evva::GoogleSheet do
2
- let(:sheet) { Evva::GoogleSheet.new(sheet_id) }
3
- let(:sheet_id) { 'abc1234567890' }
4
- let(:url_info) { "https://spreadsheets.google.com/feeds/worksheets/#{sheet_id}/public/full" }
5
- let(:url_sheet) { "https://spreadsheets.google.com/feeds/list/#{sheet_id}/od6/public/full" }
6
- let(:enum_sheet) { "https://spreadsheets.google.com/feeds/list/#{sheet_id}/osju1vh/public/full" }
7
- let(:people_sheet) { "https://spreadsheets.google.com/feeds/list/#{sheet_id}/ojyi830/public/full" }
8
- let(:file_info) { File.read('spec/fixtures/sample_public_info.html') }
9
- let(:file_sheet) { File.read('spec/fixtures/sample_public_sheet.html') }
10
- let(:enum_file) { File.read('spec/fixtures/sample_public_enums.html') }
11
- let(:people_file) { File.read('spec/fixtures/sample_public_people_properties.html') }
2
+ let(:sheet) { Evva::GoogleSheet.new(events_sheet, people_sheet, enum_sheet) }
3
+
4
+ let(:events_sheet) { "https://wtvr1" }
5
+ let(:people_sheet) { "https://wtvr2" }
6
+ let(:enum_sheet) { "https://wtvr3" }
7
+ let(:events_file) { File.read('spec/fixtures/sample_public_events.csv') }
8
+ let(:people_file) { File.read('spec/fixtures/sample_public_people_properties.csv') }
9
+ let(:enum_file) { File.read('spec/fixtures/sample_public_enums.csv') }
10
+
11
+ before do
12
+ stub_request(:get, events_sheet).to_return(status: 200, body: events_file, headers: {})
13
+ stub_request(:get, people_sheet).to_return(status: 200, body: people_file, headers: {})
14
+ stub_request(:get, enum_sheet).to_return(status: 200, body: enum_file, headers: {})
15
+ end
12
16
 
13
17
  describe '#events' do
14
18
  subject(:events) { sheet.events }
15
- before do
16
- stub_request(:get, url_info).to_return(status: 200, body: file_info, headers: {})
17
- stub_request(:get, url_sheet).to_return(status: 200, body: file_sheet, headers: {})
18
- end
19
19
 
20
- context 'when given a valid sheet' do
21
- it do
22
- expect { events }.not_to raise_error
23
- end
20
+ it do
21
+ expect { events }.not_to raise_error
22
+ end
24
23
 
25
- it 'returns an array with the corresponding events' do
26
- expected = [Evva::MixpanelEvent.new('cp_page_view', { course_id: 'Long', course_name: 'String' }),
27
- Evva::MixpanelEvent.new('nav_feed_tap', {}),
28
- Evva::MixpanelEvent.new('cp_view_scorecard', { course_id: 'Long', course_name: 'String' })]
29
- expect(events).to eq(expected)
30
- end
24
+ it 'returns an array with the corresponding events' do
25
+ expected = [
26
+ Evva::AnalyticsEvent.new('cp_page_view', { course_id: 'Long', course_name: 'String' }, ['firebase', 'custom destination']),
27
+ Evva::AnalyticsEvent.new('nav_feed_tap', {}, []),
28
+ Evva::AnalyticsEvent.new('cp_view_scorecard', { course_id: 'Long', course_name: 'String' }, ['custom destination']),
29
+ ]
30
+ expect(events).to eq(expected)
31
31
  end
32
32
 
33
- context 'when given an inexistent sheet' do
34
- before { stub_request(:get, url_info).to_return(status: 400, body: 'Not Found', headers: {}) }
33
+ context "when given an inexistent sheet" do
34
+ before { stub_request(:get, events_sheet).to_return(status: 400, body: "Not Found", headers: {}) }
35
35
 
36
36
  it do
37
- expect { events }.to raise_error /Cannot access sheet/
37
+ expect { events }.to raise_error /Http Error/
38
38
  end
39
39
  end
40
40
 
41
- context 'when given a private sheet' do
42
- before { stub_request(:get, url_info).to_return(status: 302, body: '<HTML></HTML>', headers: {}) }
41
+ context "when url content is not CSV" do
42
+ before { stub_request(:get, events_sheet).to_return(status: 200, body: "{\"asdsa\": \"This is a json\"}", headers: {}) }
43
43
 
44
44
  it do
45
- expect { events }.to raise_error /Cannot access sheet/
45
+ expect { events }.to raise_error /Cannot parse. Expected CSV/
46
46
  end
47
47
  end
48
+ end
48
49
 
49
- context 'when url content is not XML' do
50
- before { stub_request(:get, url_info).to_return(status: 200, body: 'This is not XML; { this: "is json" }', headers: {}) }
50
+ describe '#people_properties' do
51
+ subject(:people_properties) { sheet.people_properties }
51
52
 
52
- it do
53
- expect { events }.to raise_error /Cannot parse. Expected XML/
54
- end
53
+ it do
54
+ expect { people_properties }.not_to raise_error
55
55
  end
56
- end
57
56
 
58
- describe '#enum_classes' do
59
- subject(:enum_classes) { sheet.enum_classes }
60
- let(:expected_enum) do
61
- [
62
- Evva::MixpanelEnum.new('PageViewSourceScreen', ['course_discovery','synced_courses','nearby','deal']),
63
- Evva::MixpanelEnum.new('PremiumClickBuy', ['notes','hi_res_maps','whatever'])
57
+ it 'returns an array with the corresponding events' do
58
+ expect(people_properties).to eq [
59
+ Evva::AnalyticsProperty.new('rounds_with_wear', 'String', ['firebase', 'custom destination']),
60
+ Evva::AnalyticsProperty.new('total_friends', 'Int', []),
61
+ Evva::AnalyticsProperty.new('wearable_platform', 'WearableAppPlatform', ['firebase']),
64
62
  ]
65
63
  end
64
+ end
66
65
 
67
- context 'when given a valid sheet' do
68
- before do
69
- stub_request(:get, url_info).to_return(status: 200, body: file_info, headers: {})
70
- stub_request(:get, enum_sheet).to_return(status: 200, body: enum_file, headers: {})
71
- end
72
-
73
- it do
74
- expect { enum_classes }.not_to raise_error
75
- end
66
+ describe '#enum_classes' do
67
+ subject(:enum_classes) { sheet.enum_classes }
76
68
 
77
- it 'returns an array with the corresponding events' do
78
- expect(enum_classes).to eq expected_enum
79
- end
69
+ it do
70
+ expect { enum_classes }.not_to raise_error
80
71
  end
81
- end
82
72
 
83
- describe '#people_properties' do
84
- subject(:people_properties) { sheet.people_properties }
85
- let(:expected_people_properties) do
86
- [
87
- 'rounds_with_wear',
88
- 'total_friends'
73
+ it 'returns an array with the corresponding events' do
74
+ expect(enum_classes).to eq [
75
+ Evva::AnalyticsEnum.new('PageViewSourceScreen', ['course_discovery','synced_courses','nearby','deal']),
76
+ Evva::AnalyticsEnum.new('PremiumClickBuy', ['notes','hi_res_maps','whatever'])
89
77
  ]
90
78
  end
79
+ end
91
80
 
92
- context 'when given a valid sheet' do
93
- before do
94
- stub_request(:get, url_info).to_return(status: 200, body: file_info, headers: {})
95
- stub_request(:get, people_sheet).to_return(status: 200, body: people_file, headers: {})
96
- end
81
+ describe '#destinations' do
82
+ subject(:destinations) { sheet.destinations }
97
83
 
98
- it do
99
- expect { people_properties }.not_to raise_error
100
- end
84
+ it do
85
+ expect { destinations }.not_to raise_error
86
+ end
101
87
 
102
- it 'returns an array with the corresponding events' do
103
- expect(people_properties).to eq expected_people_properties
104
- end
88
+ it 'returns an array with the corresponding events' do
89
+ expect(destinations).to eq [
90
+ 'firebase',
91
+ 'custom destination',
92
+ ]
105
93
  end
106
94
  end
107
95
  end