package com.correx.testing.contracts.fixtures.projections

import com.correx.core.events.types.EventId
import com.correx.core.events.types.SessionId
import com.correx.core.sessions.projections.DefaultStateBuilder
import com.correx.core.sessions.projections.Projection
import com.correx.testing.fixtures.EventFixtures.stored
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

abstract class ProjectionContractTest<S> {

    abstract fun projection(): Projection<S>

    @Test
    fun `projection rebuild is deterministic`() {
        val events = (0 until 100).map {
            stored(EventId("e$it"), sessionId = SessionId("s1"), sequence = it.toLong())
        }

        val projection = projection()

        val builder = DefaultStateBuilder(projection)

        val state1 = builder.build(events)
        val state2 = builder.build(events)

        assertEquals(state1, state2)
    }
}