Skip to content

feat: stateful / sequential mocks #96

Description

@MaxMichel2

Part of #72

Depends on #78 (the DataStore key-shape migration — this issue adds a new piece of persisted state, better to land after that migration than alongside it).

Summary

Add stateful/sequential mocks: an operation can be configured to return a different response on successive calls (e.g. first call returns 202 Pending, second call returns 200 Success, further calls stay at 200 Success). This is a new capability — nothing in DevView supports it today.

Why this is useful

The most common manual-testing gap this fills: polling flows (order status, upload progress, async job completion) where the interesting behavior is the transition between states across repeated calls to the same endpoint, not any single response in isolation. Today, an operation's mock is static for the duration it's selected — there's no way to make "call it three times and watch the state progress" happen without manually flipping the selected mock between calls.

Verified: this doesn't exist anywhere today

NetworkMockState (devview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/model/NetworkMockState.kt:68-72) holds only globalMockingEnabled, endpointStates, lastModified — no counter of any kind. EndpointMockState/OperationMockState (:204-262) is a two-variant sealed interface (Network/Mock) with no sequence concept. The plugin resolves a response once per request with no per-call state (NetworkMockPlugin.kt:223-293).

What to build

  • A new OperationMockState variant, e.g. Sequence(responses: List<Mock>, currentIndex: Int) (naming/shape to be finalized against whatever ✨ Add Renovate config #3's rename settles on), alongside Network and Mock.
  • A per-operation call counter, keyed by OperationKey, incremented each time the sequence variant is matched and served. This needs a persisted or at-least-session-scoped counter — decide whether it lives in DataStore (survives app restart, consistent with how the rest of NetworkMockState persists) or in-memory only (resets on process death) and document the choice; recommend DataStore for consistency with everything else in NetworkMockState.
  • Exhaustion behavior: decide what happens once the sequence is exhausted. Recommend stick on last (matches the "third call onward stays at 200 Success" example above) over looping back to the start or falling through to the real network — stick-on-last is the least surprising default and matches how most real async-completion flows behave (the terminal state is stable, not cyclic).
  • Reset interaction: the counter must reset alongside existing mock-state resets — MockStateRepository.resetKnownEndpointsToNetwork() (devview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/repository/MockStateRepository.kt:362-369) and NetworkMockState.resetAllToNetwork() (devview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/model/NetworkMockState.kt:148-151) both need to clear any in-progress sequence position, not just revert to Network — otherwise a reset followed by re-selecting the same sequence resumes mid-sequence instead of restarting at index 0.
  • UI: a way to declare/reorder the sequence of responses for an operation in the endpoint detail screen (feat: rework the NetworkMock UI for specs and versions #79), and to see/reset the current position.

Acceptance criteria

  • An operation can be configured with an ordered sequence of responses.
  • Repeated calls to the operation advance through the sequence in order.
  • The sequence sticks on the last response once exhausted (or documents a different, deliberately chosen behavior).
  • Resetting an operation's mock state (individually or via "reset all") also resets its sequence position to 0.
  • Tests cover: advancing through a sequence, exhaustion behavior, and reset-clears-position.

Files likely touched

  • devview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/model/NetworkMockState.kt
  • devview-networkmock-core/src/commonMain/kotlin/com/worldline/devview/networkmock/core/repository/MockStateRepository.kt
  • devview-networkmock-ktor/src/commonMain/kotlin/com/worldline/devview/networkmock/ktor/plugin/NetworkMockPlugin.kt
  • devview-networkmock/src/commonMain/kotlin/com/worldline/devview/networkmock/NetworkMockEndpointScreen.kt

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions