Upgrade to ktorm 3.0.0, remove email field from users
This commit is contained in:
@@ -13,7 +13,6 @@ import io.ktor.server.testing.*
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.amshove.kluent.*
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.*
|
||||
@@ -37,11 +36,10 @@ class AuthControllerKtTest {
|
||||
}
|
||||
user["id"] = 1
|
||||
|
||||
coEvery { userService.getFromUsername("existing") } returns user
|
||||
coEvery { userService.userExists(1) } returns true
|
||||
coEvery { userService.getUserInfo(1) } returns User {
|
||||
coEvery { userService.find("existing") } returns user
|
||||
coEvery { userService.exists(1) } returns true
|
||||
coEvery { userService.find(1) } returns User {
|
||||
username = "existing"
|
||||
email = "existing@mail.com"
|
||||
}
|
||||
|
||||
val user2 = User {
|
||||
@@ -49,12 +47,12 @@ class AuthControllerKtTest {
|
||||
username = "wrong"
|
||||
}
|
||||
user["id"] = 2
|
||||
coEvery { userService.getFromUsername("wrong") } returns user2
|
||||
coEvery { userService.find("wrong") } returns user2
|
||||
|
||||
coEvery { userService.getFromUsername("notExisting") } returns null
|
||||
coEvery { userService.find("notExisting") } returns null
|
||||
|
||||
coEvery { userService.userExists(3) } returns false
|
||||
coEvery { userService.getUserInfo(3) } returns null
|
||||
coEvery { userService.exists(3) } returns false
|
||||
coEvery { userService.find(3) } returns null
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +77,7 @@ class AuthControllerKtTest {
|
||||
}
|
||||
}
|
||||
|
||||
coVerify { userService.getFromUsername("existing") }
|
||||
coVerify { userService.find("existing") }
|
||||
|
||||
res.status() `should be equal to` HttpStatusCode.OK
|
||||
val jsonObject = JSONObject(res.content)
|
||||
@@ -107,7 +105,7 @@ class AuthControllerKtTest {
|
||||
}
|
||||
}
|
||||
|
||||
coVerify { userService.getFromUsername("wrong") }
|
||||
coVerify { userService.find("wrong") }
|
||||
|
||||
res.status() `should be equal to` HttpStatusCode.Unauthorized
|
||||
res.content `should strictly be equal to json` """{msg: "Unauthorized"}"""
|
||||
@@ -122,7 +120,7 @@ class AuthControllerKtTest {
|
||||
}
|
||||
}
|
||||
|
||||
coVerify { userService.getFromUsername("notExisting") }
|
||||
coVerify { userService.find("notExisting") }
|
||||
|
||||
res.status() `should be equal to` HttpStatusCode.Unauthorized
|
||||
res.content `should strictly be equal to json` """{msg: "Unauthorized"}"""
|
||||
@@ -155,7 +153,7 @@ class AuthControllerKtTest {
|
||||
val jsonObject = JSONObject(res.content)
|
||||
jsonObject.keyList() `should be equal to` listOf("token", "refreshToken")
|
||||
|
||||
coVerify { userService.userExists(1) }
|
||||
coVerify { userService.exists(1) }
|
||||
res.status() `should be equal to` HttpStatusCode.OK
|
||||
}
|
||||
|
||||
@@ -170,7 +168,7 @@ class AuthControllerKtTest {
|
||||
}
|
||||
}
|
||||
|
||||
coVerify { userService.userExists(3) }
|
||||
coVerify { userService.exists(3) }
|
||||
res.status() `should be equal to` HttpStatusCode.Unauthorized
|
||||
res.content `should strictly be equal to json` """{msg: "Unauthorized"}"""
|
||||
}
|
||||
@@ -207,7 +205,7 @@ class AuthControllerKtTest {
|
||||
val res = testEngine.get("/user/me") {
|
||||
setToken(token)
|
||||
}
|
||||
res.content `should strictly be equal to json` """{user:{username:"existing", email: "existing@mail.com"}}"""
|
||||
res.content `should strictly be equal to json` """{user:{username:"existing"}}"""
|
||||
res.status() `should be equal to` HttpStatusCode.OK
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.kodein.di.Kodein
|
||||
import org.kodein.di.generic.bind
|
||||
import org.kodein.di.generic.instance
|
||||
import utils.*
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class UserControllerKtTest {
|
||||
@@ -24,31 +23,21 @@ class UserControllerKtTest {
|
||||
|
||||
init {
|
||||
// new user
|
||||
coEvery { userService.userExists("new", "new@test.com") } returns false
|
||||
coEvery { userService.createUser("new", "new@test.com", any()) } returns User {
|
||||
this.createdAt = LocalDateTime.now()
|
||||
coEvery { userService.exists("new") } returns false
|
||||
coEvery { userService.create("new", any()) } returns User {
|
||||
this.username = "new"
|
||||
this.email = "new@test.com"
|
||||
}
|
||||
|
||||
// existing user
|
||||
coEvery { userService.userExists("existing", "existing@test.com") } returns true
|
||||
coEvery { userService.createUser("existing", "existing@test.com", any()) } returns null
|
||||
coEvery { userService.getUserId("existing@test.com") } returns 1
|
||||
coEvery { userService.deleteUser(1) } returns true andThen false
|
||||
coEvery { userService.exists("existing") } returns true
|
||||
coEvery { userService.create("existing", any()) } returns null
|
||||
coEvery { userService.delete(1) } returns true andThen false
|
||||
|
||||
// modified user
|
||||
coEvery { userService.userExists("modified", "modified@test.com") } returns true
|
||||
coEvery {
|
||||
userService.userExists(
|
||||
and(not("modified"), not("existing")),
|
||||
and(not("modified@test.com"), not("existing@test.com"))
|
||||
)
|
||||
} returns false
|
||||
coEvery { userService.userExists(1) } returns true
|
||||
coEvery { userService.createUser("modified", "modified@test.com", any()) } returns null
|
||||
coEvery { userService.getUserId("modified@test.com") } returns 1
|
||||
coEvery { userService.updateUser(1, "ThisIsMyNewName", "ThisIsMyNewName@mail.com", any()) } returns Unit
|
||||
coEvery { userService.exists("modified") } returns true
|
||||
coEvery { userService.exists(and(not("modified"), not("existing"))) } returns false
|
||||
coEvery { userService.exists(1) } returns true
|
||||
coEvery { userService.create("modified", any()) } returns null
|
||||
|
||||
}
|
||||
|
||||
@@ -71,11 +60,10 @@ class UserControllerKtTest {
|
||||
json {
|
||||
it["username"] = "new"
|
||||
it["password"] = "test123abc"
|
||||
it["email"] = "new@test.com"
|
||||
}
|
||||
}
|
||||
res.status() `should be equal to` HttpStatusCode.Created
|
||||
res.content `should be equal to json` """{msg:"Created"}"""
|
||||
res.content `should strictly be equal to json` """{username:"new"}"""
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +71,6 @@ class UserControllerKtTest {
|
||||
val res = testEngine.post("/user") {
|
||||
json {
|
||||
it["username"] = "existing"
|
||||
it["email"] = "existing@test.com"
|
||||
it["password"] = "test123abc"
|
||||
}
|
||||
}
|
||||
@@ -116,28 +103,4 @@ class UserControllerKtTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class ModifyUser {
|
||||
|
||||
@Test
|
||||
fun `modify a user`() {
|
||||
val authJwt by kodein.instance<SimpleJWT>("auth")
|
||||
val token = authJwt.sign(1)
|
||||
|
||||
val res = testEngine.put("/user") {
|
||||
setToken(token)
|
||||
json {
|
||||
it["username"] = "ThisIsMyNewName"
|
||||
it["email"] = "ThisIsMyNewName@mail.com"
|
||||
it["password"] = "ThisIsMyCurrentPassword"
|
||||
}
|
||||
}
|
||||
|
||||
res.status() `should be equal to` HttpStatusCode.OK
|
||||
res.content `should be equal to json` """{msg:"OK"}"""
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -39,17 +39,12 @@ class UserServiceTest {
|
||||
fun `test create user`() {
|
||||
runBlocking {
|
||||
val username = "hubert"
|
||||
val email = "a@a"
|
||||
val password = "password"
|
||||
|
||||
userService.createUser(username, email, password)
|
||||
val id = userService.getUserId(email)
|
||||
id `should not be` null
|
||||
|
||||
userService.getUserInfo(id!!)!!.let {
|
||||
it.username `should be equal to` username
|
||||
it.email `should be equal to` email
|
||||
}
|
||||
userService.create(username, password)
|
||||
val user = userService.find(username)
|
||||
user `should not be` null
|
||||
user?.username `should be equal to` username
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +52,7 @@ class UserServiceTest {
|
||||
@Order(2)
|
||||
fun `test create same user`() {
|
||||
runBlocking {
|
||||
userService.createUser(username = "hubert", hashedPassword = "password", email = "a@a") `should be` null
|
||||
userService.create(username = "hubert", hashedPassword = "password") `should be` null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,12 +60,11 @@ class UserServiceTest {
|
||||
@Order(3)
|
||||
fun `test delete user`() {
|
||||
runBlocking {
|
||||
val email = "a@a"
|
||||
val id = userService.getUserId(email)!!
|
||||
userService.deleteUser(id)
|
||||
val id = userService.find("hubert")!!.id
|
||||
userService.delete(id)
|
||||
|
||||
userService.getUserId(email) `should be` null
|
||||
userService.getUserInfo(id) `should be` null
|
||||
userService.find("hubert") `should be` null
|
||||
userService.find(id) `should be` null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user