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

url path for facia email headline · devhttps/frontend@bcc6823 · GitHub

Commit bcc6823

Browse files
committed
url path for facia email headline
1 parent 086424e commit bcc6823

6 files changed

Lines changed: 116 additions & 56 deletions

File tree

‎common/test/common/facia/FixtureBuilder.scala‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,45 @@
11
package common.facia
22

3+
import model.facia.PressedCollection
4+
import model.{FrontProperties, PressedPage, SeoData}
35
import model.pressed._
46

57
object FixtureBuilder {
68

9+
def mkContent(id: Int): PressedContent = FixtureBuilder.mkPressedContent(id)
10+
11+
def mkPressedCollection(id: String, curated: Seq[PressedContent] = IndexedSeq.empty, backfill: Seq[PressedContent] = IndexedSeq.empty, maxItemsToDisplay: Option[Int] = None) = {
12+
PressedCollection(
13+
id = "test-collection",
14+
displayName = s"Test Collection $id",
15+
curated = curated.toList,
16+
backfill = backfill.toList,
17+
treats = List.empty,
18+
lastUpdated = None,
19+
href = None,
20+
description = None,
21+
collectionType = "unknown",
22+
groups = None,
23+
uneditable = false,
24+
showTags = false,
25+
showSections = false,
26+
hideKickers = false,
27+
showDateHeader = false,
28+
showLatestUpdate = false,
29+
config = CollectionConfig.empty.copy(displayHints = maxItemsToDisplay.map(m => DisplayHints(Some(m)))),
30+
hasMore = false
31+
)
32+
}
33+
34+
def mkPressedPage(collections: List[PressedCollection]) = {
35+
PressedPage(
36+
id = "test-pressed-page",
37+
seoData = SeoData.empty,
38+
frontProperties= FrontProperties.empty,
39+
collections = collections
40+
)
41+
}
42+
743
def mkPressedContent(id: Int, kicker: Option[ItemKicker] = None): PressedContent = {
844

945
def mkProperties(): PressedProperties = PressedProperties(
@@ -18,7 +54,7 @@ object FixtureBuilder {
1854
isCrossword = false,
1955
byline = None,
2056
image = None,
21-
webTitle = "",
57+
webTitle = s"webTitle $id",
2258
linkText = None,
2359
embedType = None,
2460
embedCss = None,
Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package layout
22

33
import common.facia.FixtureBuilder
4-
import model.facia.PressedCollection
5-
import model.pressed.{CollectionConfig, DisplayHints, PressedContent}
6-
import model.{FrontProperties, PressedPage, SeoData}
74
import org.scalatest.{FlatSpec, Matchers, OptionValues}
85

96
class CollectionEmailTest extends FlatSpec with Matchers with OptionValues {
107

118
it should "respect the maxItemsToDisplay property if set" in {
12-
val pressedPage = mkPressedPage(
13-
List(mkPressedCollection(
9+
val pressedPage = FixtureBuilder.mkPressedPage(
10+
List(FixtureBuilder.mkPressedCollection(
1411
id = "1",
15-
curated = (1 to 4).map(mkContent),
16-
backfill = (5 to 8).map(mkContent),
12+
curated = (1 to 4).map(FixtureBuilder.mkContent),
13+
backfill = (5 to 8).map(FixtureBuilder.mkContent),
1714
maxItemsToDisplay = Some(8))
1815
)
1916
)
@@ -23,11 +20,11 @@ class CollectionEmailTest extends FlatSpec with Matchers with OptionValues {
2320
}
2421

2522
it should "exclude empty containers" in {
26-
val pressedPage = mkPressedPage(
23+
val pressedPage = FixtureBuilder.mkPressedPage(
2724
List(
28-
mkPressedCollection(id = "1", curated = (10 to 12).map(mkContent), backfill = (13 to 15).map(mkContent)),
29-
mkPressedCollection(id = "2", curated = Nil, backfill = Nil),
30-
mkPressedCollection(id = "3", curated = (30 to 32).map(mkContent), backfill = (33 to 35).map(mkContent))
25+
FixtureBuilder.mkPressedCollection(id = "1", curated = (10 to 12).map(FixtureBuilder.mkContent), backfill = (13 to 15).map(FixtureBuilder.mkContent)),
26+
FixtureBuilder.mkPressedCollection(id = "2", curated = Nil, backfill = Nil),
27+
FixtureBuilder.mkPressedCollection(id = "3", curated = (30 to 32).map(FixtureBuilder.mkContent), backfill = (33 to 35).map(FixtureBuilder.mkContent))
3128
)
3229
)
3330

@@ -36,37 +33,4 @@ class CollectionEmailTest extends FlatSpec with Matchers with OptionValues {
3633
result.contentCollections.map(_.displayName) shouldEqual List("Test Collection 1", "Test Collection 3")
3734
}
3835

39-
private def mkContent(id: Int): PressedContent = FixtureBuilder.mkPressedContent(id)
40-
41-
private def mkPressedCollection(id: String, curated: Seq[PressedContent] = IndexedSeq.empty, backfill: Seq[PressedContent] = IndexedSeq.empty, maxItemsToDisplay: Option[Int] = None) = {
42-
PressedCollection(
43-
id = "test-colleciton",
44-
displayName = s"Test Collection $id",
45-
curated = curated.toList,
46-
backfill = backfill.toList,
47-
treats = List.empty,
48-
lastUpdated = None,
49-
href = None,
50-
description = None,
51-
collectionType = "unknown",
52-
groups = None,
53-
uneditable = false,
54-
showTags = false,
55-
showSections = false,
56-
hideKickers = false,
57-
showDateHeader = false,
58-
showLatestUpdate = false,
59-
config = CollectionConfig.empty.copy(displayHints = maxItemsToDisplay.map(m => DisplayHints(Some(m)))),
60-
hasMore = false
61-
)
62-
}
63-
64-
private def mkPressedPage(collections: List[PressedCollection]) = {
65-
PressedPage(
66-
id = "test-pressed-page",
67-
seoData = SeoData.empty,
68-
frontProperties= FrontProperties.empty,
69-
collections = collections
70-
)
71-
}
7236
}

‎facia/app/controllers/FaciaController.scala‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package controllers
33
import common._
44
import controllers.front._
55
import layout.{CollectionEssentials, ContentCard, FaciaCard, FaciaCardAndIndex, FaciaContainer, Front}
6-
import model.Cached.{RevalidatableResult, WithoutRevalidationResult}
6+
import model.Cached.{CacheableResult, RevalidatableResult, WithoutRevalidationResult}
77
import model._
88
import model.facia.PressedCollection
99
import model.pressed.{CollectionConfig, PressedContent}
@@ -83,6 +83,17 @@ trait FaciaController extends BaseController with Logging with ImplicitControlle
8383

8484
def rootEditionRedirect(): Action[AnyContent] = renderFront(path = "")
8585

86+
def renderFrontHeadline(path: String): Action[AnyContent] = Action.async { implicit request =>
87+
def notFound() = {
88+
log.warn(s"headline not found for $path")
89+
FrontHeadline.headlineNotFound
90+
}
91+
92+
frontJsonFapi.get(path, liteRequestType)
93+
.map(_.fold[CacheableResult](notFound())(FrontHeadline.renderEmailHeadline))
94+
.map(Cached(CacheTime.Facia))
95+
}
96+
8697
def renderFront(path: String): Action[AnyContent] = Action.async { implicit request =>
8798
log.info(s"Serving Path: $path")
8899
if (shouldEditionRedirect(path))
@@ -134,7 +145,7 @@ trait FaciaController extends BaseController with Logging with ImplicitControlle
134145

135146
private def renderEmail(faciaPage: PressedPage)(implicit request: RequestHeader) = {
136147
if (request.isEmailHeadlineText) {
137-
renderEmailHeadline(faciaPage)
148+
FrontHeadline.renderEmailHeadline(faciaPage)
138149
} else {
139150
renderEmailFront(faciaPage)
140151
}
@@ -152,15 +163,6 @@ trait FaciaController extends BaseController with Logging with ImplicitControlle
152163
}
153164
}
154165

155-
private def renderEmailHeadline(faciaPage: PressedPage) = {
156-
val webTitle = for {
157-
topCollection <- faciaPage.collections.headOption
158-
topCurated <- topCollection.curatedPlusBackfillDeduplicated.headOption
159-
} yield RevalidatableResult.Ok(topCurated.properties.webTitle)
160-
161-
webTitle.getOrElse(WithoutRevalidationResult(NotFound("Could not extract headline from front")))
162-
}
163-
164166
def renderFrontPress(path: String): Action[AnyContent] = Action.async { implicit request => renderFrontPressResult(path) }
165167

166168
def renderContainer(id: String, preserveLayout: Boolean = false): Action[AnyContent] = Action.async { implicit request =>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package controllers.front
2+
3+
import common.Logging
4+
import model.Cached.{RevalidatableResult, WithoutRevalidationResult}
5+
import model.{Cached, PressedPage}
6+
import play.api.mvc.Results
7+
8+
object FrontHeadline extends Results with Logging {
9+
10+
val headlineNotFound: Cached.CacheableResult = WithoutRevalidationResult(NotFound("Could not extract headline from front"))
11+
12+
def renderEmailHeadline(faciaPage: PressedPage): Cached.CacheableResult = {
13+
val webTitle = for {
14+
topCollection <- faciaPage.collections.headOption
15+
topCurated <- topCollection.curatedPlusBackfillDeduplicated.headOption
16+
} yield RevalidatableResult.Ok(topCurated.properties.webTitle)
17+
18+
webTitle.getOrElse {
19+
log.warn(s"headline not found for ${faciaPage.id}")
20+
headlineNotFound
21+
}
22+
}
23+
24+
}

‎facia/conf/routes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ GET /*path/rss
3232
GET /*path/lite.json controllers.FaciaController.renderFrontJsonLite(path)
3333
GET /*path.emailjson controllers.FaciaController.renderFrontJson(path)
3434
GET /*path.json controllers.FaciaController.renderFrontJson(path)
35+
GET /*path/headline.txt controllers.FaciaController.renderFrontHeadline(path)
3536
GET / controllers.FaciaController.rootEditionRedirect()
3637
GET /*path controllers.FaciaController.renderFront(path)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package controllers.front
2+
3+
import akka.util.Timeout
4+
import common.facia.FixtureBuilder
5+
import model.Cached.RevalidatableResult
6+
import org.scalatest.{FunSuite, Matchers}
7+
import play.api.test.Helpers
8+
import scala.concurrent.duration._
9+
import scala.concurrent.Future
10+
import scala.language.postfixOps
11+
12+
class FrontHeadlineTest extends FunSuite with Matchers {
13+
implicit val timeout: Timeout = Timeout(5 seconds)
14+
15+
test("renderEmailHeadline extracts headline from pressed page") {
16+
val pressedPage = FixtureBuilder.mkPressedPage(
17+
List(FixtureBuilder.mkPressedCollection(
18+
id = "1",
19+
curated = (1 to 4).map(FixtureBuilder.mkContent),
20+
backfill = (5 to 8).map(FixtureBuilder.mkContent),
21+
maxItemsToDisplay = Some(8))
22+
)
23+
)
24+
25+
val RevalidatableResult(result, _) = FrontHeadline.renderEmailHeadline(pressedPage)
26+
val resultFuture = Future.successful(result)
27+
val headline = Helpers.contentAsString(resultFuture)
28+
val status = Helpers.status(resultFuture)
29+
30+
headline shouldBe "webTitle 1"
31+
status shouldBe 200
32+
}
33+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL