| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -610,13 +610,22 @@ final case class Video ( | |||
| 610 | 610 | source: Option[String], | |
| 611 | 611 | mediaAtom: Option[MediaAtom] ) extends ContentType { | |
| 612 | 612 | ||
| 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 { | ||
| 616 | 618 | 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 | ||
| 618 | 627 | } | |
| 619 | - ).flatten.mkString(", ")).filter(_.nonEmpty) | ||
| 628 | + } | ||
| 620 | 629 | ||
| 621 | 630 | lazy val videoLinkText: String = { | |
| 622 | 631 | val suffixVariations = List( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ package model | |||
| 3 | 3 | import com.gu.contentapi.client.model.v1.{Content => ApiContent, Element => ApiElement, Tag => ApiTag, _} | |
| 4 | 4 | import com.gu.contentapi.client.utils.CapiModelEnrichment.RichJodaDateTime | |
| 5 | 5 | import common.Edition | |
| 6 | + import model.content.MediaAtom | ||
| 6 | 7 | import org.joda.time.DateTime | |
| 7 | 8 | import org.scalatest.{FlatSpec, Matchers} | |
| 8 | 9 | import org.scalatestplus.play.OneAppPerSuite | |
@@ -140,13 +141,13 @@ class ContentTest extends FlatSpec with Matchers with OneAppPerSuite with implic | |||
| 140 | 141 | sectionId = None, sectionName = None, webUrl = url, apiUrl = "apiurl", references = Nil) | |
| 141 | 142 | } | |
| 142 | 143 | ||
| 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)) | ||
| 145 | 146 | } | |
| 146 | 147 | ||
| 147 | 148 | private val article = contentApi("article", Nil) | |
| 148 | 149 | ||
| 149 | - private def contentApi(contentType: String, elements: List[ApiElement]): ApiContent = { | ||
| 150 | + private def contentApi(contentType: String, elements: List[ApiElement], maybeByline: Option[String] = None): ApiContent = { | ||
| 150 | 151 | ApiContent( | |
| 151 | 152 | id = "/content", | |
| 152 | 153 | sectionId = None, | |
@@ -156,7 +157,8 @@ class ContentTest extends FlatSpec with Matchers with OneAppPerSuite with implic | |||
| 156 | 157 | webUrl = "webUrl", | |
| 157 | 158 | apiUrl = "apiUrl", | |
| 158 | 159 | tags = List(tag(s"type/$contentType")), | |
| 159 | - elements = Some(elements) | ||
| 160 | + elements = Some(elements), | ||
| 161 | + fields = Some(ContentFields(byline = maybeByline)) | ||
| 160 | 162 | ) | |
| 161 | 163 | } | |
| 162 | 164 | ||
@@ -172,4 +174,33 @@ class ContentTest extends FlatSpec with Matchers with OneAppPerSuite with implic | |||
| 172 | 174 | Asset(AssetType.Image, Some("image/jpeg"), Some("http://www.foo.com/bar"), | |
| 173 | 175 | Some(AssetFields(caption = Some(caption), width = Some(width)))) | |
| 174 | 176 | } | |
| 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 | + } | ||
| 175 | 206 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments