FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

update byline on video pages for atom pages · devhttps/frontend@fdb5728 · GitHub

Commit fdb5728

Browse files
committed
update byline on video pages for atom pages
use the source field from the atom on an atom powered video page
1 parent daab861 commit fdb5728

2 files changed

Lines changed: 49 additions & 9 deletions

File tree

‎common/app/model/content.scala‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,22 @@ final case class Video (
610610
source: Option[String],
611611
mediaAtom: Option[MediaAtom] ) extends ContentType {
612612

613-
lazy val bylineWithSource: Option[String] = Some(Seq(
614-
trail.byline,
615-
source.map{
613+
614+
lazy val bylineWithSource: Option[String] = {
615+
val videoSource: Option[String] = source.orElse(mediaAtom.flatMap(_.source))
616+
617+
def prettySource(source: String): String = source match {
616618
case "guardian.co.uk" => "theguardian.com"
617-
case other => s"Source: $other"
619+
case other if other.nonEmpty => s"Source: $other"
620+
}
621+
622+
(trail.byline, videoSource) match {
623+
case (Some(b), Some(s)) if b.nonEmpty && s.nonEmpty => Some(s"$b, ${prettySource(s)}")
624+
case (Some(b), _) if b.nonEmpty => Some(b)
625+
case (_, Some(s)) if s.nonEmpty => Some(prettySource(s))
626+
case _ => None
618627
}
619-
).flatten.mkString(", ")).filter(_.nonEmpty)
628+
}
620629

621630
lazy val videoLinkText: String = {
622631
val suffixVariations = List(

‎common/test/model/ContentTest.scala‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package model
33
import com.gu.contentapi.client.model.v1.{Content => ApiContent, Element => ApiElement, Tag => ApiTag, _}
44
import com.gu.contentapi.client.utils.CapiModelEnrichment.RichJodaDateTime
55
import common.Edition
6+
import model.content.MediaAtom
67
import org.joda.time.DateTime
78
import org.scalatest.{FlatSpec, Matchers}
89
import org.scalatestplus.play.OneAppPerSuite
@@ -140,13 +141,13 @@ class ContentTest extends FlatSpec with Matchers with OneAppPerSuite with implic
140141
sectionId = None, sectionName = None, webUrl = url, apiUrl = "apiurl", references = Nil)
141142
}
142143

143-
private def content(contentType: String, elements: List[ApiElement]): ContentType = {
144-
Content(contentApi(contentType, elements))
144+
private def content(contentType: String, elements: List[ApiElement], maybeByline: Option[String] = None): ContentType = {
145+
Content(contentApi(contentType, elements, maybeByline))
145146
}
146147

147148
private val article = contentApi("article", Nil)
148149

149-
private def contentApi(contentType: String, elements: List[ApiElement]): ApiContent = {
150+
private def contentApi(contentType: String, elements: List[ApiElement], maybeByline: Option[String] = None): ApiContent = {
150151
ApiContent(
151152
id = "/content",
152153
sectionId = None,
@@ -156,7 +157,8 @@ class ContentTest extends FlatSpec with Matchers with OneAppPerSuite with implic
156157
webUrl = "webUrl",
157158
apiUrl = "apiUrl",
158159
tags = List(tag(s"type/$contentType")),
159-
elements = Some(elements)
160+
elements = Some(elements),
161+
fields = Some(ContentFields(byline = maybeByline))
160162
)
161163
}
162164

@@ -172,4 +174,33 @@ class ContentTest extends FlatSpec with Matchers with OneAppPerSuite with implic
172174
Asset(AssetType.Image, Some("image/jpeg"), Some("http://www.foo.com/bar"),
173175
Some(AssetFields(caption = Some(caption), width = Some(width))))
174176
}
177+
178+
179+
"Video" should "return the correct byline" in {
180+
val videoSource = Some("test-video-source")
181+
val atomSource = Some("test-atom-source")
182+
val emptySource = Some("")
183+
val byline = Some("test-byline")
184+
185+
val contentNoByline = content("video", Nil).content
186+
val contentWithByline = content("video", Nil, byline).content
187+
188+
val mediaAtomWithSource = Some(MediaAtom("", "", Nil, "", None, atomSource, None, None, None, None))
189+
val mediaAtomWithNoSource = Some(MediaAtom("", "", Nil, "", None, None, None, None, None, None))
190+
val mediaAtomWithEmptySource = Some(MediaAtom("", "", Nil, "", None, emptySource, None, None, None, None))
191+
192+
Video(contentNoByline, None, None).bylineWithSource should be (None)
193+
Video(contentNoByline, videoSource, None).bylineWithSource should be (videoSource.map(s => s"Source: $s"))
194+
Video(contentNoByline, None, mediaAtomWithSource).bylineWithSource should be (atomSource.map(s => s"Source: $s"))
195+
Video(contentNoByline, None, mediaAtomWithNoSource).bylineWithSource should be (None)
196+
Video(contentNoByline, None, mediaAtomWithEmptySource).bylineWithSource should be (None)
197+
Video(contentNoByline, Some("guardian.co.uk"), None).bylineWithSource should be (Some("theguardian.com"))
198+
199+
Video(contentWithByline, None, None).bylineWithSource should be (byline)
200+
Video(contentWithByline, videoSource, None).bylineWithSource should be (videoSource.map(s => s"${byline.get}, Source: $s"))
201+
Video(contentWithByline, None, mediaAtomWithSource).bylineWithSource should be (atomSource.map(s => s"${byline.get}, Source: $s"))
202+
Video(contentWithByline, None, mediaAtomWithNoSource).bylineWithSource should be (byline)
203+
Video(contentWithByline, None, mediaAtomWithEmptySource).bylineWithSource should be (byline)
204+
Video(contentWithByline, Some("guardian.co.uk"), None).bylineWithSource should be (Some(s"${byline.get}, theguardian.com"))
205+
}
175206
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL