-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We'd like to send a list of crosswords to DCAR, so this changes the structure of the data model. It also applies some of the solutions logic used in the similar `CrosswordData` model, widens the types of crosswords requested, and switches to a more specific CAPI search query. Note that it uses the CAPI client's `SearchQuery` directly rather than frontend's `contentApiClient.search`, as that includes a number of fields we don't need here.
- Loading branch information
Showing
3 changed files
with
149 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
common/test/model/dotcomrendering/EditionsCrosswordRenderingDataModelTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package model.dotcomrendering | ||
|
||
import com.gu.contentapi.client.model.v1.{CapiDateTime, Crossword, CrosswordType, CrosswordDimensions, CrosswordEntry} | ||
import model.dotcomrendering.pageElements.EditionsCrosswordRenderingDataModel | ||
import org.mockito.Mockito.when | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatestplus.mockito.MockitoSugar | ||
import org.joda.time.DateTime | ||
|
||
class EditionsCrosswordRenderingDataModelTest extends AnyFlatSpec with Matchers with MockitoSugar { | ||
val mockEntry = CrosswordEntry( | ||
id = "mockId", | ||
solution = Some("Mock solution"), | ||
) | ||
|
||
val mockCrossword = Crossword( | ||
name = "Mock name", | ||
`type` = CrosswordType.Quick, | ||
number = 1, | ||
date = CapiDateTime(DateTime.now().getMillis(), "date"), | ||
dimensions = CrosswordDimensions(1, 1), | ||
entries = Seq(mockEntry, mockEntry), | ||
solutionAvailable = true, | ||
hasNumbers = false, | ||
randomCluesOrdering = false, | ||
) | ||
|
||
"apply" should "provide solutions when 'dateSolutionAvailable' is in the past" in { | ||
val crossword = mockCrossword.copy( | ||
solutionAvailable = true, | ||
dateSolutionAvailable = Some(CapiDateTime(DateTime.now().minusDays(1).getMillis(), "date")), | ||
) | ||
|
||
val crosswords = | ||
EditionsCrosswordRenderingDataModel(Seq(crossword, crossword)) | ||
.crosswords | ||
.toSeq | ||
|
||
crosswords(0).entries(0).solution shouldBe Some("Mock solution") | ||
crosswords(0).entries(1).solution shouldBe Some("Mock solution") | ||
crosswords(1).entries(0).solution shouldBe Some("Mock solution") | ||
crosswords(1).entries(1).solution shouldBe Some("Mock solution") | ||
} | ||
|
||
"apply" should "provide solutions when 'dateSolutionAvailable' is 'None' and solutionAvailable is 'true'" in { | ||
val crossword = mockCrossword.copy( | ||
solutionAvailable = true, | ||
dateSolutionAvailable = None, | ||
) | ||
|
||
val crosswords = | ||
EditionsCrosswordRenderingDataModel(Seq(crossword, crossword)) | ||
.crosswords | ||
.toSeq | ||
|
||
crosswords(0).entries(0).solution shouldBe Some("Mock solution") | ||
crosswords(0).entries(1).solution shouldBe Some("Mock solution") | ||
crosswords(1).entries(0).solution shouldBe Some("Mock solution") | ||
crosswords(1).entries(1).solution shouldBe Some("Mock solution") | ||
} | ||
|
||
"apply" should "not provide solutions when 'dateSolutionAvailable' is in the future" in { | ||
val crossword = mockCrossword.copy( | ||
solutionAvailable = true, | ||
dateSolutionAvailable = Some(CapiDateTime(DateTime.now().plusDays(1).getMillis(), "date")), | ||
) | ||
|
||
val crosswords = | ||
EditionsCrosswordRenderingDataModel(Seq(crossword, crossword)) | ||
.crosswords | ||
.toSeq | ||
|
||
crosswords(0).entries(0).solution shouldBe None | ||
crosswords(0).entries(1).solution shouldBe None | ||
crosswords(1).entries(0).solution shouldBe None | ||
crosswords(1).entries(1).solution shouldBe None | ||
} | ||
|
||
"apply" should "not provide solutions when 'dateSolutionAvailable' is 'None' and solutionAvailable is 'false'" in { | ||
val crossword = mockCrossword.copy( | ||
solutionAvailable = false, | ||
dateSolutionAvailable = None, | ||
) | ||
|
||
val crosswords = | ||
EditionsCrosswordRenderingDataModel(Seq(crossword, crossword)) | ||
.crosswords | ||
.toSeq | ||
|
||
crosswords(0).entries(0).solution shouldBe None | ||
crosswords(0).entries(1).solution shouldBe None | ||
crosswords(1).entries(0).solution shouldBe None | ||
crosswords(1).entries(1).solution shouldBe None | ||
} | ||
} |