feat: automatically sync and update endpoints from Cloudflare R2 on every app launch

This commit is contained in:
2026-11-18 13:47:48 +05:30
parent 48dabc50a8
commit f31f049877
3 changed files with 141 additions and 0 deletions
@@ -64,4 +64,56 @@ class DeviceRepositoryTest {
assertEquals(1, remaining.size)
assertEquals("2", remaining[0].id)
}
@Test
fun updateEndpoints_whenEndpointsChange_updatesDeviceAndReturnsTrue() {
val device = DeviceConfig(
id = "dev-1",
name = "Debian Server",
node = "debian",
secretKey = "Carbon@12",
r2Url = "https://r2.example.com/config.json",
powerOnUrl = "https://old.url/on",
powerOffUrl = "https://old.url/off",
rebootUrl = "https://old.url/reboot"
)
repository.addDevice(device)
val updated = repository.updateEndpoints(
deviceId = "dev-1",
powerOnUrl = "https://new.url/on",
powerOffUrl = "https://new.url/off",
rebootUrl = "https://new.url/reboot"
)
assertTrue(updated)
val saved = repository.getDevices().first { it.id == "dev-1" }
assertEquals("https://new.url/on", saved.powerOnUrl)
assertEquals("https://new.url/off", saved.powerOffUrl)
assertEquals("https://new.url/reboot", saved.rebootUrl)
}
@Test
fun updateEndpoints_whenEndpointsIdentical_returnsFalse() {
val device = DeviceConfig(
id = "dev-1",
name = "Debian Server",
node = "debian",
secretKey = "Carbon@12",
r2Url = "https://r2.example.com/config.json",
powerOnUrl = "https://same.url/on",
powerOffUrl = "https://same.url/off",
rebootUrl = "https://same.url/reboot"
)
repository.addDevice(device)
val updated = repository.updateEndpoints(
deviceId = "dev-1",
powerOnUrl = "https://same.url/on",
powerOffUrl = "https://same.url/off",
rebootUrl = "https://same.url/reboot"
)
org.junit.Assert.assertFalse(updated)
}
}