Skip to content

Instantly share code, notes, and snippets.

@supermanue
Last active April 7, 2022 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supermanue/ef3ece104b7e039396bfe994c9a3cd96 to your computer and use it in GitHub Desktop.
Save supermanue/ef3ece104b7e039396bfe994c9a3cd96 to your computer and use it in GitHub Desktop.
Testing the Adapter
object DoobiePersistenceServiceTest extends DefaultRunnableSpec {
def beforeEach: ZIO[DBTransactor, Throwable, Unit] = dropUserTable.flatMap(_ => createUserTable)
def spec: ZSpec[TestEnvironment, Failure] =
suite("DoobiePersistenceService unit test")(
testM("GET should return a UserNotFound if the element does not exist") {
for {
_ <- beforeEach
notFound <- RIO.accessM[UserPersistence](_.get.get(100).either)
} yield assert(notFound.swap.getOrElse(anything))(isSubtype[UserNotFound](anything))
},
testM("GET should return the user if it exists") {
for {
_ <- beforeEach
stored <- RIO.accessM[UserPersistence](_.get.create(user)).either
found <- RIO.accessM[UserPersistence](_.get.get(user.id.value)).either
} yield assert(stored)(isRight(equalTo(user))) && assert(found)(isRight(equalTo(user)))
}
).provideSomeLayer[TestEnvironment](
(Configuration.live >+> Blocking.live >+> DoobiePersistenceService.transactorLive >+> DoobiePersistenceService.live)
.mapError(_ => TestFailure.Runtime(Cause.die(new Exception("die"))))
) @@ sequential
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment