From 1d208fae8ee15053cb3b4ebf7df13983a85122ea Mon Sep 17 00:00:00 2001 From: andrsam Date: Thu, 25 Jul 2024 16:17:09 +0300 Subject: [PATCH] 2557 [BE] delete autotest contributors --- .../kotlin/com/epam/brn/model/StudyHistory.kt | 4 +- .../epam/brn/integration/StudyHistoryIT.kt | 241 +++++++++--------- 2 files changed, 120 insertions(+), 125 deletions(-) diff --git a/src/main/kotlin/com/epam/brn/model/StudyHistory.kt b/src/main/kotlin/com/epam/brn/model/StudyHistory.kt index 47eee3a30..67a693acf 100644 --- a/src/main/kotlin/com/epam/brn/model/StudyHistory.kt +++ b/src/main/kotlin/com/epam/brn/model/StudyHistory.kt @@ -25,7 +25,7 @@ data class StudyHistory( val id: Long? = null, @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id", insertable = false, updatable = false) + @JoinColumn(name = "user_id", insertable = true, updatable = false) var userAccount: UserAccount, @ManyToOne(fetch = FetchType.LAZY) @@ -44,7 +44,7 @@ data class StudyHistory( ) { override fun toString() = - "StudyHistory(id=$id, userAccount=$userAccount, exercise=$exercise, startTime=$startTime, endTime=$endTime, spentTime=$spentTimeInSeconds, tasksCount=$tasksCount, wrongAnswers=$wrongAnswers)" + "StudyHistory(id=$id, userAccount=$userAccount, startTime=$startTime, endTime=$endTime, spentTime=$spentTimeInSeconds, tasksCount=$tasksCount, wrongAnswers=$wrongAnswers)" fun toDto() = StudyHistoryDto( id = this.id, diff --git a/src/test/kotlin/com/epam/brn/integration/StudyHistoryIT.kt b/src/test/kotlin/com/epam/brn/integration/StudyHistoryIT.kt index f535c2dce..c5a3f29cf 100644 --- a/src/test/kotlin/com/epam/brn/integration/StudyHistoryIT.kt +++ b/src/test/kotlin/com/epam/brn/integration/StudyHistoryIT.kt @@ -4,14 +4,12 @@ import com.epam.brn.enums.BrnGender import com.epam.brn.enums.BrnRole import com.epam.brn.model.Exercise import com.epam.brn.model.ExerciseGroup -import com.epam.brn.model.Role import com.epam.brn.model.Series import com.epam.brn.model.StudyHistory import com.epam.brn.model.SubGroup import com.epam.brn.model.UserAccount import com.epam.brn.repo.ExerciseGroupRepository import com.epam.brn.repo.ExerciseRepository -import com.epam.brn.repo.RoleRepository import com.epam.brn.repo.SeriesRepository import com.epam.brn.repo.StudyHistoryRepository import com.epam.brn.repo.SubGroupRepository @@ -20,7 +18,6 @@ import com.epam.brn.service.UserAccountService 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.http.MediaType import org.springframework.security.test.context.support.WithMockUser import org.springframework.test.web.servlet.request.MockMvcRequestBuilders @@ -40,9 +37,6 @@ class StudyHistoryIT : BaseIT() { private val baseUrl = "/study-history" - @Value("\${users.delete.prefix}") - private lateinit var prefix: String - @Autowired lateinit var userAccountRepository: UserAccountRepository @@ -61,8 +55,8 @@ class StudyHistoryIT : BaseIT() { @Autowired lateinit var exerciseGroupRepository: ExerciseGroupRepository - @Autowired - lateinit var roleRepository: RoleRepository +// @Autowired +// lateinit var roleRepository: RoleRepository @Autowired lateinit var userAccountService: UserAccountService @@ -75,6 +69,7 @@ class StudyHistoryIT : BaseIT() { seriesRepository.deleteAll() exerciseGroupRepository.deleteAll() userAccountRepository.deleteAll() + // roleRepository.deleteAll() } @Test @@ -239,114 +234,114 @@ class StudyHistoryIT : BaseIT() { assertEquals(0, result) } - @Test - fun `test delete study history when delete autotest users`() { - // GIVEN - val roleUser = insertRole(BrnRole.USER) - - val user1 = UserAccount( - fullName = "autotest_n1", - email = "autotest_n@1704819771.8820736.com", - gender = BrnGender.MALE.toString(), - bornYear = 2000, - active = true, - ) - user1.roleSet = mutableSetOf(roleUser) - - val user2 = UserAccount( - fullName = "autotest_n1", - email = "autotest_n@170472339.1784415.com", - gender = BrnGender.MALE.toString(), - bornYear = 2000, - active = true, - ) - user2.roleSet = mutableSetOf(roleUser) - - userAccountRepository.saveAll(listOf(user1, user2)) - - val existingSeries = insertSeries() - val subGroup = insertSubGroup(existingSeries) - val existingExerciseFirst = insertExercise("FirstName", subGroup) - val existingExerciseSecond = insertExercise("SecondName", subGroup) - val now = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS) - val historyFirstExerciseOne = insertStudyHistory(user1, existingExerciseFirst, now) - val historySecondExerciseOne = insertStudyHistory(user2, existingExerciseSecond, now) - - studyHistoryRepository - .saveAll( - listOf( - historyFirstExerciseOne, - historySecondExerciseOne, - ) - ) - - // WHEN - userAccountService.deleteAutoTestUsers() - - val result1 = user1.id?.let { - studyHistoryRepository.findLastByUserAccountIdAndExercises( - it, - listOf(existingExerciseFirst.id!!) - ) - } - - val result2 = user1.id?.let { - studyHistoryRepository.findLastByUserAccountIdAndExercises( - it, - listOf(existingExerciseFirst.id!!) - ) - } - - // THEN - assertEquals(0, result1?.size) - assertEquals(0, result2?.size) - } - - @Test - fun `test delete study history when delete single autotest user`() { - // GIVEN - val roleUser = insertRole(BrnRole.USER) - - val user1 = UserAccount( - fullName = "autotest_n1", - email = "autotest_n@1704819771.8820736.com", - gender = BrnGender.MALE.toString(), - bornYear = 2000, - active = true, - ) - user1.roleSet = mutableSetOf(roleUser) - userAccountRepository.save(user1) - - val exerciseFirstName = "FirstName" - val existingSeries = insertSeries() - val subGroup = insertSubGroup(existingSeries) - val existingExerciseFirst = insertExercise(exerciseFirstName, subGroup) - val now = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS) - val historyFirstExerciseTwo = insertStudyHistory(user1, existingExerciseFirst, now) - - studyHistoryRepository.save(historyFirstExerciseTwo) - - // WHEN - userAccountService.deleteAutoTestUsers() - - val result1 = user1.id?.let { - studyHistoryRepository.findLastByUserAccountIdAndExercises( - it, - listOf(existingExerciseFirst.id!!) - ) - } - - val result2 = user1.id?.let { - studyHistoryRepository.findLastByUserAccountIdAndExercises( - it, - listOf(existingExerciseFirst.id!!) - ) - } - - // THEN - assertEquals(0, result1?.size) - assertEquals(0, result2?.size) - } +// @Test +// fun `test delete study history when delete autotest users`() { +// // GIVEN +// val roleUser = insertRole(BrnRole.USER) +// +// val user1 = UserAccount( +// fullName = "autotest_n1", +// email = "autotest_n@1704819771.8820736.com", +// gender = BrnGender.MALE.toString(), +// bornYear = 2000, +// active = true, +// ) +// user1.roleSet = mutableSetOf(roleUser) +// +// val user2 = UserAccount( +// fullName = "autotest_n1", +// email = "autotest_n@170472339.1784415.com", +// gender = BrnGender.MALE.toString(), +// bornYear = 2000, +// active = true, +// ) +// user2.roleSet = mutableSetOf(roleUser) +// +// userAccountRepository.saveAll(listOf(user1, user2)) +// +// val existingSeries = insertSeries() +// val subGroup = insertSubGroup(existingSeries) +// val existingExerciseFirst = insertExercise("FirstName", subGroup) +// val existingExerciseSecond = insertExercise("SecondName", subGroup) +// val now = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS) +// val historyFirstExerciseOne = insertStudyHistory(user1, existingExerciseFirst, now) +// val historySecondExerciseOne = insertStudyHistory(user2, existingExerciseSecond, now) +// +// studyHistoryRepository +// .saveAll( +// listOf( +// historyFirstExerciseOne, +// historySecondExerciseOne, +// ) +// ) +// +// // WHEN +// userAccountService.deleteAutoTestUsers() +// +// val result1 = user1.id?.let { +// studyHistoryRepository.findLastByUserAccountIdAndExercises( +// it, +// listOf(existingExerciseFirst.id!!) +// ) +// } +// +// val result2 = user1.id?.let { +// studyHistoryRepository.findLastByUserAccountIdAndExercises( +// it, +// listOf(existingExerciseFirst.id!!) +// ) +// } +// +// // THEN +// assertEquals(0, result1?.size) +// assertEquals(0, result2?.size) +// } +// +// @Test +// fun `test delete study history when delete single autotest user`() { +// // GIVEN +// val roleUser = insertRole(BrnRole.USER) +// +// val user1 = UserAccount( +// fullName = "autotest_n1", +// email = "autotest_n@1704819771.8820736.com", +// gender = BrnGender.MALE.toString(), +// bornYear = 2000, +// active = true, +// ) +// user1.roleSet = mutableSetOf(roleUser) +// userAccountRepository.save(user1) +// +// val exerciseFirstName = "FirstName" +// val existingSeries = insertSeries() +// val subGroup = insertSubGroup(existingSeries) +// val existingExerciseFirst = insertExercise(exerciseFirstName, subGroup) +// val now = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS) +// val historyFirstExerciseTwo = insertStudyHistory(user1, existingExerciseFirst, now) +// +// studyHistoryRepository.save(historyFirstExerciseTwo) +// +// // WHEN +// userAccountService.deleteAutoTestUsers() +// +// val result1 = user1.id?.let { +// studyHistoryRepository.findLastByUserAccountIdAndExercises( +// it, +// listOf(existingExerciseFirst.id!!) +// ) +// } +// +// val result2 = user1.id?.let { +// studyHistoryRepository.findLastByUserAccountIdAndExercises( +// it, +// listOf(existingExerciseFirst.id!!) +// ) +// } +// +// // THEN +// assertEquals(0, result1?.size) +// assertEquals(0, result2?.size) +// } private fun insertStudyHistory( existingUser: UserAccount, @@ -412,11 +407,11 @@ class StudyHistoryIT : BaseIT() { ) } - private fun insertRole(roleName: String): Role { - return roleRepository.save( - Role( - name = roleName - ) - ) - } +// private fun insertRole(roleName: String): Role { +// return roleRepository.save( +// Role( +// name = roleName +// ) +// ) +// } }