-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2557 [BE] delete autotest contributors (#2596)
Co-authored-by: Elena Moshnikova <[email protected]>
- Loading branch information
Showing
15 changed files
with
381 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"count": 1 | ||
} | ||
], | ||
"errors": [], | ||
"meta": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,8 +106,7 @@ class InitialDataLoader( | |
val firstUser = createUser("Name1", "[email protected]", setOf(userRole)) | ||
val secondUser = createUser("Name2", "[email protected]", setOf(userRole, specialistRole)) | ||
val autoTestUser = createUser("autoTestUser", AUTO_TEST_USER_EMAIL, setOf(userRole)) | ||
val autoTestSpecialist = | ||
createUser("autoTestSpecialist", AUTO_TEST_SPECIALIST_EMAIL, setOf(userRole, specialistRole)) | ||
val autoTestSpecialist = createUser("autoTestSpecialist", AUTO_TEST_SPECIALIST_EMAIL, setOf(userRole, specialistRole)) | ||
val listOfUsers = listOf(admin, firstUser, secondUser, autoTestUser, autoTestSpecialist) | ||
userAccountRepository.saveAll(listOfUsers) | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
alter table user_roles | ||
drop constraint fk6teafluo1xt1re7vbgr16w8iy; | ||
|
||
alter table user_roles | ||
add constraint user_roles_to_user_account | ||
foreign key (user_id) references user_account | ||
on delete cascade; | ||
|
||
alter table study_history | ||
drop constraint fk5gkcspvt7bmyc80jv8vfbfpqt; | ||
|
||
alter table study_history | ||
add constraint study_history_to_user_account | ||
foreign key (user_id) references user_account | ||
on delete cascade; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package com.epam.brn.controller | ||
|
||
import com.epam.brn.dto.HeadphonesDto | ||
import com.epam.brn.dto.UserAccountDto | ||
import com.epam.brn.dto.request.UserAccountChangeRequest | ||
import com.epam.brn.dto.request.UserAccountCreateRequest | ||
import com.epam.brn.dto.response.BrnResponse | ||
import com.epam.brn.dto.UserAccountDto | ||
import com.epam.brn.dto.response.UserWithAnalyticsResponse | ||
import com.epam.brn.enums.BrnGender | ||
import com.epam.brn.enums.BrnRole | ||
import com.epam.brn.enums.HeadphonesType | ||
import com.epam.brn.enums.BrnGender | ||
import com.epam.brn.service.DoctorService | ||
import com.epam.brn.service.UserAccountService | ||
import com.epam.brn.service.UserAnalyticsService | ||
|
@@ -314,4 +314,35 @@ internal class UserDetailControllerTest { | |
users.statusCodeValue shouldBe HttpStatus.SC_OK | ||
(users.body as BrnResponse<*>).data shouldBe listOf(userAccountDto) | ||
} | ||
|
||
@Test | ||
fun `deleteAutoTestUsers should return count of deleted users`() { | ||
// GIVEN | ||
val usersCount = 2L | ||
every { userAccountService.deleteAutoTestUsers() } returns usersCount | ||
|
||
// WHEN | ||
val result = userDetailController.deleteAutoTestUsers() | ||
|
||
// THEN | ||
verify { userAccountService.deleteAutoTestUsers() } | ||
result.statusCodeValue shouldBe HttpStatus.SC_OK | ||
(result.body as BrnResponse<*>).data shouldBe usersCount | ||
} | ||
|
||
@Test | ||
fun `deleteAutoTestUserByEmail should return count of deleted users`() { | ||
// GIVEN | ||
val email = "[email protected]" | ||
val usersCount = 1L | ||
every { userAccountService.deleteAutoTestUserByEmail(email) } returns usersCount | ||
|
||
// WHEN | ||
val result = userDetailController.deleteAutoTestUserByEmail(email) | ||
|
||
// THEN | ||
verify { userAccountService.deleteAutoTestUserByEmail(email) } | ||
result.statusCodeValue shouldBe HttpStatus.SC_OK | ||
(result.body as BrnResponse<*>).data shouldBe usersCount | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
package com.epam.brn.integration | ||
|
||
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.enums.BrnGender | ||
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 | ||
import com.epam.brn.repo.UserAccountRepository | ||
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 | ||
|
@@ -54,6 +57,12 @@ class StudyHistoryIT : BaseIT() { | |
@Autowired | ||
lateinit var exerciseGroupRepository: ExerciseGroupRepository | ||
|
||
@Autowired | ||
lateinit var roleRepository: RoleRepository | ||
|
||
@Autowired | ||
lateinit var userAccountService: UserAccountService | ||
|
||
@AfterEach | ||
fun deleteAfterTest() { | ||
studyHistoryRepository.deleteAll() | ||
|
@@ -62,6 +71,7 @@ class StudyHistoryIT : BaseIT() { | |
seriesRepository.deleteAll() | ||
exerciseGroupRepository.deleteAll() | ||
userAccountRepository.deleteAll() | ||
roleRepository.deleteAll() | ||
} | ||
|
||
@Test | ||
|
@@ -226,6 +236,110 @@ 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 = "[email protected]", | ||
gender = BrnGender.MALE.toString(), | ||
bornYear = 2000, | ||
active = true, | ||
) | ||
user1.roleSet = mutableSetOf(roleUser) | ||
|
||
val user2 = UserAccount( | ||
fullName = "autotest_n1", | ||
email = "[email protected]", | ||
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 | ||
val count = 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(2, count) | ||
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 email = "[email protected]" | ||
|
||
val user1 = UserAccount( | ||
fullName = "autotest_n1", | ||
email = email, | ||
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 | ||
val count = userAccountService.deleteAutoTestUserByEmail(email) | ||
|
||
val result1 = user1.id?.let { | ||
studyHistoryRepository.findLastByUserAccountIdAndExercises( | ||
it, | ||
listOf(existingExerciseFirst.id!!) | ||
) | ||
} | ||
|
||
// THEN | ||
assertEquals(1, count) | ||
assertEquals(0, result1?.size) | ||
} | ||
|
||
private fun insertStudyHistory( | ||
existingUser: UserAccount, | ||
existingExercise: Exercise, | ||
|
@@ -289,4 +403,6 @@ class StudyHistoryIT : BaseIT() { | |
) | ||
) | ||
} | ||
|
||
private fun insertRole(roleName: String): Role = roleRepository.save(Role(name = roleName)) | ||
} |
Oops, something went wrong.