Skip to content

Commit

Permalink
NTV-351 Segment – Add project_url to properties (#1515)
Browse files Browse the repository at this point in the history
* add  project URL flowing through Segment

* Fix test
  • Loading branch information
hadia committed Jan 19, 2022
1 parent e06232d commit c786445
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
Expand Up @@ -275,6 +275,7 @@ object AnalyticEventsUtils {
}
put("has_add_ons", hasAddOns?.hasAddons() ?: false)
put("tags", project.tags()?.let { it.joinToString(", ") } ?: "")
put("url", project.urls().web().project())
}

return MapUtils.prefixKeys(properties, prefix)
Expand Down
84 changes: 41 additions & 43 deletions app/src/test/java/com/kickstarter/libs/SegmentTest.kt
Expand Up @@ -53,7 +53,9 @@ import com.kickstarter.mock.factories.RewardFactory
import com.kickstarter.mock.factories.UserFactory
import com.kickstarter.models.Project
import com.kickstarter.models.Reward
import com.kickstarter.models.Urls
import com.kickstarter.models.User
import com.kickstarter.models.Web
import com.kickstarter.services.DiscoveryParams
import com.kickstarter.ui.data.PledgeData
import com.kickstarter.ui.data.PledgeFlowContext
Expand Down Expand Up @@ -759,16 +761,7 @@ class SegmentTest : KSRobolectricTestCase() {

@Test
fun testProjectProperties_LoggedInUser_IsBacker() {
val project = ProjectFactory.backedProject()
.toBuilder()
.id(4)
.tags(listOfTags())
.category(CategoryFactory.ceramicsCategory())
.commentsCount(3)
.creator(creator())
.location(LocationFactory.unitedStates())
.updatesCount(5)
.build()
val project = backedProject()
val user = user()
val client = client(user)
client.eventNames.subscribe(this.segmentTrack)
Expand Down Expand Up @@ -978,16 +971,7 @@ class SegmentTest : KSRobolectricTestCase() {

@Test
fun testManagePledgePageViewed() {
val project = ProjectFactory.backedProject()
.toBuilder()
.id(4)
.tags(listOfTags())
.category(CategoryFactory.ceramicsCategory())
.commentsCount(3)
.creator(creator())
.location(LocationFactory.unitedStates())
.updatesCount(5)
.build()
val project = backedProject()

val addOn1 = RewardFactory.addOn()
val addOn2 = RewardFactory.addOnMultiple()
Expand Down Expand Up @@ -1033,16 +1017,7 @@ class SegmentTest : KSRobolectricTestCase() {

@Test
fun testUpdatePledgePageViewed() {
val project = ProjectFactory.backedProject()
.toBuilder()
.id(4)
.category(CategoryFactory.ceramicsCategory())
.commentsCount(3)
.creator(creator())
.location(LocationFactory.unitedStates())
.tags(listOfTags())
.updatesCount(5)
.build()
val project = backedProject()
val user = user()
val client = client(user)
client.eventNames.subscribe(this.segmentTrack)
Expand Down Expand Up @@ -1070,16 +1045,7 @@ class SegmentTest : KSRobolectricTestCase() {

@Test
fun testCheckoutProperties_whenFixingPledge() {
val project = ProjectFactory.backedProject()
.toBuilder()
.id(4)
.tags(listOfTags())
.category(CategoryFactory.ceramicsCategory())
.commentsCount(3)
.creator(creator())
.location(LocationFactory.unitedStates())
.updatesCount(5)
.build()
val project = backedProject()
val user = user()
val client = client(user)
client.eventNames.subscribe(this.segmentTrack)
Expand Down Expand Up @@ -1624,6 +1590,7 @@ class SegmentTest : KSRobolectricTestCase() {
assertEquals("tag1, tag2, tag3", expectedProperties["project_tags"])
assertEquals("discovery", expectedProperties["session_ref_tag"])
assertEquals("recommended", expectedProperties["session_referrer_credit"])
assertEquals("https://www.kickstarter.com/projects/${expectedProperties["project_creator_uid"]}/slug-1", expectedProperties["project_url"])
assertEquals(false, expectedProperties["project_has_add_ons"])
}

Expand Down Expand Up @@ -1695,17 +1662,48 @@ class SegmentTest : KSRobolectricTestCase() {
.starredProjectsCount(2)
.build()

private fun project() =
ProjectFactory.project().toBuilder()
private fun project(): Project {
val creatorUser = creator()
val slug = "slug-1"
val projectUrl = "https://www.kickstarter.com/projects/" + creatorUser.id() + "/" + slug
val web = Web.builder()
.project(projectUrl)
.rewards("$projectUrl/rewards")
.updates("$projectUrl/posts")
.build()
return ProjectFactory.project().toBuilder()
.id(4)
.urls(Urls.builder().web(web).build())
.category(CategoryFactory.ceramicsCategory())
.creator(creator())
.creator(creatorUser)
.commentsCount(3)
.tags(listOfTags())
.location(LocationFactory.unitedStates())
.updatesCount(5)
.build()
}

private fun backedProject(): Project {
val creatorUser = creator()
val slug = "slug-1"
val projectUrl = "https://www.kickstarter.com/projects/" + creatorUser.id() + "/" + slug
val web = Web.builder()
.project(projectUrl)
.rewards("$projectUrl/rewards")
.updates("$projectUrl/posts")
.build()
return ProjectFactory.backedProject()
.toBuilder()
.id(4)
.urls(Urls.builder().web(web).build())
.category(CategoryFactory.ceramicsCategory())
.commentsCount(3)
.creator(creator())
.location(LocationFactory.unitedStates())
.tags(listOfTags())
.updatesCount(5)
.build()
}
private fun reward() =
RewardFactory.rewardWithShipping().toBuilder()
.id(2)
Expand Down

0 comments on commit c786445

Please sign in to comment.