# `Electric.Client.Mock`
[🔗](https://github.com/electric-sql/electric/tree/%40core/elixir-client%400.10.2/packages/elixir-client/lib/electric/client/mock.ex#L1)

Allows for mocking stream messages.

## Usage

``` elixir
{:ok, client} = Electric.Client.Mock.new()

users = [
  %{id: 1, name: "User 1"},
  %{id: 2, name: "User 2"},
  %{id: 3, name: "User 3"}
]

ref = Electric.Client.Mock.async_response(client,
  status: 200,
  schema: %{id: %{type: "int8"}, name: %{type: "text"}},
  last_offset: Client.Offset.first(),
  shape_handle: "users-1",
  body: Electric.Client.Mock.transaction(users, operation: :insert)
)

messages = Electric.Client.stream(client, "users", live: false) |> Enum.into([])

request = Electric.Client.Mock.async_await(ref, timeout = 5_000)
```

# `change_opt`

```elixir
@type change_opt() ::
  {:value, map()}
  | {:operation, :insert | :update | :delete}
  | {:offset, Electric.Client.Offset.t()}
```

# `change_opts`

```elixir
@type change_opts() :: [change_opt()]
```

# `response_opt`

```elixir
@type response_opt() ::
  {:status, pos_integer()}
  | {:headers, %{required(String.t()) =&gt; String.t() | [String.t(), ...]}}
  | {:body, [map()]}
  | {:schema, Electric.Client.schema()}
  | {:shape_handle, Electric.Client.shape_handle()}
  | {:last_offset, Electric.Client.Offset.t()}
```

# `response_opts`

```elixir
@type response_opts() :: [response_opt()]
```

# `transaction_opt`

```elixir
@type transaction_opt() :: {:lsn, non_neg_integer()} | {:up_to_date, boolean()}
```

# `transaction_opts`

```elixir
@type transaction_opts() :: [transaction_opt() | change_opt()]
```

# `async_await`

```elixir
@spec async_await(reference(), pos_integer() | :infinity) ::
  Electric.Client.Fetch.Request.t()
```

# `async_response`

# `change`

```elixir
@spec change(change_opts()) :: map()
```

# `headers`

```elixir
@spec headers(
  shape_handle: Electric.Client.shape_handle(),
  last_offset: Electric.Client.Offset.t(),
  schema: Electric.Client.schema(),
  next_cursor: Electric.Client.cursor()
) :: %{required(String.t()) =&gt; [String.t()]}
```

# `new`

```elixir
@spec new(pid()) :: {:ok, Electric.Client.t()}
```

Create a new mock client, linked to the `parent` process, `self()` by default.

# `response`

```elixir
@spec response(Electric.Client.t(), response_opts()) ::
  {:ok, Electric.Client.Fetch.Request.t()}
@spec response(Electric.Client.t(), response_opts()) :: reference()
```

# `transaction`

```elixir
@spec transaction(values :: [map()], transaction_opts()) :: [map()]
```

Wrap the given `values` in `Client.Messages.ChangeMessage` structs at the
given `:lsn`.

By default this will append an `up-to-date` control message to the end of the
liist of changes. Pass `up_to_date: false` to disable this.

# `up_to_date`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
