@@ -15,9 +15,17 @@ import scala.concurrent.{Await, ExecutionContext, Future}
1515class 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 json = """ {"version":"1","articles":[{"id":"id/1","shortUrl":"p/1","date":"2026-07-16T10:15:30Z","read":false}]}"""
20+ updateSavedArticles.save(any[Map [String , String ]](), any[SavedArticles ]()) returns Future .successful(Left (mock[SaveForLaterError ]))
21+
22+ Await .result(controller(LambdaRequest (Some (json))), Duration .Inf )
23+
24+ there was one(updateSavedArticles).save(any[Map [String , String ]](), any[SavedArticles ]())
25+ }
1826
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}]}"""
27+ " return a 400 when the date is not in the expected format" in new Setup {
28+ val json = """ {"version":"1","articles":[{"id":"id/1","shortUrl":"p/1","date":"Fri Jan 01 08:00:01 GMT+08:00 2010 ","read":false}]}"""
2129 val response = Await .result(controller(LambdaRequest (Some (json))), Duration .Inf )
2230
2331 response.statusCode mustEqual StatusCodes .badRequest
@@ -36,19 +44,11 @@ class SaveArticlesControllerSpec extends Specification with Mockito {
3644 response.statusCode mustEqual StatusCodes .badRequest
3745 }
3846
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- }
4747 }
4848
4949 trait Setup extends Scope {
5050 implicit val executionContext : ExecutionContext = scala.concurrent.ExecutionContext .global
5151 val updateSavedArticles = mock[UpdateSavedArticles ]
5252 val controller = new SaveArticlesController (updateSavedArticles)
5353 }
54- }
54+ }
0 commit comments