test: remove references to deleted userApiToken and deviceId fields

This commit is contained in:
Hossain Khan
2026-02-05 19:59:08 -05:00
parent b0958b8564
commit 5bf17d8e66
2 changed files with 5 additions and 125 deletions
@@ -626,100 +626,4 @@ class TrmnlDeviceConfigDataStoreTest {
val preferences = deviceConfigDataStore.deviceModelPreferencesFlow.first()
assertThat(preferences).isEmpty()
}
@Test
fun `saveDeviceId and getDeviceId work correctly`() =
runTest {
// Arrange
val expectedDeviceId = 12345
// Act
deviceConfigDataStore.saveDeviceId(expectedDeviceId)
val retrievedDeviceId = deviceConfigDataStore.getDeviceId()
// Assert
assertThat(retrievedDeviceId).isEqualTo(expectedDeviceId)
}
@Test
fun `getDeviceId returns null when not saved`() =
runTest {
// Act
val deviceId = deviceConfigDataStore.getDeviceId()
// Assert
assertThat(deviceId).isNull()
}
@Test
fun `saveDeviceConfig persists deviceId to both JSON and legacy storage`() =
runTest {
// Arrange
val configWithDeviceId =
TrmnlDeviceConfig(
type = TrmnlDeviceType.BYOD,
apiAccessToken = "test-token",
apiBaseUrl = "https://trmnl.com",
userApiToken = "user_test_token",
deviceId = 999,
)
// Act
deviceConfigDataStore.saveDeviceConfig(configWithDeviceId)
// Assert - Verify device ID is persisted via getDeviceId (legacy storage)
val deviceId = deviceConfigDataStore.getDeviceId()
assertThat(deviceId).isEqualTo(999)
// Assert - Verify device ID is persisted via deviceConfigFlow (JSON storage)
val loadedConfig = deviceConfigDataStore.deviceConfigFlow.first()
assertThat(loadedConfig).isNotNull()
assertThat(loadedConfig?.deviceId).isEqualTo(999)
}
@Test
fun `deviceConfigFlow loads deviceId from legacy storage when JSON not present`() =
runTest {
// Arrange - Save individual fields (legacy approach) without JSON
deviceConfigDataStore.saveDeviceType(TrmnlDeviceType.BYOD)
deviceConfigDataStore.saveAccessToken("test-token")
deviceConfigDataStore.saveServerUrl("https://trmnl.com")
deviceConfigDataStore.saveDeviceId(777)
// Act
val loadedConfig = deviceConfigDataStore.deviceConfigFlow.first()
// Assert
assertThat(loadedConfig).isNotNull()
assertThat(loadedConfig?.deviceId).isEqualTo(777)
assertThat(loadedConfig?.type).isEqualTo(TrmnlDeviceType.BYOD)
}
@Test
fun `saveDeviceConfig removes deviceId from storage when null`() =
runTest {
// Arrange - First save config with deviceId
val configWithDeviceId =
TrmnlDeviceConfig(
type = TrmnlDeviceType.BYOD,
apiAccessToken = "test-token",
apiBaseUrl = "https://trmnl.com",
deviceId = 123,
)
deviceConfigDataStore.saveDeviceConfig(configWithDeviceId)
// Verify it was saved
assertThat(deviceConfigDataStore.getDeviceId()).isEqualTo(123)
// Act - Now save config without deviceId
val configWithoutDeviceId = configWithDeviceId.copy(deviceId = null)
deviceConfigDataStore.saveDeviceConfig(configWithoutDeviceId)
// Assert - DeviceId should be removed
val deviceId = deviceConfigDataStore.getDeviceId()
assertThat(deviceId).isNull()
val loadedConfig = deviceConfigDataStore.deviceConfigFlow.first()
assertThat(loadedConfig?.deviceId).isNull()
}
}
@@ -608,11 +608,7 @@ class TrmnlDisplayRepositoryTest {
fun `reportDeviceBatteryStatus should report battery for valid BYOD config`() =
runTest {
// Arrange
val byodConfigWithDeviceId =
byodDeviceConfig.copy(
deviceId = 123,
userApiToken = "user_test_token",
)
val byodConfigWithDeviceId = byodDeviceConfig
every { androidDeviceInfoProvider.getBatteryLevel() } returns 75
@@ -645,11 +641,7 @@ class TrmnlDisplayRepositoryTest {
fun `reportDeviceBatteryStatus should skip for non-BYOD device`() =
runTest {
// Arrange - TRMNL device (not BYOD)
val trmnlConfig =
testDeviceConfig.copy(
deviceId = 123,
userApiToken = "user_test_token",
)
val trmnlConfig = testDeviceConfig
// Act
repository.reportDeviceBatteryStatus(trmnlConfig)
@@ -665,11 +657,7 @@ class TrmnlDisplayRepositoryTest {
fun `reportDeviceBatteryStatus should skip when deviceId is null`() =
runTest {
// Arrange
val configWithoutDeviceId =
byodDeviceConfig.copy(
deviceId = null,
userApiToken = "user_test_token",
)
val configWithoutDeviceId = byodDeviceConfig
// Act
repository.reportDeviceBatteryStatus(configWithoutDeviceId)
@@ -685,11 +673,7 @@ class TrmnlDisplayRepositoryTest {
fun `reportDeviceBatteryStatus should skip when userApiToken is null`() =
runTest {
// Arrange
val configWithoutUserToken =
byodDeviceConfig.copy(
deviceId = 123,
userApiToken = null,
)
val configWithoutUserToken = byodDeviceConfig
// Act
repository.reportDeviceBatteryStatus(configWithoutUserToken)
@@ -705,11 +689,7 @@ class TrmnlDisplayRepositoryTest {
fun `reportDeviceBatteryStatus should skip when battery level unavailable`() =
runTest {
// Arrange
val byodConfigWithDeviceId =
byodDeviceConfig.copy(
deviceId = 123,
userApiToken = "user_test_token",
)
val byodConfigWithDeviceId = byodDeviceConfig
every { androidDeviceInfoProvider.getBatteryLevel() } returns null
@@ -729,8 +709,6 @@ class TrmnlDisplayRepositoryTest {
// Arrange
val byodConfig =
byodDeviceConfig.copy(
deviceId = null,
userApiToken = "test_token",
apiAccessToken = "test_api_key",
)
val expectedRssi = -65
@@ -773,8 +751,6 @@ class TrmnlDisplayRepositoryTest {
// Arrange
val byodConfig =
byodDeviceConfig.copy(
deviceId = null,
userApiToken = "test_token",
apiAccessToken = "test_api_key",
)
val expectedBattery = 80