Skip to content

Commit

Permalink
fix: Build
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Dec 20, 2023
1 parent b4c6345 commit 84ba57f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class SignUpService(
) {
@Transactional
fun signUp(dto: SignUpDto): JwtAuthenticationResponse? {

userAccountService.findActive(dto.email)?.let {
throw BadRequestException(Message.USERNAME_ALREADY_EXISTS)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ class UserAccountService(
return userAccount
}

@CacheEvict(cacheNames = [Caches.USER_ACCOUNTS], key = "#result.id")
fun createUser(userAccount: UserAccount, rawPassword: String): UserAccount {
userAccountRepository.saveAndFlush(userAccount)
userAccount.password = passwordEncoder.encode(rawPassword)
applicationEventPublisher.publishEvent(OnUserCreated(this, userAccount))
applicationEventPublisher.publishEvent(OnUserCountChanged(this))
return userAccount
}

@CacheEvict(Caches.USER_ACCOUNTS, key = "#id")
@Transactional
fun delete(id: Long) {
Expand Down
28 changes: 15 additions & 13 deletions ee/backend/tests/src/test/kotlin/io/tolgee/ee/UsageReportingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package io.tolgee.ee
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.tolgee.AbstractSpringTest
import io.tolgee.constants.Feature
import io.tolgee.dtos.request.auth.SignUpDto
import io.tolgee.ee.data.SubscriptionStatus
import io.tolgee.ee.model.EeSubscription
import io.tolgee.ee.repository.EeSubscriptionRepository
import io.tolgee.model.UserAccount
import io.tolgee.service.security.SignUpService
import io.tolgee.testing.assert
import org.junit.jupiter.api.Test
import org.mockito.kotlin.KArgumentCaptor
Expand Down Expand Up @@ -34,6 +35,9 @@ class UsageReportingTest : AbstractSpringTest() {
@Autowired
private lateinit var eeLicenseMockRequestUtil: EeLicensingMockRequestUtil

@Autowired
private lateinit var signUpService: SignUpService

@Test
fun `it checks for subscription changes`() {
eeSubscriptionRepository.save(
Expand All @@ -59,21 +63,19 @@ class UsageReportingTest : AbstractSpringTest() {

verify {
val user1 = userAccountService.createUser(
SignUpDto(
"Test",
email = "aa@a.a",
organizationName = "Ho",
password = "12345678"
)
UserAccount(
name = "Test",
username = "aa@a.a",
),
rawPassword = "12345678"
)
captor.assertSeats(1)
val user2 = userAccountService.createUser(
SignUpDto(
"Test",
email = "ab@a.a",
organizationName = "Ho",
password = "12345678"
)
UserAccount(
name = "Test",
username = "ab@a.a",
),
rawPassword = "12345678"
)
captor.assertSeats(2)
userAccountService.delete(user1.id)
Expand Down

0 comments on commit 84ba57f

Please sign in to comment.