InMemoryTestTransport

A Transport that records every event in memory instead of sending it anywhere — for unit tests that need to assert "does this code fire the right event with the right properties?" without a real backend or dev.ynagai.autograph.DebugTransport's log-only, non-assertable output.

val transport = InMemoryTestTransport()
val tracker = Autograph {
transport(transport)
store = InMemorySeqStore() // don't let seq/session state leak onto disk between test runs
dispatcher = kotlinx.coroutines.Dispatchers.Unconfined // stamp synchronously in tests
}

tracker.track("Recipe Saved", target = "share_button")

transport.assertEventFired("Recipe Saved", properties = mapOf("target" to "share_button"))

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
Link copied to clipboard
data class RecordedEvent(val kind: InMemoryTestTransport.Kind, val name: String, val properties: JsonObject, val envelope: Envelope?)

One recorded call. name is the event/screen name for Kind.TRACK/Kind.SCREEN, or the user id for Kind.IDENTIFY.

Properties

Link copied to clipboard

Every event recorded so far, in the order they were delivered to this transport.

Link copied to clipboard

How many times flush was called.

Link copied to clipboard

How many times reset was called.

Link copied to clipboard

Functions

Link copied to clipboard

Asserts that a track event named name was recorded, and returns it.

Link copied to clipboard

Asserts that no track event named name was ever recorded.

Link copied to clipboard

Asserts that identify(userId, ...) was recorded, and returns it. See assertEventFired for traits/exact.

Link copied to clipboard

Asserts that both dev.ynagai.autograph.Envelope.seq (gapless, +1 within each contiguous run of events sharing a session id — a session rotation restarts it at 1, which is expected and not a gap) and dev.ynagai.autograph.Envelope.globalSeq (gapless, +1 across the whole device lifetime, independent of session) hold wherever each is non-null. Depending on AutographConfig.sequence, only one, both, or neither may be stamped (SequenceMode.None stamps neither, so nothing is checked); events with no envelope are skipped.

Link copied to clipboard

Asserts that events fired in exactly this names order (across all kinds — track/screen/identify).

Link copied to clipboard

Asserts that a screen event named name was recorded, and returns it. See assertEventFired for properties/exact.

Link copied to clipboard

Asserts every recorded event with an envelope belongs to the same session (no rotation occurred), and returns that session id.

Link copied to clipboard
fun clear()

Discards every recorded event — useful between test cases sharing one transport/tracker.

Link copied to clipboard
open override fun connect(envelopes: EnvelopeSource)
Link copied to clipboard
open override fun flush()
Link copied to clipboard
open override fun identify(userId: String, traits: JsonObject, envelope: Envelope?)
Link copied to clipboard
open override fun reset()
Link copied to clipboard
open override fun screen(name: String, properties: JsonObject, envelope: Envelope?)
Link copied to clipboard
open override fun track(name: String, properties: JsonObject, envelope: Envelope?)