Files
correx/testing/replay/src/test/kotlin/SessionReplayTest.kt
T
kami f827685ed0 chore(damn): detekt, build, tests, formatting
fixed detekt issues where possible.
fixed disttar failing build because tools is added twice in the server module.
added workflowId where required.
fixed some tests not being recognized because of runBlocking without explicit return type.
formatting + imports.
2026-05-22 00:10:05 +04:00

58 lines
2.2 KiB
Kotlin

import com.correx.core.events.events.EventMetadata
import com.correx.core.events.events.EventPayload
import com.correx.core.events.events.NewEvent
import com.correx.core.events.events.SessionCompletedEvent
import com.correx.core.events.events.SessionPausedEvent
import com.correx.core.events.events.SessionResumedEvent
import com.correx.core.events.events.SessionStartedEvent
import com.correx.core.events.types.EventId
import com.correx.core.events.types.SessionId
import com.correx.core.sessions.DefaultSessionReducer
import com.correx.core.sessions.SessionProjector
import com.correx.core.sessions.SessionStatus
import com.correx.core.sessions.projections.replay.DefaultEventReplayer
import com.correx.infrastructure.persistence.InMemoryEventStore
import kotlinx.datetime.Clock
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class SessionReplayTest {
private val store = InMemoryEventStore()
private val projector = SessionProjector(DefaultSessionReducer())
private val replayer = DefaultEventReplayer(store, projector)
@Test
fun `rebuild session from event stream`(): Unit = kotlinx.coroutines.runBlocking {
val sessionId = SessionId("s1")
val metadataToPayload = mapOf<EventMetadata, EventPayload>(
EventMetadata(EventId("start"), sessionId, Clock.System.now(), 1, null, null) to SessionStartedEvent(
sessionId
),
EventMetadata(EventId("paused"), sessionId, Clock.System.now(), 1, null, null) to SessionPausedEvent(
sessionId
),
EventMetadata(EventId("resumed"), sessionId, Clock.System.now(), 1, null, null) to SessionResumedEvent(
sessionId
),
EventMetadata(
EventId("completed"),
sessionId,
Clock.System.now(),
1,
null,
null
) to SessionCompletedEvent(sessionId),
)
metadataToPayload.map { (meta, payload) ->
store.append(NewEvent(meta, payload))
}
val state = replayer.rebuild(sessionId)
assertEquals(SessionStatus.COMPLETED, state.status)
}
}