Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2592 [BE] job for deleting autotest contributors #2602

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/kotlin/com/epam/brn/job/AutoTestUsersDeletionJob.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.epam.brn.job

import com.epam.brn.service.UserAccountService
import org.apache.logging.log4j.kotlin.logger
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

@Component
class AutoTestUsersDeletionJob(val userAccountService: UserAccountService) {
private val log = logger()

@Scheduled(cron = "@midnight")
fun deleteAutoTestUsers() {
val usersCount = userAccountService.deleteAutoTestUsers()
log.info("Deleted $usersCount autotest users")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UserAccountServiceImpl(
private val headphonesService: HeadphonesService,
private val timeService: TimeService,
) : UserAccountService {
@Value("\${users.delete.prefix}")
@Value("\${autotest.users.deletion.prefix}")
private lateinit var prefix: String

override fun findUserByEmail(email: String): UserAccountDto =
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ github.api.url.base=https://api.github.com
github.api.url.path.contributors=/repos/{OWNER}/{REPO}/contributors
github.api.url.path.users=/users/{username}

users.delete.prefix=autotest
autotest.users.deletion.prefix=autotest

# Swagger
springdoc.swagger-ui.tagsSorter=alpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import org.assertj.core.api.Assertions
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.security.test.context.support.WithMockUser
import org.springframework.test.web.servlet.ResultActions
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import java.nio.charset.StandardCharsets
Expand All @@ -49,9 +48,6 @@ class UserDetailsControllerIT : BaseIT() {
@Autowired
lateinit var roleRepository: RoleRepository

@Value("\${users.delete.prefix}")
private lateinit var prefix: String

internal val email: String = "test@test.test"
private val baseUrl = "/users"
private val currentUserBaseUrl = "$baseUrl/current"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.epam.brn.job

import com.epam.brn.repo.UserAccountRepository
import com.epam.brn.service.impl.UserAccountServiceImpl
import io.mockk.every
import io.mockk.impl.annotations.InjectMockKs
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import io.mockk.verify
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.test.util.ReflectionTestUtils

@DisplayName("AutoTestUsersDeletionJob test using MockK")
@ExtendWith(MockKExtension::class)
class AutoTestUsersDeletionJobTest {

@InjectMockKs
lateinit var autoTestUsersDeletionJob: AutoTestUsersDeletionJob

@MockK
lateinit var userAccountService: UserAccountServiceImpl

@MockK
lateinit var userAccountRepository: UserAccountRepository
@Test
fun deleteAutoTestUsers() {
// GIVEN
val prefix = "autotest"
ReflectionTestUtils.setField(userAccountService, "prefix", prefix)
every { userAccountService.deleteAutoTestUsers() } returns 2L

// WHEN
autoTestUsersDeletionJob.deleteAutoTestUsers()

// THEN
verify { userAccountService.deleteAutoTestUsers() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,6 @@ internal class UserAccountServiceTest {
@Test
fun `should throw IllegalArgumentException when email not starts from prefix`() {
// GIVEN
val usersCount = 1L
val email = "aaa@bbb.com"
val prefix = "autotest"
ReflectionTestUtils.setField(userAccountService, "prefix", prefix)
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ github.api.url.base=https://api.github.com
github.api.url.path.contributors=/repos/{OWNER}/{REPO}/contributors
github.api.url.path.users=/users/{username}

users.delete.prefix=autotest
autotest.users.deletion.prefix=autotest
Loading