# `MobMedia.Engine.Fake`
[🔗](https://github.com/GenericJam/mob_media/blob/0.1.0/lib/mob_media/engine/fake.ex#L1)

A device-free engine for host tests and agents.

    # config/test.exs
    config :mob_media, engine: MobMedia.Engine.Fake

It goes through the same `MobMedia` code as the platform engine (the
worker, the timeout, the temporary files), so a test sees exactly what a
phone would return for the same answer.

  * **WAV files are decoded for real**: `info` reports their duration and
    `audio_pcm` converts them with `MobMedia.PCM.convert/5`, so a test can
    feed a recording through to transcription. 16-bit PCM only. A WAV has no
    video: `frame` is `{:error, :no_video}`.
  * **Any path can be scripted** with `script/2`, which wins over the file's
    contents: give it the info, the audio and the frame it should answer
    with. That's how a test pretends a `.mp4` or `.m4a` exists.
  * Everything else is `{:error, :unsupported}`.

Results are delivered from another process, as the platform engine does.

# `script`

```elixir
@type script() :: [
  info: map() | {:error, term()},
  audio: {binary(), pos_integer(), pos_integer()} | {:error, term()},
  frame: {binary(), pos_integer(), pos_integer()} | {:error, term()},
  delay: non_neg_integer()
]
```

A scripted answer for a path; see `script/2`.

# `reset`

```elixir
@spec reset() :: :ok
```

Forget every scripted path.

# `script`

```elixir
@spec script(Path.t(), script()) :: :ok
```

Script the answers for `path` (it must still exist: `MobMedia` checks that
first).

  * `:info` — a map merged into `%{duration_ms: nil, width: nil,
    height: nil, has_audio: false, has_video: false, mime: nil}`, or
    `{:error, reason}`.
  * `:audio` — `{pcm, rate, channels}`, s16le, converted to whatever
    `MobMedia.audio_pcm/2` asks for; or `{:error, reason}`. Default
    `{:error, :no_audio}`.
  * `:frame` — `{jpeg, width, height}`, returned as is whatever the
    options; or `{:error, reason}`. Default `{:error, :no_video}`.
  * `:delay` — milliseconds before each answer (to exercise timeouts).

---

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