package invalid.lena.rsend

import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Test

class ConfigTest {

    @Test
    fun roundTrip() {
        val c = Config(
            remote = Remote("home", 2222, "backup"),
            schedule = Schedule(enabled = true, intervalMinutes = 30, wifiOnly = false, requireCharging = true),
            folders = listOf(
                Folder("DCIM", "/storage/emulated/0/DCIM", "/b/DCIM", false, listOf(".thumbnails/")),
                Folder("W", "/w", "/b/w", true, emptyList()),
            ),
        )
        assertEquals(c, Config.fromJson(c.toJson()))
    }

    @Test
    fun defaultsForEmptyObject() {
        assertEquals(Config(), Config.fromJson(JSONObject("{}")))
    }

    @Test
    fun scheduleUsesWorkManagerMinimum() {
        val json = JSONObject("""{"schedule":{"intervalMinutes":1}}""")
        assertEquals(Schedule.MIN_INTERVAL_MINUTES, Config.fromJson(json).schedule.intervalMinutes)
    }
}
