package de.tsschulz.timeclock.data.offline

import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json
import org.junit.Assert.assertEquals
import org.junit.Test

class PendingClockActionTest {
    private val json = Json { ignoreUnknownKeys = true }

    @Test
    fun pendingClockActionsRoundTrip() {
        val actions = listOf(
            PendingClockAction(id = "1", action = "start work", createdAtEpochMillis = 1_777_000_000_000),
            PendingClockAction(id = "2", action = "stop work", createdAtEpochMillis = 1_777_000_300_000),
        )

        val raw = json.encodeToString(ListSerializer(PendingClockAction.serializer()), actions)
        val decoded = json.decodeFromString(ListSerializer(PendingClockAction.serializer()), raw)

        assertEquals(actions, decoded)
        assertEquals("start work", decoded.first().action)
        assertEquals("stop work", decoded.last().action)
    }
}
