defmodule Medicode.TranscriptionServerTest do @moduledoc """ Tests for Medicode.TranscriptionServer """ use Medicode.DataCase import Medicode.TranscriptionsFixtures alias Medicode.Transcriptions alias Medicode.TranscriptionServer setup do sample_file = __DIR__ |> Path.join("../../medasrdemo-Paul.mp3") |> Path.expand() transcription = transcription_fixture(%{filename: sample_file}) %{transcription: transcription} end test "transcribe and tag audio", %{transcription: transcription} do spec = {TranscriptionServer, {:transcription, transcription}} {:ok, pid} = start_supervised(spec, restart: :transient) # NOTE: Monitoring the async process to ensure it completes # before asserting results. See https://elixirforum.com/t/whats-the-correct-way-to-handle-async-tasks-i-dont-care-about-in-an-exunit-test-error-postgrex-protocol-disconnected/36605/2 # for further explanation. ref = Process.monitor(pid) assert_receive({:DOWN, ^ref, :process, _object, _pid}, 5_000) transcription = Transcriptions.get_transcription!(transcription.id, true) assert 14 == Enum.count(transcription.chunks) end end