ContentType - Multiple Types

Setup

defmodule Foo do
  use(Mazurka.Resource)

  mediatype(Hyper) do
    action() do
      %{"hello" => "World"}
    end
  end

  mediatype(HTML) do
    action() do
      {"html", nil, []}
    end
  end
end

application/json

{_, content_type, _} = Foo.action([{"application", "hyper+json", %{}}], %{}, %{}, %{})
{"application", "hyper+json", %{}} = content_type

text/html

{_, content_type, _} = Foo.action([{"text", "html", %{}}], %{}, %{}, %{})
{"text", "html", %{}} = content_type

application/*

{_, content_type, _} = Foo.action([{"application", "*", %{}}], %{}, %{}, %{})
{"application", "json", %{}} = content_type

*/html

{_, content_type, _} = Foo.action([{"*", "html", %{}}], %{}, %{}, %{})
{"text", "html", %{}} = content_type

*/*

{_, content_type, _} = Foo.action([{"*", "*", %{}}], %{}, %{}, %{})
{"application", "json", %{}} = content_type

foo/bar, application/json

{_, content_type, _} = Foo.action([{"foo", "bar", %{}}, {"application", "json", %{}}], %{}, %{}, %{})
{"application", "json", %{}} = content_type

text/plain

assert_raise(Mazurka.UnacceptableContentTypeException, fn -> Foo.action([{"text", "plain", %{}}], %{}, %{}, %{}) end)