-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10b9780
commit 1e6668b
Showing
8 changed files
with
511 additions
and
17 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
65 changes: 65 additions & 0 deletions
65
.../src/test/kotlin/com/divinelink/core/domain/jellyseerr/GetJellyseerrDetailsUseCaseTest.kt
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,65 @@ | ||
package com.divinelink.core.domain.jellyseerr | ||
|
||
import com.divinelink.core.commons.domain.data | ||
import com.divinelink.core.datastore.PreferenceStorage | ||
import com.divinelink.core.model.jellyseerr.JellyseerrLoginMethod | ||
import com.divinelink.core.testing.MainDispatcherRule | ||
import com.divinelink.core.testing.factories.model.jellyseerr.JellyseerrAccountDetailsFactory | ||
import com.divinelink.core.testing.repository.TestJellyseerrRepository | ||
import com.divinelink.core.testing.storage.FakePreferenceStorage | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class GetJellyseerrDetailsUseCaseTest { | ||
|
||
private lateinit var preferenceStorage: PreferenceStorage | ||
|
||
private val repository = TestJellyseerrRepository() | ||
|
||
@get:Rule | ||
val mainDispatcherRule = MainDispatcherRule() | ||
private val testDispatcher = mainDispatcherRule.testDispatcher | ||
|
||
@Test | ||
fun `test get jellyseerr account details with null storage data`() = runTest { | ||
preferenceStorage = FakePreferenceStorage() | ||
|
||
repository.mockGetJellyseerrAccountDetails(JellyseerrAccountDetailsFactory.jellyseerr()) | ||
|
||
val useCase = GetJellyseerrDetailsUseCase( | ||
storage = preferenceStorage, | ||
repository = repository.mock, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
val result = useCase.invoke(Unit).first() | ||
|
||
assertThat(result.isFailure).isTrue() | ||
assertThat(result.exceptionOrNull()).isInstanceOf(Exception::class.java) | ||
} | ||
|
||
@Test | ||
fun `test get jellyseerr account details with storage data`() = runTest { | ||
preferenceStorage = FakePreferenceStorage( | ||
jellyseerrAddress = "http://localhost:8096", | ||
jellyseerrAccount = "jellyseerrAccount", | ||
jellyseerrSignInMethod = JellyseerrLoginMethod.JELLYSEERR.name, | ||
) | ||
|
||
repository.mockGetJellyseerrAccountDetails(JellyseerrAccountDetailsFactory.jellyseerr()) | ||
|
||
val useCase = GetJellyseerrDetailsUseCase( | ||
storage = preferenceStorage, | ||
repository = repository.mock, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
val result = useCase.invoke(Unit).first() | ||
|
||
assertThat(result.isSuccess).isTrue() | ||
assertThat(result.data).isEqualTo(JellyseerrAccountDetailsFactory.jellyseerr()) | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
...omain/src/test/kotlin/com/divinelink/core/domain/jellyseerr/LoginJellyseerrUseCaseTest.kt
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,153 @@ | ||
package com.divinelink.core.domain.jellyseerr | ||
|
||
import com.divinelink.core.datastore.PreferenceStorage | ||
import com.divinelink.core.model.Password | ||
import com.divinelink.core.model.Username | ||
import com.divinelink.core.model.jellyseerr.JellyseerrLoginMethod | ||
import com.divinelink.core.model.jellyseerr.JellyseerrLoginParams | ||
import com.divinelink.core.testing.MainDispatcherRule | ||
import com.divinelink.core.testing.factories.model.jellyseerr.JellyseerrAccountDetailsFactory | ||
import com.divinelink.core.testing.repository.TestJellyseerrRepository | ||
import com.divinelink.core.testing.storage.FakePreferenceStorage | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class LoginJellyseerrUseCaseTest { | ||
|
||
private lateinit var preferenceStorage: PreferenceStorage | ||
|
||
private val repository = TestJellyseerrRepository() | ||
|
||
@get:Rule | ||
val mainDispatcherRule = MainDispatcherRule() | ||
private val testDispatcher = mainDispatcherRule.testDispatcher | ||
|
||
@Test | ||
fun `test loginJellyseerr with null parameters throws exception`() = runTest { | ||
preferenceStorage = FakePreferenceStorage() | ||
|
||
val useCase = LoginJellyseerrUseCase( | ||
repository = repository.mock, | ||
storage = preferenceStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
useCase.invoke(null).collect { | ||
assertThat(it.isFailure).isTrue() | ||
assertThat(it.exceptionOrNull()).isInstanceOf(IllegalArgumentException::class.java) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test loginJellyseerr with Jellyfin login method`() = runTest { | ||
preferenceStorage = FakePreferenceStorage() | ||
|
||
repository.mockSignInWithJellyfin(Result.success(JellyseerrAccountDetailsFactory.jellyfin())) | ||
|
||
val useCase = LoginJellyseerrUseCase( | ||
repository = repository.mock, | ||
storage = preferenceStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
useCase.invoke( | ||
JellyseerrLoginParams( | ||
username = Username("jellyfinUsername"), | ||
password = Password("password"), | ||
address = "http://localhost:8096", | ||
signInMethod = JellyseerrLoginMethod.JELLYFIN, | ||
), | ||
).collect { | ||
assertThat(it.isSuccess).isTrue() | ||
assertThat(it.getOrNull()).isEqualTo(JellyseerrAccountDetailsFactory.jellyfin()) | ||
assertThat(preferenceStorage.jellyseerrAccount.first()).isEqualTo("jellyfinUsername") | ||
assertThat(preferenceStorage.jellyseerrAddress.first()).isEqualTo("http://localhost:8096") | ||
assertThat( | ||
preferenceStorage.jellyseerrSignInMethod.first(), | ||
).isEqualTo(JellyseerrLoginMethod.JELLYFIN.name) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test loginJellyseerr with Jellyseerr login method`() = runTest { | ||
preferenceStorage = FakePreferenceStorage() | ||
|
||
repository.mockSignInWithJellyseerr( | ||
Result.success(JellyseerrAccountDetailsFactory.jellyseerr()), | ||
) | ||
|
||
val useCase = LoginJellyseerrUseCase( | ||
repository = repository.mock, | ||
storage = preferenceStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
useCase.invoke( | ||
JellyseerrLoginParams( | ||
username = Username("jellyseerrUsername"), | ||
password = Password("password"), | ||
address = "http://localhost:8096", | ||
signInMethod = JellyseerrLoginMethod.JELLYSEERR, | ||
), | ||
).collect { | ||
assertThat(it.isSuccess).isTrue() | ||
assertThat(it.getOrNull()).isEqualTo(JellyseerrAccountDetailsFactory.jellyseerr()) | ||
assertThat(preferenceStorage.jellyseerrAccount.first()).isEqualTo("jellyseerrUsername") | ||
assertThat(preferenceStorage.jellyseerrAddress.first()).isEqualTo("http://localhost:8096") | ||
assertThat( | ||
preferenceStorage.jellyseerrSignInMethod.first(), | ||
).isEqualTo(JellyseerrLoginMethod.JELLYSEERR.name) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test loginJellyseerr with Jellyseerr login method and error`() = runTest { | ||
preferenceStorage = FakePreferenceStorage() | ||
|
||
repository.mockSignInWithJellyseerr(Result.failure(Exception("error"))) | ||
|
||
val useCase = LoginJellyseerrUseCase( | ||
repository = repository.mock, | ||
storage = preferenceStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
useCase.invoke( | ||
JellyseerrLoginParams( | ||
username = Username("jellyseerrUsername"), | ||
password = Password("password"), | ||
address = "http://localhost:8096", | ||
signInMethod = JellyseerrLoginMethod.JELLYSEERR, | ||
), | ||
).collect { | ||
assertThat(it.isFailure).isTrue() | ||
} | ||
} | ||
|
||
@Test | ||
fun `test loginJellyseerr with Jellyfin login method and error`() = runTest { | ||
preferenceStorage = FakePreferenceStorage() | ||
|
||
repository.mockSignInWithJellyfin(Result.failure(Exception("error"))) | ||
|
||
val useCase = LoginJellyseerrUseCase( | ||
repository = repository.mock, | ||
storage = preferenceStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
useCase.invoke( | ||
JellyseerrLoginParams( | ||
username = Username("jellyfinUsername"), | ||
password = Password("password"), | ||
address = "http://localhost:8096", | ||
signInMethod = JellyseerrLoginMethod.JELLYFIN, | ||
), | ||
).collect { | ||
assertThat(it.isFailure).isTrue() | ||
} | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
...main/src/test/kotlin/com/divinelink/core/domain/jellyseerr/LogoutJellyseerrUseCaseTest.kt
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,120 @@ | ||
package com.divinelink.core.domain.jellyseerr | ||
|
||
import com.divinelink.core.datastore.SessionStorage | ||
import com.divinelink.core.model.jellyseerr.JellyseerrLoginMethod | ||
import com.divinelink.core.testing.MainDispatcherRule | ||
import com.divinelink.core.testing.factories.storage.SessionStorageFactory | ||
import com.divinelink.core.testing.factories.storage.SessionStorageFactory.toWzd | ||
import com.divinelink.core.testing.repository.TestJellyseerrRepository | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class LogoutJellyseerrUseCaseTest { | ||
|
||
private lateinit var sessionStorage: SessionStorage | ||
|
||
private val repository = TestJellyseerrRepository() | ||
|
||
@get:Rule | ||
val mainDispatcherRule = MainDispatcherRule() | ||
private val testDispatcher = mainDispatcherRule.testDispatcher | ||
|
||
@Test | ||
fun `test logout jellyseerr with null address`() = runTest { | ||
sessionStorage = SessionStorageFactory.empty() | ||
|
||
val useCase = LogoutJellyseerrUseCase( | ||
repository = repository.mock, | ||
sessionStorage = sessionStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
val result = useCase.invoke(Unit).first() | ||
|
||
assertThat(result.isFailure).isTrue() | ||
assertThat(result.exceptionOrNull()).isInstanceOf(Exception::class.java) | ||
assertThat(result.exceptionOrNull()?.message).isEqualTo("No address found.") | ||
} | ||
|
||
@Test | ||
fun `test logout jellyseerr with success`() = runTest { | ||
sessionStorage = SessionStorageFactory.empty().toWzd { | ||
withJellyseerrAddress("http://localhost:8096") | ||
} | ||
|
||
repository.mockLogout(Result.success(Unit)) | ||
|
||
val useCase = LogoutJellyseerrUseCase( | ||
repository = repository.mock, | ||
sessionStorage = sessionStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
val result = useCase.invoke(Unit).first() | ||
|
||
assertThat(result.isSuccess).isTrue() | ||
assertThat(result.getOrNull()).isEqualTo("http://localhost:8096") | ||
} | ||
|
||
@Test | ||
fun `test logout jellyseerr with success clear jellyseerr session`() = runTest { | ||
sessionStorage = SessionStorageFactory.empty().toWzd { | ||
withJellyseerrAddress("http://localhost:8096") | ||
withJellyseerrAccount("jellyseerrAccount") | ||
withJellyseerrSignInMethod(JellyseerrLoginMethod.JELLYSEERR.name) | ||
withJellyseerrAuthCookie("jellyseerrAuthCookie") | ||
} | ||
|
||
assertThat(sessionStorage.storage.jellyseerrAddress.first()).isEqualTo("http://localhost:8096") | ||
assertThat(sessionStorage.storage.jellyseerrAccount.first()).isEqualTo("jellyseerrAccount") | ||
assertThat(sessionStorage.storage.jellyseerrSignInMethod.first()).isEqualTo( | ||
JellyseerrLoginMethod.JELLYSEERR.name, | ||
) | ||
assertThat(sessionStorage.encryptedStorage.jellyseerrAuthCookie).isEqualTo( | ||
"jellyseerrAuthCookie", | ||
) | ||
|
||
repository.mockLogout(Result.success(Unit)) | ||
|
||
val useCase = LogoutJellyseerrUseCase( | ||
repository = repository.mock, | ||
sessionStorage = sessionStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
val result = useCase.invoke(Unit).first() | ||
|
||
assertThat(result.isSuccess).isTrue() | ||
|
||
repository.verifyClearJellyseerrAccountDetails() | ||
|
||
assertThat(sessionStorage.storage.jellyseerrAddress.first()).isNull() | ||
assertThat(sessionStorage.storage.jellyseerrAccount.first()).isNull() | ||
assertThat(sessionStorage.storage.jellyseerrSignInMethod.first()).isNull() | ||
assertThat(sessionStorage.encryptedStorage.jellyseerrAuthCookie).isNull() | ||
} | ||
|
||
@Test | ||
fun `test logout jellyseerr with failure`() = runTest { | ||
sessionStorage = SessionStorageFactory.empty().toWzd { | ||
withJellyseerrAddress("http://localhost:8096") | ||
} | ||
|
||
repository.mockLogout(Result.failure(Exception("Logout failed."))) | ||
|
||
val useCase = LogoutJellyseerrUseCase( | ||
repository = repository.mock, | ||
sessionStorage = sessionStorage, | ||
dispatcher = testDispatcher, | ||
) | ||
|
||
val result = useCase.invoke(Unit).first() | ||
|
||
assertThat(result.isFailure).isTrue() | ||
assertThat(result.exceptionOrNull()).isInstanceOf(Exception::class.java) | ||
assertThat(result.exceptionOrNull()?.message).isEqualTo("Logout failed.") | ||
} | ||
} |
Oops, something went wrong.