Skip to content

Instantly share code, notes, and snippets.

@supermanue
Created March 26, 2022 17:46
Show Gist options
  • Save supermanue/aa9fb57a2b404be66267ef86388c2552 to your computer and use it in GitHub Desktop.
Save supermanue/aa9fb57a2b404be66267ef86388c2552 to your computer and use it in GitHub Desktop.
User test
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