Created
March 26, 2022 17:46
-
-
Save supermanue/aa9fb57a2b404be66267ef86388c2552 to your computer and use it in GitHub Desktop.
User test
This file contains hidden or 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 UserTest extends DefaultRunnableSpec with DomainFixtures { | |
def spec: ZSpec[TestEnvironment, Failure] = | |
suite("UserTest")( | |
testM("creating a user with valid input should succeed") { | |
check(positiveIntGen, nonemptyStringGen) { (positiveInt, nonemptyString) => | |
val user = User.build(positiveInt, nonemptyString) | |
assert(user)(isRight) | |
} | |
}, | |
testM("creating a user with id=0 should fail") { | |
check(nonemptyStringGen) { nonemptyString => | |
val user = User.build(0, nonemptyString) | |
assert(user.left.getOrElse(false).isInstanceOf[RefinedTypeError])(isTrue) | |
} | |
}, | |
testM("creating a user with negative id should fail") { | |
check(nonemptyStringGen) { nonemptyString => | |
val user = User.build(-1, nonemptyString) | |
assert(user.left.getOrElse(false).isInstanceOf[RefinedTypeError])(isTrue) | |
} | |
}, | |
testM("creating a user with an empty name should fail") { | |
check(positiveIntGen) { positiveInt => | |
val user = User.build(positiveInt, "") | |
assert(user.left.getOrElse(false).isInstanceOf[RefinedTypeError])(isTrue) | |
} | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment