Last active
April 7, 2022 06:53
-
-
Save supermanue/ef3ece104b7e039396bfe994c9a3cd96 to your computer and use it in GitHub Desktop.
Testing the Adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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