Skip to content

Commit d654d2d

Browse files
committed
update test
1 parent c3424dc commit d654d2d

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

mobile-save-for-later/src/test/scala/com/gu/sfl/controller/SaveArticlesControllerSpec.scala

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@ import scala.concurrent.{Await, ExecutionContext, Future}
1515
class SaveArticlesControllerSpec extends Specification with Mockito {
1616

1717
"SaveArticlesController" should {
18+
"save the articles when the date is in the expected format" in new Setup {
19+
val validDateTimeString = "2026-07-16T10:15:30Z"
20+
val json = s"""{"version":"1","articles":[{"id":"id/1","shortUrl":"p/1","date": $validDateTimeString,"read":false}]}"""
21+
updateSavedArticles.save(any[Map[String, String]](), any[SavedArticles]()) returns Future.successful(Left(mock[SaveForLaterError]))
22+
23+
Await.result(controller(LambdaRequest(Some(json))), Duration.Inf)
1824

19-
"return a 400 when the date on an article is not in the expected format" in new Setup {
20-
val json = """{"version":"1","articles":[{"id":"id/1","shortUrl":"p/1","date":"2026-07-16T10:15:30.123Z","read":false}]}"""
25+
there was one(updateSavedArticles).save(any[Map[String, String]](), any[SavedArticles]())
26+
}
27+
28+
"return a 400 when the date is not in the expected format" in new Setup {
29+
val invalidDateTimeString = "Fri Jan 01 08:00:01 GMT+08:00 2010"
30+
val json = s"""{"version":"1","articles":[{"id":"id/1","shortUrl":"p/1","date": $invalidDateTimeString,"read":false}]}"""
2131
val response = Await.result(controller(LambdaRequest(Some(json))), Duration.Inf)
2232

2333
response.statusCode mustEqual StatusCodes.badRequest
@@ -35,20 +45,11 @@ class SaveArticlesControllerSpec extends Specification with Mockito {
3545

3646
response.statusCode mustEqual StatusCodes.badRequest
3747
}
38-
39-
"attempt to save the articles when the date is in the expected format" in new Setup {
40-
val json = """{"version":"1","articles":[{"id":"id/1","shortUrl":"p/1","date":"2026-07-16T10:15:30Z","read":false}]}"""
41-
updateSavedArticles.save(any[Map[String, String]](), any[SavedArticles]()) returns Future.successful(Left(mock[SaveForLaterError]))
42-
43-
Await.result(controller(LambdaRequest(Some(json))), Duration.Inf)
44-
45-
there was one(updateSavedArticles).save(any[Map[String, String]](), any[SavedArticles]())
46-
}
4748
}
4849

4950
trait Setup extends Scope {
5051
implicit val executionContext: ExecutionContext = scala.concurrent.ExecutionContext.global
5152
val updateSavedArticles = mock[UpdateSavedArticles]
5253
val controller = new SaveArticlesController(updateSavedArticles)
5354
}
54-
}
55+
}

0 commit comments

Comments
 (0)