| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f59cc4b commit e789b64
18 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,11 @@ final case class Commercial( | |||
| 46 | 46 | * MetaData represents a page on the site, whether facia or content | |
| 47 | 47 | */ | |
| 48 | 48 | object Fields { | |
| 49 | + // This is the time from which journalists start using the reader revenue flag in Composer. | ||
| 50 | + // For content published before then, we need handle it as we did before, taking | ||
| 51 | + // the sensitive flag to mean "don't display reader revenue asks" | ||
| 52 | + private val shouldHideReaderRevenueCutoffDate = new DateTime("2017-07-03T12:00:00.000Z") | ||
| 53 | + | ||
| 49 | 54 | def make(apiContent: contentapi.Content): Fields = { | |
| 50 | 55 | Fields ( | |
| 51 | 56 | trailText = apiContent.fields.flatMap(_.trailText), | |
@@ -59,12 +64,26 @@ object Fields { | |||
| 59 | 64 | displayHint = apiContent.fields.flatMap(_.displayHint).getOrElse(""), | |
| 60 | 65 | isLive = apiContent.fields.flatMap(_.liveBloggingNow).getOrElse(false), | |
| 61 | 66 | sensitive = apiContent.fields.flatMap(_.sensitive), | |
| 62 | - shouldHideReaderRevenue = apiContent.fields.flatMap(_.shouldHideReaderRevenue), | ||
| 67 | + shouldHideReaderRevenue = Some(shouldHideReaderRevenue(apiContent, shouldHideReaderRevenueCutoffDate)), | ||
| 63 | 68 | legallySensitive = apiContent.fields.flatMap(_.legallySensitive), | |
| 64 | 69 | firstPublicationDate = apiContent.fields.flatMap(_.firstPublicationDate).map(_.toJodaDateTime), | |
| 65 | 70 | lang = apiContent.fields.flatMap(_.lang) | |
| 66 | 71 | ) | |
| 67 | 72 | } | |
| 73 | + | ||
| 74 | + def shouldHideReaderRevenue(apiContent: contentapi.Content, cutoffDate: DateTime): Boolean = { | ||
| 75 | + val publishedBeforeCutoff = apiContent.webPublicationDate.exists(_.toJodaDateTime < cutoffDate) | ||
| 76 | + val isPaidContent = Tags.make(apiContent).isPaidContent | ||
| 77 | + val isSensitive = apiContent.fields.flatMap(_.sensitive).getOrElse(false) | ||
| 78 | + val shouldHideAdverts = apiContent.fields.flatMap(_.shouldHideAdverts).getOrElse(false) | ||
| 79 | + | ||
| 80 | + apiContent.fields.flatMap(_.shouldHideReaderRevenue) match { | ||
| 81 | + case _ if isPaidContent => true | ||
| 82 | + case Some(shouldHide) => shouldHide | ||
| 83 | + case None if publishedBeforeCutoff => isSensitive || shouldHideAdverts | ||
| 84 | + case None => false | ||
| 85 | + } | ||
| 86 | + } | ||
| 68 | 87 | } | |
| 69 | 88 | ||
| 70 | 89 | final case class Fields( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,9 @@ | |||
| 1 | 1 | package model | |
| 2 | 2 | ||
| 3 | + import com.gu.contentapi.client.model.v1.{Content => ApiContent, ContentFields, Tag => ApiTag, TagType} | ||
| 4 | + import com.gu.contentapi.client.utils.CapiModelEnrichment.RichJodaDateTime | ||
| 3 | 5 | import org.scalatest.{FlatSpec, Matchers} | |
| 6 | + import org.joda.time.DateTime | ||
| 4 | 7 | ||
| 5 | 8 | class MetaDataTest extends FlatSpec with Matchers { | |
| 6 | 9 | ||
@@ -15,4 +18,87 @@ class MetaDataTest extends FlatSpec with Matchers { | |||
| 15 | 18 | testMetaData("world/2014/jun/19/obama-100-special-forces-iraq", "world").adUnitSuffix should be("world") | |
| 16 | 19 | } | |
| 17 | 20 | ||
| 21 | + val defaultTag = ApiTag(id = "type/article", `type` = TagType.Keyword, webTitle = "", | ||
| 22 | + sectionId = None, sectionName = None, webUrl = "", apiUrl = "apiurl", references = Nil) | ||
| 23 | + | ||
| 24 | + val paidContentTag = ApiTag(id = "tone/advertisement-features", `type` = TagType.Keyword, webTitle = "", | ||
| 25 | + sectionId = None, sectionName = None, webUrl = "", apiUrl = "apiurl", references = Nil) | ||
| 26 | + | ||
| 27 | + val cutoffDate = new DateTime("2017-07-03T12:00:00.000Z") | ||
| 28 | + val dateBeforeCutoff = new DateTime("2017-07-02T12:00:00.000Z") | ||
| 29 | + val dateAfterCutoff = new DateTime("2017-07-04T12:00:00.000Z") | ||
| 30 | + | ||
| 31 | + private def contentApi( shouldHideReaderRevenue: Option[Boolean] = None, | ||
| 32 | + isPaid: Boolean = false, | ||
| 33 | + isSensitive: Boolean = false, | ||
| 34 | + shouldHideAdverts: Boolean = false, | ||
| 35 | + publicationDate: DateTime) = { | ||
| 36 | + ApiContent( | ||
| 37 | + id = "/content", | ||
| 38 | + sectionId = None, | ||
| 39 | + sectionName = None, | ||
| 40 | + webPublicationDate = Some(publicationDate.toCapiDateTime), | ||
| 41 | + webTitle = "webTitle", | ||
| 42 | + webUrl = "webUrl", | ||
| 43 | + apiUrl = "apiUrl", | ||
| 44 | + tags = defaultTag :: (if (isPaid) List(paidContentTag) else Nil), | ||
| 45 | + elements = None, | ||
| 46 | + fields = Some( | ||
| 47 | + ContentFields( | ||
| 48 | + sensitive = Some(isSensitive), | ||
| 49 | + shouldHideReaderRevenue = shouldHideReaderRevenue, | ||
| 50 | + shouldHideAdverts = Some(shouldHideAdverts) | ||
| 51 | + ) | ||
| 52 | + ) | ||
| 53 | + ) | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + "shouldHideReaderRevenue" should "hide if shouldHideReaderRevenue is unset, and content is sensitive and published before cutoff" in { | ||
| 57 | + val content = contentApi(isSensitive = true, publicationDate = dateBeforeCutoff) | ||
| 58 | + Fields.shouldHideReaderRevenue(content, cutoffDate) should be(true) | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + it should "hide if shouldHideReaderRevenue is unset, and content is shouldHideAdverts and published before cutoff" in { | ||
| 62 | + val content = contentApi(shouldHideAdverts = true, publicationDate = dateBeforeCutoff) | ||
| 63 | + Fields.shouldHideReaderRevenue(content, cutoffDate) should be(true) | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + it should "not hide if shouldHideReaderRevenue is unset and published after cutoff, even if sensitive" in { | ||
| 67 | + val content = contentApi(isSensitive = true, publicationDate = dateAfterCutoff) | ||
| 68 | + Fields.shouldHideReaderRevenue(content, cutoffDate) should be(false) | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + it should "not hide if shouldHideReaderRevenue is unset and published after cutoff, even if shouldHideAdverts" in { | ||
| 72 | + val content = contentApi(shouldHideAdverts = true, publicationDate = dateAfterCutoff) | ||
| 73 | + Fields.shouldHideReaderRevenue(content, cutoffDate) should be(false) | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + it should "not hide if shouldHideReaderRevenue is false and published before cutoff, even if sensitive" in { | ||
| 77 | + val content = contentApi(shouldHideReaderRevenue = Some(false), isSensitive = true, publicationDate = dateBeforeCutoff) | ||
| 78 | + Fields.shouldHideReaderRevenue(content, cutoffDate) should be(false) | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + it should "hide if shouldHideReaderRevenue is true, regardless of publication date or sensitive flag" in { | ||
| 82 | + val sensitiveOldContent = contentApi(shouldHideReaderRevenue = Some(true), isSensitive = true, publicationDate = dateBeforeCutoff) | ||
| 83 | + val sensitiveNewContent = contentApi(shouldHideReaderRevenue = Some(true), isSensitive = true, publicationDate = dateBeforeCutoff) | ||
| 84 | + val notSensitiveOldContent = contentApi(shouldHideReaderRevenue = Some(true), publicationDate = dateAfterCutoff) | ||
| 85 | + val notSensitiveNewContent = contentApi(shouldHideReaderRevenue = Some(true), publicationDate = dateAfterCutoff) | ||
| 86 | + | ||
| 87 | + Fields.shouldHideReaderRevenue(sensitiveOldContent, cutoffDate) should be(true) | ||
| 88 | + Fields.shouldHideReaderRevenue(sensitiveNewContent, cutoffDate) should be(true) | ||
| 89 | + Fields.shouldHideReaderRevenue(notSensitiveOldContent, cutoffDate) should be(true) | ||
| 90 | + Fields.shouldHideReaderRevenue(notSensitiveNewContent, cutoffDate) should be(true) | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + it should "hide if content is paid, regardless of shouldHideReaderRevenue flag, publication date or sensitive flag" in { | ||
| 94 | + val sensitiveOldContent = contentApi(shouldHideReaderRevenue = Some(false), isSensitive = true, isPaid = true, publicationDate = dateBeforeCutoff) | ||
| 95 | + val sensitiveNewContent = contentApi(shouldHideReaderRevenue = Some(true), isSensitive = true, isPaid = true, publicationDate = dateBeforeCutoff) | ||
| 96 | + val notSensitiveOldContent = contentApi(shouldHideReaderRevenue = None, isPaid = true, publicationDate = dateAfterCutoff) | ||
| 97 | + val notSensitiveNewContent = contentApi(shouldHideReaderRevenue = None, isPaid = true, publicationDate = dateAfterCutoff) | ||
| 98 | + | ||
| 99 | + Fields.shouldHideReaderRevenue(sensitiveOldContent, cutoffDate) should be(true) | ||
| 100 | + Fields.shouldHideReaderRevenue(sensitiveNewContent, cutoffDate) should be(true) | ||
| 101 | + Fields.shouldHideReaderRevenue(notSensitiveOldContent, cutoffDate) should be(true) | ||
| 102 | + Fields.shouldHideReaderRevenue(notSensitiveNewContent, cutoffDate) should be(true) | ||
| 103 | + } | ||
| 18 | 104 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,6 @@ define([ | |||
| 20 | 20 | audienceCriteria: 'All', | |
| 21 | 21 | audience: 1, | |
| 22 | 22 | audienceOffset: 0, | |
| 23 | - showForSensitive: true, | ||
| 24 | 23 | useTargetingTool: true, | |
| 25 | 24 | ||
| 26 | 25 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,8 +30,6 @@ define([ | |||
| 30 | 30 | audience: 1, | |
| 31 | 31 | audienceOffset: 0, | |
| 32 | 32 | ||
| 33 | - showForSensitive: true, | ||
| 34 | - | ||
| 35 | 33 | pageCheck: function(page) { | |
| 36 | 34 | var isElection = page.keywordIds && | |
| 37 | 35 | page.keywordIds.includes('general-election-2017') && | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,8 +29,6 @@ define([ | |||
| 29 | 29 | audience: 1, | |
| 30 | 30 | audienceOffset: 0, | |
| 31 | 31 | ||
| 32 | - showForSensitive: true, | ||
| 33 | - | ||
| 34 | 32 | pageCheck: function(page) { | |
| 35 | 33 | return page.keywordIds && | |
| 36 | 34 | page.keywordIds.includes('general-election-2017') && | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,8 +91,6 @@ define([ | |||
| 91 | 91 | audience: 1, | |
| 92 | 92 | audienceOffset: 0, | |
| 93 | 93 | ||
| 94 | - showForSensitive: true, | ||
| 95 | - | ||
| 96 | 94 | pageCheck: function(page) { | |
| 97 | 95 | return page.contentType === 'LiveBlog'; | |
| 98 | 96 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,8 +68,6 @@ define([ | |||
| 68 | 68 | audience: 1, | |
| 69 | 69 | audienceOffset: 0, | |
| 70 | 70 | ||
| 71 | - showForSensitive: true, | ||
| 72 | - | ||
| 73 | 71 | pageCheck: function(page) { | |
| 74 | 72 | return page.contentType === 'LiveBlog'; | |
| 75 | 73 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,12 +12,8 @@ define([ | |||
| 12 | 12 | acquisitionsEpicThankYouTemplate | |
| 13 | 13 | ) { | |
| 14 | 14 | ||
| 15 | - function isRecentContributor() { | ||
| 16 | - return contributionsUtilities.daysSinceLastContribution < 180 | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | 15 | function isTargetReader() { | |
| 20 | - return userFeatures.isPayingMember() || isRecentContributor() | ||
| 16 | + return userFeatures.isPayingMember() || userFeatures.isRecentContributor() | ||
| 21 | 17 | } | |
| 22 | 18 | ||
| 23 | 19 | function worksWellWithPageTemplate() { | |
@@ -27,9 +23,7 @@ define([ | |||
| 27 | 23 | } | |
| 28 | 24 | ||
| 29 | 25 | function isTargetPage() { | |
| 30 | - return worksWellWithPageTemplate() && | ||
| 31 | - !config.page.isPaidContent && | ||
| 32 | - !config.page.shouldHideAdverts | ||
| 26 | + return worksWellWithPageTemplate() && !config.page.shouldHideReaderRevenue | ||
| 33 | 27 | } | |
| 34 | 28 | ||
| 35 | 29 | return contributionsUtilities.makeABTest({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,6 @@ define([ | |||
| 19 | 19 | audience: 1, | |
| 20 | 20 | audienceOffset: 0, | |
| 21 | 21 | ||
| 22 | - showForSensitive: true, | ||
| 23 | 22 | showToContributorsAndSupporters: true, | |
| 24 | 23 | ||
| 25 | 24 | useTargetingTool: true, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,6 @@ define([ | |||
| 50 | 50 | audienceCriteria: 'Non-paying UK edition readers - mobile resolution and above', | |
| 51 | 51 | audience: 0.1, | |
| 52 | 52 | audienceOffset: 0, | |
| 53 | - showForSensitive: false, | ||
| 54 | 53 | useTargetingTool: false, | |
| 55 | 54 | ||
| 56 | 55 | overrideCanRun: false, | |
@@ -59,7 +58,7 @@ define([ | |||
| 59 | 58 | config.page.edition.toUpperCase() === 'UK' && | |
| 60 | 59 | config.page.contentType === 'Article' && | |
| 61 | 60 | !config.page.isMinuteArticle && | |
| 62 | - commercialFeatures.commercialFeatures.canReasonablyAskForMoney | ||
| 61 | + contributionsUtilities.shouldShowReaderRevenue() | ||
| 63 | 62 | }, | |
| 64 | 63 | ||
| 65 | 64 | variants: [ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments