logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

set_locale_plug_test.exs (1155B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Plugs.SetLocalePlugTest do
  5. use ExUnit.Case, async: true
  6. use Plug.Test
  7. alias Pleroma.Plugs.SetLocalePlug
  8. alias Plug.Conn
  9. test "default locale is `en`" do
  10. conn =
  11. :get
  12. |> conn("/cofe")
  13. |> SetLocalePlug.call([])
  14. assert "en" == Gettext.get_locale()
  15. assert %{locale: "en"} == conn.assigns
  16. end
  17. test "use supported locale from `accept-language`" do
  18. conn =
  19. :get
  20. |> conn("/cofe")
  21. |> Conn.put_req_header(
  22. "accept-language",
  23. "ru, fr-CH, fr;q=0.9, en;q=0.8, *;q=0.5"
  24. )
  25. |> SetLocalePlug.call([])
  26. assert "ru" == Gettext.get_locale()
  27. assert %{locale: "ru"} == conn.assigns
  28. end
  29. test "use default locale if locale from `accept-language` is not supported" do
  30. conn =
  31. :get
  32. |> conn("/cofe")
  33. |> Conn.put_req_header("accept-language", "tlh")
  34. |> SetLocalePlug.call([])
  35. assert "en" == Gettext.get_locale()
  36. assert %{locale: "en"} == conn.assigns
  37. end
  38. end