Consolidate Environment(UrlDataJson)Extensions files in data layer (#509)

This commit is contained in:
Brian Yencho
2024-01-05 18:36:57 -06:00
committed by GitHub
parent 4d06ca8ec0
commit aa0d574a12
5 changed files with 96 additions and 108 deletions

View File

@@ -165,7 +165,7 @@ class EnvironmentRepositoryTest {
}
private const val ENVIRONMENT_EXTENSIONS_PATH =
"com.x8bit.bitwarden.data.platform.repository.util.EnvironmentExtensionsKt"
"com.x8bit.bitwarden.data.platform.repository.util.EnvironmentUrlDataJsonExtensionsKt"
private class FakeEnvironmentDiskSource : EnvironmentDiskSource {
override var preAuthEnvironmentUrlData: EnvironmentUrlDataJson? = null

View File

@@ -1,86 +0,0 @@
package com.x8bit.bitwarden.data.platform.repository.util
import com.x8bit.bitwarden.data.auth.datasource.disk.model.EnvironmentUrlDataJson
import com.x8bit.bitwarden.data.platform.repository.model.Environment
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class EnvironmentExtensionsTest {
@Test
fun `toEnvironmentUrls should correctly convert US urls to the expected type`() {
assertEquals(
Environment.Us,
EnvironmentUrlDataJson.DEFAULT_US.toEnvironmentUrls(),
)
}
@Test
fun `toEnvironmentUrls should correctly convert EU urls to the expected type`() {
assertEquals(
Environment.Eu,
EnvironmentUrlDataJson.DEFAULT_EU.toEnvironmentUrls(),
)
}
@Test
fun `toEnvironmentUrls should correctly convert custom urls to the expected type`() {
val environmentUrlData = EnvironmentUrlDataJson(
base = "base",
api = "api",
identity = "identity",
icon = "icon",
notifications = "notifications",
webVault = "webVault",
events = "events",
)
assertEquals(
Environment.SelfHosted(
environmentUrlData = environmentUrlData,
),
environmentUrlData.toEnvironmentUrls(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert US urls to the expected type`() {
assertEquals(
Environment.Us,
EnvironmentUrlDataJson.DEFAULT_US.toEnvironmentUrlsOrDefault(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert EU urls to the expected type`() {
assertEquals(
Environment.Eu,
EnvironmentUrlDataJson.DEFAULT_EU.toEnvironmentUrlsOrDefault(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert custom urls to the expected type`() {
val environmentUrlData = EnvironmentUrlDataJson(
base = "base",
api = "api",
identity = "identity",
icon = "icon",
notifications = "notifications",
webVault = "webVault",
events = "events",
)
assertEquals(
Environment.SelfHosted(
environmentUrlData = environmentUrlData,
),
environmentUrlData.toEnvironmentUrlsOrDefault(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should convert null types to US values`() {
assertEquals(
Environment.Us,
(null as EnvironmentUrlDataJson?).toEnvironmentUrlsOrDefault(),
)
}
}

View File

@@ -33,4 +33,82 @@ class EnvironmentUrlsDataJsonExtensionsTest {
environment.labelOrBaseUrlHost,
)
}
@Test
fun `toEnvironmentUrls should correctly convert US urls to the expected type`() {
assertEquals(
Environment.Us,
EnvironmentUrlDataJson.DEFAULT_US.toEnvironmentUrls(),
)
}
@Test
fun `toEnvironmentUrls should correctly convert EU urls to the expected type`() {
assertEquals(
Environment.Eu,
EnvironmentUrlDataJson.DEFAULT_EU.toEnvironmentUrls(),
)
}
@Test
fun `toEnvironmentUrls should correctly convert custom urls to the expected type`() {
val environmentUrlData = EnvironmentUrlDataJson(
base = "base",
api = "api",
identity = "identity",
icon = "icon",
notifications = "notifications",
webVault = "webVault",
events = "events",
)
assertEquals(
Environment.SelfHosted(
environmentUrlData = environmentUrlData,
),
environmentUrlData.toEnvironmentUrls(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert US urls to the expected type`() {
assertEquals(
Environment.Us,
EnvironmentUrlDataJson.DEFAULT_US.toEnvironmentUrlsOrDefault(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert EU urls to the expected type`() {
assertEquals(
Environment.Eu,
EnvironmentUrlDataJson.DEFAULT_EU.toEnvironmentUrlsOrDefault(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert custom urls to the expected type`() {
val environmentUrlData = EnvironmentUrlDataJson(
base = "base",
api = "api",
identity = "identity",
icon = "icon",
notifications = "notifications",
webVault = "webVault",
events = "events",
)
assertEquals(
Environment.SelfHosted(
environmentUrlData = environmentUrlData,
),
environmentUrlData.toEnvironmentUrlsOrDefault(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should convert null types to US values`() {
assertEquals(
Environment.Us,
(null as EnvironmentUrlDataJson?).toEnvironmentUrlsOrDefault(),
)
}
}