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 f456ed3 commit 2460597
Showing 1 changed file with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,110 @@ class SyncAccountInfoUseCaseTest {
)
}
}

@Test
fun userNameAndInstanceTypeChanged() = 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 = "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.FIREFISH,
userName = "panta2",
)
).getOrThrow()

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

@Test
fun unchanged() = 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()
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
).getOrThrow()

}
}

0 comments on commit 2460597

Please sign in to comment.