EndpointMockState
Represents the mocking state for a single API endpoint.
Each endpoint is either passing traffic through to the actual network or returning a specific mock response. The two variants are represented as distinct types, eliminating any ambiguous state combinations that existed in the previous boolean-flag approach.
Variants
| Variant | Behavior | displayName |
|---|---|---|
| Network | All requests pass through to the actual network (default) | "Network" |
| Mock | Requests return the mock response loaded from Mock.responseFile | Mock.responseFile without .json |
Usage Example
// Configure endpoint to use a mock response
val state = EndpointMockState.Mock(responseFile = "getUser-200.json")
// Configure endpoint to use the actual network
val state = EndpointMockState.NetworkChecking the state
when (state) {
is EndpointMockState.Network -> { /* use real network */}
is EndpointMockState.Mock -> { /* load mock from state.responseFile */}
}Response File Naming Convention
The Mock.responseFile should match one of the available response files for the endpoint, following the naming convention:
{endpointId}-{statusCode}.json{endpointId}-{statusCode}-{suffix}.json
Example files for a getUser endpoint:
getUser-200.jsongetUser-404-simple.jsongetUser-404-detailed.jsongetUser-500.json
See also
Inheritors
Types
The endpoint will return a mock response loaded from responseFile.
The endpoint will pass all requests through to the actual network.