Skip to content

Commit

Permalink
2544 add accounts for auto tests (#2545)
Browse files Browse the repository at this point in the history
* 2544 add accounts for autotest
  • Loading branch information
ElenaSpb authored Nov 29, 2023
1 parent cb59d62 commit aa116f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
56 changes: 31 additions & 25 deletions src/main/kotlin/com/epam/brn/service/load/InitialDataLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class InitialDataLoader(
}

fun getSourceFiles(): List<String> {
var profile: String = environment.activeProfiles[0].lowercase()
val profile: String = environment.activeProfiles[0].lowercase()
val subFolder = if (profile == "dev") "dev/" else ""
return listOf(
"groups_.csv",
Expand Down Expand Up @@ -103,14 +103,27 @@ class InitialDataLoader(
val specialistRole =
roleService.save(Role(name = BrnRole.SPECIALIST))
val admin = addAdminUser(setOf(adminRole, userRole, specialistRole))
val listOfUsers = mutableListOf(admin)
listOfUsers.addAll(addDefaultUsers(userRole))
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 listOfUsers = listOf(admin, firstUser, secondUser, autoTestUser, autoTestSpecialist)
userAccountRepository.saveAll(listOfUsers)
} else {
try {
roleService.findByName(BrnRole.SPECIALIST)
} catch (e: EntityNotFoundException) {
roleService.save(Role(name = BrnRole.SPECIALIST))
}
}
try {
roleService.findByName(BrnRole.SPECIALIST)
} catch (e: EntityNotFoundException) {
roleService.save(Role(name = BrnRole.SPECIALIST))
if (userAccountRepository.findUserAccountByEmail(AUTO_TEST_USER_EMAIL).isEmpty) {
val userRole = roleService.findByName(BrnRole.USER)
val specialistRole = roleService.findByName(BrnRole.SPECIALIST)
val autoTestUser = createUser("autoTestUser", AUTO_TEST_USER_EMAIL, setOf(userRole))
val autoTestSpecialist =
createUser("autoTestSpecialist", AUTO_TEST_SPECIALIST_EMAIL, setOf(userRole, specialistRole))
userAccountRepository.saveAll(listOf(autoTestUser, autoTestSpecialist))
}
addAdminAllRoles()
audiometryLoader.loadInitialAudiometricsWithTasks()
Expand Down Expand Up @@ -185,31 +198,24 @@ class InitialDataLoader(
return userAccount
}

private fun addDefaultUsers(userRole: Role): MutableList<UserAccount> {
private fun createUser(name: String, email: String, roles: Set<Role>): UserAccount {
val password = passwordEncoder.encode("password")
val firstUser = UserAccount(
fullName = "Name1",
email = "[email protected]",
active = true,
bornYear = 1999,
gender = BrnGender.MALE.toString()
)
val secondUser = UserAccount(
fullName = "Name2",
email = "[email protected]",
val userAccount = UserAccount(
fullName = name,
email = email,
active = true,
bornYear = 1999,
gender = BrnGender.FEMALE.toString()
bornYear = 2000,
gender = BrnGender.MALE.toString(),
)
firstUser.password = password
secondUser.password = password
firstUser.roleSet.addAll(setOf(userRole))
secondUser.roleSet.addAll(setOf(userRole))
return mutableListOf(firstUser, secondUser)
userAccount.password = password
userAccount.roleSet.addAll(roles)
return userAccount
}
}

const val ADMIN_EMAIL = "[email protected]"
const val AUTO_TEST_USER_EMAIL = "[email protected]"
const val AUTO_TEST_SPECIALIST_EMAIL = "[email protected]"

const val SINGLE_SIMPLE_WORDS_FILE_NAME = "series_words_ru"
const val SINGLE_SIMPLE_WORDS_EN_FILE_NAME = "series_words_en"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CsvLoadingTestIT : BaseIT() {
// exerciseRepository.findAll() shouldHaveSize 188
// taskRepository.findAll() shouldHaveSize 188
// resourceRepository.findAll() shouldHaveSize 881
userAccountRepository.findAll() shouldHaveSize 3
userAccountRepository.findAll() shouldHaveSize 5
roleRepository.findAll() shouldHaveSize 3
}

Expand Down

0 comments on commit aa116f8

Please sign in to comment.