Skip to content

Commit

Permalink
feat: テストケースを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Dec 24, 2023
1 parent 5146ee4 commit f456ed3
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 1 deletion.
4 changes: 4 additions & 0 deletions modules/model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ dependencies {
testImplementation libs.junit.jupiter.api
testRuntimeOnly libs.junit.jupiter.engine
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SyncAccountInfoUseCase @Inject constructor(
accountRepository.add(
account.copy(
instanceType = remoteSoftwareType,
userName = account.userName
userName = user.userName
), false
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package net.pantasystem.milktea.model.account

import kotlinx.coroutines.test.runTest
import net.pantasystem.milktea.model.nodeinfo.NodeInfo
import net.pantasystem.milktea.model.nodeinfo.NodeInfoRepository
import net.pantasystem.milktea.model.user.User
import net.pantasystem.milktea.model.user.make
import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.verifyBlocking

class SyncAccountInfoUseCaseTest {

@Test
fun softwareTypeChanged() = runTest {
val account = Account(
accountId = 1,
remoteId = "1",
instanceDomain = "https://misskey.io",
instanceType = Account.InstanceType.FIREFISH,
userName = "panta",
pages = emptyList(),
token = "test",
)
val accountRepository: AccountRepository = mock() {
onBlocking {
add(any(), any())
} doReturn Result.success(
account
)
}
val nodeInfoRepository: NodeInfoRepository = mock() {
onBlocking {
find(any())
} doReturn Result.success(
NodeInfo(
host = "misskey.io",
software = NodeInfo.Software(
name = "firefish",
version = "12.34.56"
),
version = "12.34.56"
)
)
}
val useCase = SyncAccountInfoUseCase(
accountRepository = accountRepository,
nodeInfoRepository = nodeInfoRepository,
userRepository = mock() {
onBlocking {
find(any(), any())
} doReturn User.Detail.make(
id = User.Id(1L, "1"),
userName = "panta",
)
}
)
useCase(
account.copy(
instanceType = Account.InstanceType.MISSKEY,
)
).getOrThrow()

verifyBlocking(accountRepository) {
add(
Account(
accountId = 1,
remoteId = "1",
instanceDomain = "https://misskey.io",
instanceType = Account.InstanceType.FIREFISH,
userName = "panta",
pages = emptyList(),
token = "test",
),
false
)
}
}

@Test
fun userNameChanged() = runTest {
val account = Account(
accountId = 1,
remoteId = "1",
instanceDomain = "https://misskey.io",
instanceType = Account.InstanceType.MISSKEY,
userName = "panta",
pages = emptyList(),
token = "test",
)
val accountRepository: AccountRepository = mock() {
onBlocking {
add(any(), any())
} doReturn Result.success(
account,
)
}
val nodeInfoRepository: NodeInfoRepository = mock() {
onBlocking {
find(any())
} doReturn Result.success(
NodeInfo(
host = "misskey.io",
software = NodeInfo.Software(
name = "misskey",
version = "12.34.56"
),
version = "12.34.56"
)
)
}
val useCase = SyncAccountInfoUseCase(
accountRepository = accountRepository,
nodeInfoRepository = nodeInfoRepository,
userRepository = mock() {
onBlocking {
find(any(), any())
} doReturn User.Detail.make(
id = User.Id(1L, "1"),
userName = "panta",
)
}
)
useCase(
account.copy(
userName = "panta2",
)
).getOrThrow()

verifyBlocking(accountRepository) {
add(
account,
false
)
}
}

@Test
fun userNameEmptyAndChanged() = runTest {
val account = Account(
accountId = 1,
remoteId = "1",
instanceDomain = "https://misskey.io",
instanceType = Account.InstanceType.MISSKEY,
userName = "",
pages = emptyList(),
token = "test",
)
val accountRepository: AccountRepository = mock() {
onBlocking {
add(any(), any())
} doReturn Result.success(
account,
)
}
val nodeInfoRepository: NodeInfoRepository = mock() {
onBlocking {
find(any())
} doReturn Result.success(
NodeInfo(
host = "misskey.io",
software = NodeInfo.Software(
name = "misskey",
version = "12.34.56"
),
version = "12.34.56"
)
)
}
val useCase = SyncAccountInfoUseCase(
accountRepository = accountRepository,
nodeInfoRepository = nodeInfoRepository,
userRepository = mock() {
onBlocking {
find(any(), any())
} doReturn User.Detail.make(
id = User.Id(1L, "1"),
userName = "panta",
)
}
)
useCase(
account.copy(
userName = "",
)
).getOrThrow()

verifyBlocking(accountRepository) {
add(
account.copy(
userName = "panta"
),
false
)
}
}
}

0 comments on commit f456ed3

Please sign in to comment.