Add users validation
This commit is contained in:
+4
-3
@@ -1,4 +1,4 @@
|
||||
package routing
|
||||
package integration.routing
|
||||
|
||||
import be.vandewalleh.auth.SimpleJWT
|
||||
import be.vandewalleh.entities.User
|
||||
@@ -70,7 +70,7 @@ class UserControllerKtTest {
|
||||
val res = testEngine.post("/user") {
|
||||
json {
|
||||
it["username"] = "new"
|
||||
it["password"] = "test"
|
||||
it["password"] = "test123abc"
|
||||
it["email"] = "new@test.com"
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class UserControllerKtTest {
|
||||
json {
|
||||
it["username"] = "existing"
|
||||
it["email"] = "existing@test.com"
|
||||
it["password"] = "test"
|
||||
it["password"] = "test123abc"
|
||||
}
|
||||
}
|
||||
res.status() `should be equal to` HttpStatusCode.Conflict
|
||||
@@ -129,6 +129,7 @@ class UserControllerKtTest {
|
||||
json {
|
||||
it["username"] = "ThisIsMyNewName"
|
||||
it["email"] = "ThisIsMyNewName@mail.com"
|
||||
it["password"] = "ThisIsMyCurrentPassword"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package services
|
||||
package integration.services
|
||||
|
||||
import be.vandewalleh.mainModule
|
||||
import be.vandewalleh.migrations.Migration
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package utils
|
||||
|
||||
import am.ik.yavi.core.ConstraintViolations
|
||||
|
||||
val ConstraintViolations.firstInvalid: Any?
|
||||
get() = this.violations().firstOrNull()?.name()
|
||||
Reference in New Issue
Block a user