Skip to content

Commit

Permalink
Remove server side test check
Browse files Browse the repository at this point in the history
  • Loading branch information
emma-imber committed May 21, 2024
1 parent f88b87a commit ffd0f59
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 37 deletions.
10 changes: 0 additions & 10 deletions common/app/experiments/Experiments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ object ActiveExperiments extends ExperimentsDefinition {
UpdatedHeaderDesign,
UpdateLogoAdPartner,
MastheadWithHighlights,
AffiliateLinksDCR,
)
implicit val canCheckExperiment: CanCheckExperiment = new CanCheckExperiment(this)
}
Expand Down Expand Up @@ -58,15 +57,6 @@ object UpdateLogoAdPartner
participationGroup = Perc0A,
)

object AffiliateLinksDCR
extends Experiment(
name = "affiliate-links-dcr",
description = "Display affiliate links on all eligible DCR articles",
owners = Seq(Owner.withGithub("[email protected]")),
sellByDate = LocalDate.of(2024, 7, 30),
participationGroup = Perc0E,
)

object DCRTagPages
extends Experiment(
name = "dcr-tag-pages",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object DotcomBlocksRenderingDataModel {
bodyBlocks: Seq[APIBlock],
): DotcomBlocksRenderingDataModel = {
val content = page.item
val shouldAddAffiliateLinks = DotcomRenderingUtils.shouldAddAffiliateLinks(content)(request)
val shouldAddAffiliateLinks = DotcomRenderingUtils.shouldAddAffiliateLinks(content)
val contentDateTimes = DotcomRenderingUtils.contentDateTimes(content)

val edition = Edition(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ object DotcomRenderingDataModel {
blocks.exists(block => DotcomRenderingUtils.stringContainsAffiliateableLinks(block.bodyHtml))
}

val shouldAddAffiliateLinks = DotcomRenderingUtils.shouldAddAffiliateLinks(content)(request)
val shouldAddAffiliateLinks = DotcomRenderingUtils.shouldAddAffiliateLinks(content)
val shouldAddDisclaimer = hasAffiliateLinks(bodyBlocks)

val contentDateTimes: ArticleDateTimes = ArticleDateTimes(
Expand Down
13 changes: 7 additions & 6 deletions common/app/model/dotcomrendering/DotcomRenderingUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,16 @@ object DotcomRenderingUtils {
}
}

def shouldAddAffiliateLinks(content: ContentType)(implicit request: RequestHeader): Boolean = {
def shouldAddAffiliateLinks(content: ContentType): Boolean = {
val contentHtml = Jsoup.parse(content.fields.body)
val bodyElements = contentHtml.select("body").first().children()

/**
* On smaller devices, the disclaimer is inserted before paragraph 2 of the article body and floats left.
* This logic ensures there are two clear paragraphs of text at the top of the article.
* We don't support inserting the disclaimer next to other element types.
* It also ensures the second paragraph is long enough to accommodate the disclaimer appearing alongside it.
*/
* On smaller devices, the disclaimer is inserted before paragraph 2 of the article body and floats left.
* This logic ensures there are two clear paragraphs of text at the top of the article.
* We don't support inserting the disclaimer next to other element types.
* It also ensures the second paragraph is long enough to accommodate the disclaimer appearing alongside it.
*/
if (bodyElements.size >= 2) {
val firstEl = bodyElements.get(0)
val secondEl = bodyElements.get(1)
Expand Down
10 changes: 4 additions & 6 deletions common/app/views/support/HtmlCleaner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import common.{Edition, GuLogging, LinkTo}
import conf.Configuration.affiliateLinks._
import conf.Configuration.site.host
import conf.switches.Switches._
import experiments.{ActiveExperiments, AffiliateLinksDCR}
import layout.ContentWidths
import layout.ContentWidths._
import model._
Expand Down Expand Up @@ -873,8 +872,7 @@ case class AffiliateLinksCleaner(
appendDisclaimer: Option[Boolean] = None,
tags: List[String],
publishedDate: Option[DateTime],
)(implicit request: RequestHeader)
extends HtmlCleaner
) extends HtmlCleaner
with GuLogging {

override def clean(document: Document): Document = {
Expand Down Expand Up @@ -943,15 +941,15 @@ object AffiliateLinksCleaner {
alwaysOffTags: Set[String],
tagPaths: List[String],
firstPublishedDate: Option[DateTime],
)(implicit request: RequestHeader): Boolean = {
): Boolean = {
val publishedCutOffDate = new DateTime(2020, 8, 14, 0, 0)

// Never include affiliate links if it is tagged with an always off tag, or if it was published before our cut off date.
// The cut off date is temporary while we are working on improving the compliance of affiliate links.
if (
!contentHasAlwaysOffTag(tagPaths, alwaysOffTags) && (firstPublishedDate.exists(
!contentHasAlwaysOffTag(tagPaths, alwaysOffTags) && firstPublishedDate.exists(
_.isBefore(publishedCutOffDate),
) || ActiveExperiments.isParticipating(AffiliateLinksDCR))
)
) {
if (showAffiliateLinks.isDefined) {
showAffiliateLinks.contains(true)
Expand Down
23 changes: 10 additions & 13 deletions common/test/views/support/cleaner/AffiliateLinksCleanerTest.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package views.support.cleaner
import conf.Configuration
import conf.switches.Switches.ServerSideExperiments
import org.joda.time.DateTime
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import play.api.test.FakeRequest
import views.support.AffiliateLinksCleaner._

class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Expand All @@ -18,7 +16,6 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
}

"shouldAddAffiliateLinks" should "correctly determine when to add affiliate links" in {
val fakeTestControlRequest = FakeRequest().withHeaders("X-GU-Experiment-0perc-E" -> "control")
val supportedSections = Set("film", "books", "fashion")
val oldPublishedDate = Some(new DateTime(2020, 8, 13, 0, 0))
val newPublishedDate = Some(new DateTime(2020, 8, 15, 0, 0))
Expand All @@ -32,7 +29,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set.empty,
List.empty,
oldPublishedDate,
)(fakeTestControlRequest) should be(false)
) should be(false)
shouldAddAffiliateLinks(
switchedOn = true,
"film",
Expand All @@ -42,7 +39,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set.empty,
List.empty,
oldPublishedDate,
)(fakeTestControlRequest) should be(true)
) should be(true)
shouldAddAffiliateLinks(
switchedOn = true,
"film",
Expand All @@ -52,7 +49,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set.empty,
List.empty,
oldPublishedDate,
)(fakeTestControlRequest) should be(false)
) should be(false)
shouldAddAffiliateLinks(
switchedOn = true,
"news",
Expand All @@ -62,7 +59,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set.empty,
List.empty,
oldPublishedDate,
)(fakeTestControlRequest) should be(true)
) should be(true)
shouldAddAffiliateLinks(
switchedOn = true,
"news",
Expand All @@ -72,7 +69,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set.empty,
List("bereavement"),
oldPublishedDate,
)(fakeTestControlRequest) should be(false)
) should be(false)
shouldAddAffiliateLinks(
switchedOn = true,
"news",
Expand All @@ -82,7 +79,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set.empty,
List("tech"),
oldPublishedDate,
)(fakeTestControlRequest) should be(false)
) should be(false)
shouldAddAffiliateLinks(
switchedOn = true,
"fashion",
Expand All @@ -92,7 +89,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set.empty,
List("tech"),
oldPublishedDate,
)(fakeTestControlRequest) should be(true)
) should be(true)
shouldAddAffiliateLinks(
switchedOn = true,
"fashion",
Expand All @@ -102,7 +99,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set("bereavement"),
List("bereavement"),
oldPublishedDate,
)(fakeTestControlRequest) should be(false)
) should be(false)
shouldAddAffiliateLinks(
switchedOn = true,
"fashion",
Expand All @@ -112,7 +109,7 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set("bereavement"),
List("tech"),
oldPublishedDate,
)(fakeTestControlRequest) should be(true)
) should be(true)
shouldAddAffiliateLinks(
switchedOn = true,
"film",
Expand All @@ -122,6 +119,6 @@ class AffiliateLinksCleanerTest extends AnyFlatSpec with Matchers {
Set.empty,
List.empty,
newPublishedDate,
)(fakeTestControlRequest) should be(true)
) should be(true)
}
}

0 comments on commit ffd0f59

Please sign in to comment.