Skip to content

Added find an existing video use case & unit test #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package tv.codely.mooc.video.application.search

import tv.codely.mooc.video.domain.{Video, VideoRepository}
import tv.codely.mooc.video.domain.{Video, VideoId,VideoRepository}

import scala.concurrent.Future

final class VideosSearcher(repository: VideoRepository) {
def all(): Future[Seq[Video]] = repository.all()

def find(videoId: VideoId): Future[Option[Video]] = {
repository.find(videoId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ trait VideoRepository {
def all(): Future[Seq[Video]]

def save(video: Video): Future[Unit]

def find(videoId: VideoId): Future[Option[Video]]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tv.codely.mooc.video.infrastructure.repository

import doobie.implicits._
import tv.codely.mooc.video.domain.{Video, VideoRepository}
import tv.codely.mooc.video.domain.{Video, VideoId, VideoRepository}
import tv.codely.mooc.shared.infrastructure.doobie.TypesConversions._
import tv.codely.shared.infrastructure.doobie.DoobieDbConnection

Expand All @@ -17,4 +17,9 @@ final class DoobieMySqlVideoRepository(db: DoobieDbConnection)(implicit executio
.transact(db.transactor)
.unsafeToFuture()
.map(_ => ())

override def find(videoId: VideoId): Future[Option[Video]] =
db.read(sql"SELECT video_id, title, duration_in_seconds, category, creator_id FROM videos WHERE video_id=${videoId.value}"
.query[Video]
.option)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ final class VideosSearcherShould extends UnitTestCase with VideoRepositoryMock {

searcher.all().futureValue shouldBe existingVideos
}

"find an existing video" in {
val video = VideoMother.random
repositoryShouldFind(video)
repository.find(video.id).futureValue.get shouldBe video
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ protected[video] trait VideoRepositoryMock extends MockFactory {
(repository.all _)
.expects()
.returning(Future.successful(videos))

protected def repositoryShouldFind(video: Video): Unit =
(repository.find _)
.expects(video.id)
.returning(Future.successful(Some(video)))
}