Add users validation

This commit is contained in:
2020-06-15 00:27:55 +02:00
parent f09219b032
commit e360489257
8 changed files with 109 additions and 11 deletions
@@ -0,0 +1,57 @@
package unit.validation
import be.vandewalleh.entities.User
import be.vandewalleh.validation.user.registerValidator
import org.amshove.kluent.*
import org.junit.jupiter.api.*
import utils.firstInvalid
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class RegisterValidationTest {
@Test
fun `valid register test`() {
val violations = registerValidator.validate(User {
username = "hubert"
password = "definitelyNotMyPassword"
email = "test@mail.com"
})
violations.isValid `should be equal to` true
}
@Test
fun `invalid email test`() {
val violations = registerValidator.validate(User {
username = "hubert"
password = "definitelyNotMyPassword"
email = "teom"
})
violations.isValid `should be equal to` false
violations.firstInvalid `should be equal to` "email"
}
@Test
fun `missing email test`() {
val violations = registerValidator.validate(User {
username = "hubert"
password = "definitelyNotMyPassword"
})
violations.isValid `should be equal to` false
violations.firstInvalid `should be equal to` "email"
}
@Test
fun `username too long test`() {
val violations = registerValidator.validate(User {
username = "6X9iboWmEOWjVjkO328ReTJ1gGPTTmB/ZGgBLhB6EzAJoWkJht8"
password = "definitelyNotMyPassword"
email = "test@mail.com"
})
violations.isValid `should be equal to` false
violations.firstInvalid `should be equal to` "username"
}
}