forked from CodelyTV/scala-ddd-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoEntryPointShould.scala
49 lines (42 loc) · 1.45 KB
/
VideoEntryPointShould.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tv.codely.scala_http_api.entry_point
import doobie.implicits._
import akka.http.scaladsl.model.{ContentTypes, StatusCodes}
import org.scalatest.BeforeAndAfterEach
import spray.json._
import tv.codely.scala_http_api.module.video.domain.VideoStub
import tv.codely.scala_http_api.module.video.infrastructure.marshaller.VideoJsValueMarshaller
final class VideoEntryPointShould extends AcceptanceSpec with BeforeAndAfterEach {
private def cleanVideosTable(): Unit =
sql"TRUNCATE TABLE videos".update.run
.transact(doobieDbConnection.transactor)
.unsafeToFuture()
.map(_ => ())
.futureValue
override protected def beforeEach(): Unit = {
super.beforeEach()
cleanVideosTable()
}
"save a video" in posting(
"/videos",
"""
|{
| "id": "c5e3774b-20bb-47d3-b9fa-9f9a6e75e280",
| "title": "Creando proyectos #Scala con SBT new ƛ🌈",
| "duration_in_seconds": 698,
| "category": "Screencast",
| "creator_id": "3f3df8d8-ad4c-4a1a-9d32-5c14663a409e"
|}
""".stripMargin
) {
status shouldBe StatusCodes.NoContent
}
"return all the videos" in {
val videos = VideoStub.randomSeq
videos.foreach(v => videoDependencies.repository.save(v).futureValue)
getting("/videos") {
status shouldBe StatusCodes.OK
contentType shouldBe ContentTypes.`application/json`
entityAs[String].parseJson shouldBe VideoJsValueMarshaller.marshall(videos)
}
}
}