Skip to content

Commit

Permalink
fix: unit test of groupService
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiinaKin committed Dec 2, 2024
1 parent 87d1e62 commit 04313ca
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/src/test/kotlin/io/sakurasou/service/group/GroupServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.sakurasou.model.DatabaseSingleton
import io.sakurasou.model.dao.group.GroupDao
import io.sakurasou.model.dao.relation.RelationDao
import io.sakurasou.model.dao.strategy.StrategyDao
import io.sakurasou.model.dao.user.UserDao
import io.sakurasou.model.dto.GroupInsertDTO
import io.sakurasou.model.dto.GroupUpdateDTO
import io.sakurasou.model.entity.Group
Expand All @@ -30,6 +31,7 @@ import kotlin.test.assertFailsWith
*/
class GroupServiceTest {
private lateinit var groupDao: GroupDao
private lateinit var userDao: UserDao
private lateinit var strategyDao: StrategyDao
private lateinit var relationDao: RelationDao
private lateinit var groupService: GroupService
Expand All @@ -41,9 +43,10 @@ class GroupServiceTest {
mockkObject(DatabaseSingleton)
mockkObject(Clock.System)
groupDao = mockk()
userDao = mockk()
strategyDao = mockk()
relationDao = mockk()
groupService = GroupServiceImpl(groupDao, strategyDao, relationDao)
groupService = GroupServiceImpl(groupDao, userDao, strategyDao, relationDao)
instant = Clock.System.now()
every { Clock.System.now() } returns instant
now = instant.toLocalDateTime(TimeZone.UTC)
Expand Down Expand Up @@ -82,10 +85,23 @@ class GroupServiceTest {

@Test
fun `delete group should be successful`() = runBlocking {
val group = Group(
id = 1,
name = "Test Group",
description = "test",
strategyId = 1,
config = GroupConfig(GroupStrategyConfig()),
isSystemReserved = false,
createTime = now
)

coEvery { DatabaseSingleton.dbQuery<Int>(any()) } coAnswers {
this.arg<suspend () -> Int>(0).invoke()
}
every { groupDao.deleteGroupById(1) } returns 1
every { groupDao.findGroupById(1L) } returns group
every { userDao.doesUsersBelongToUserGroup(group.id) } returns false
every { relationDao.deleteGroupToRolesByGroupId(group.id) } just Runs
every { groupDao.deleteGroupById(group.id) } returns 1

groupService.deleteGroup(1)

Expand Down

0 comments on commit 04313ca

Please sign in to comment.