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 40aaa03 commit a5adea8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
6 changes: 3 additions & 3 deletions springboot/api/src/main/kotlin/webapp/users/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ data class User(
}


suspend fun Pair<User, ApplicationContext>.findOneUserByEmail(
suspend fun ApplicationContext.findOneUserByEmail(
email: String
): Either<Throwable, User> = try {
second.getBean<DatabaseClient>()
.sql("SELECT * FROM `user` WHERE LOWER(email) = LOWER(:email)")
getBean<DatabaseClient>()
.sql("select * from `user` u where lower(u.email) = lower(:email)")
.bind("email", email)
.fetch()
.awaitOne()
Expand Down
44 changes: 30 additions & 14 deletions springboot/api/src/test/kotlin/webapp/users/UserTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.getBean
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.ApplicationContext
import org.springframework.dao.EmptyResultDataAccessException
import org.springframework.test.context.ActiveProfiles
import webapp.TestUtils.Data.user
import webapp.TestUtils.countRoles
Expand Down Expand Up @@ -87,27 +88,42 @@ class UserTests {

@Test
fun `check findOneByEmail with non-existent email`() = runBlocking {
assertEquals(0, context.countUsers())
(user to context).save()
assertEquals(1, context.countUsers())
(user to context).findOneUserByEmail("user@dummy.com").run {
when (this) {
is Left -> assertNotNull(value)

is Right -> assertNull(value)
context
.findOneUserByEmail("user@dummy.com")
.mapLeft { assertTrue(it is EmptyResultDataAccessException) }
.run {
assertFalse(isRight())
assertTrue(isLeft())
}
}

}


@Test
fun `check findOneByEmail with existant email`() = runBlocking {
"USEEEEEEEEEER : $user".let(::i)
assertEquals(0, context.countUsers())
(user to context).save()
assertEquals(1, context.countUsers())
(user to context).findOneUserByEmail(user.email).run {
when (this) {
is Left -> assertEquals(value::class.java, NullPointerException::class.java)

is Right -> assertEquals(user, value)
}
}
// assertEquals(1, context.countUsers())
// context
// .findOneUserByEmail(user.email)
// .apply { "0RIIIIIIIIGHT : ${isRight()}".let(::i) }
// .map {
// assertEquals(it, user)
// assertTrue(it is User)
//// "USEEEEEEEEEER : $user".let(::i)
// }
// .mapLeft {
// "PRINT LEEEEEEEEEFT : $it".let(::i)
// it is NullPointerException
// }.run {
// "LEEEEEEEEEFT : ${isLeft()}".let(::i)
// "RIIIIIIIIGHT : ${isRight()}".let(::i)
//// assertTrue(this.isRight())
//// assertFalse(isLeft())
// }
}
}
Original file line number Diff line number Diff line change
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).findOneUserByEmail(user.email).run {
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).findOneUserByEmail(user.email).run {
context.findOneUserByEmail(user.email).run {
when (this) {
is Left -> assertEquals(value::class.java, NullPointerException::class.java)
is Right -> {
Expand Down

0 comments on commit a5adea8

Please sign in to comment.