Skip to content

Commit

Permalink
Push works
Browse files Browse the repository at this point in the history
  • Loading branch information
cheroliv committed Sep 29, 2024
1 parent 1c13342 commit 40aaa03
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
19 changes: 13 additions & 6 deletions springboot/api/src/main/kotlin/webapp/core/model/EntityModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ abstract class EntityModel<T>(
const val ID_MEMBER = "id"

// Generic extension function that allows the ID to be applied to any EntityModel type
inline fun <reified T : EntityModel<ID>, ID> T.withId(id: ID): T {
inline fun <reified T : EntityModel<ID>, ID> T.withId(id: ID): T =
// Use reflection to create a copy with the passed ID
return this::class.constructors.first { it.parameters.any { param -> param.name == ID_MEMBER } }
.call(id, *this::class.constructors.first().parameters.drop(1).map { param ->
this::class.members.first { member -> member.name == param.name }.call(this)
}.toTypedArray())
}
this::class.constructors.first {
it.parameters.any { param -> param.name == ID_MEMBER }
}.call(id, *this::class
.constructors
.first()
.parameters
.drop(1).map { param ->
this::class
.members
.first { member -> member.name == param.name }
.call(this)
}.toTypedArray())
}
}

2 changes: 1 addition & 1 deletion springboot/api/src/main/kotlin/webapp/users/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ data class User(
}


suspend fun Pair<User, ApplicationContext>.findOneByEmail(
suspend fun Pair<User, ApplicationContext>.findOneUserByEmail(
email: String
): Either<Throwable, User> = try {
second.getBean<DatabaseClient>()
Expand Down
7 changes: 3 additions & 4 deletions springboot/api/src/test/kotlin/webapp/users/UserTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import webapp.TestUtils.defaultRoles
import webapp.TestUtils.deleteAllUsersOnly
import webapp.core.utils.AppUtils.cleanField
import webapp.core.utils.i
import webapp.users.User.UserDao.Dao.findOneByEmail
import webapp.users.User.UserDao.Dao.findOneUserByEmail
import webapp.users.User.UserDao.Dao.save
import webapp.users.User.UserDao.Dao.toJson
import kotlin.test.*
Expand All @@ -38,7 +38,6 @@ class UserTests {
@AfterTest
fun cleanUp() = runBlocking { context.deleteAllUsersOnly() }


@Test
fun `save default user should work in this context `() = runBlocking {
val count = context.countUsers()
Expand Down Expand Up @@ -90,7 +89,7 @@ class UserTests {
fun `check findOneByEmail with non-existent email`() = runBlocking {
(user to context).save()
assertEquals(1, context.countUsers())
(user to context).findOneByEmail("user@dummy.com").run {
(user to context).findOneUserByEmail("user@dummy.com").run {
when (this) {
is Left -> assertNotNull(value)

Expand All @@ -103,7 +102,7 @@ class UserTests {
fun `check findOneByEmail with existant email`() = runBlocking {
(user to context).save()
assertEquals(1, context.countUsers())
(user to context).findOneByEmail(user.email).run {
(user to context).findOneUserByEmail(user.email).run {
when (this) {
is Left -> assertEquals(value::class.java, NullPointerException::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import webapp.TestUtils.countUsers
import webapp.TestUtils.deleteAllUsersOnly
import webapp.core.utils.i
import webapp.users.User
import webapp.users.User.UserDao.Dao.findOneByEmail
import webapp.users.User.UserDao.Dao.findOneUserByEmail
import webapp.users.User.UserRestApis.API_SIGNUP_PATH
import kotlin.test.*

Expand Down Expand Up @@ -112,7 +112,7 @@ class SignupIntegrationTests {
assertEquals(countUserBefore, context.countUsers())
// assertEquals(countUserBefore + 1, context.countUsers())
// assertEquals(countUserAuthBefore + 1, context.countUserAuthority())
(user to context).findOneByEmail(user.email).run {
(user to context).findOneUserByEmail(user.email).run {
when (this) {
is Left -> assertEquals(EmptyResultDataAccessException::class.java, value::class.java)
is Right -> {
Expand Down Expand Up @@ -145,7 +145,7 @@ class SignupIntegrationTests {
assertEquals(countUserBefore, context.countUsers())
assertEquals(countUserBefore + 1, context.countUsers())
assertEquals(countUserAuthBefore + 1, context.countUserAuthority())
(user to context).findOneByEmail(user.email).run {
(user to context).findOneUserByEmail(user.email).run {
when (this) {
is Left -> assertEquals(value::class.java, NullPointerException::class.java)
is Right -> {
Expand Down

0 comments on commit 40aaa03

Please sign in to comment.