diff options
| author | Roman Chvanikov <chvanikoff@pm.me> | 2019-07-12 18:08:27 +0300 |
|---|---|---|
| committer | Roman Chvanikov <chvanikoff@pm.me> | 2019-07-12 18:08:27 +0300 |
| commit | eae991b06a22bf7fc3eef7a0d5b409c931c1f6cb (patch) | |
| tree | 77cd19ea54b8efa69e45b2d37876e7d5084cf38e /test/plugs | |
| parent | 371d39e160efa51f2fe608e1788f6b11b89d9839 (diff) | |
| parent | db75288b71e7531f8e5033f56fc0b9a7d1d8efb3 (diff) | |
| download | pleroma-eae991b06a22bf7fc3eef7a0d5b409c931c1f6cb.tar.gz pleroma-eae991b06a22bf7fc3eef7a0d5b409c931c1f6cb.zip | |
merge develop
Diffstat (limited to 'test/plugs')
| -rw-r--r-- | test/plugs/rate_limiter_test.exs | 4 | ||||
| -rw-r--r-- | test/plugs/set_locale_plug_test.exs | 46 |
2 files changed, 50 insertions, 0 deletions
diff --git a/test/plugs/rate_limiter_test.exs b/test/plugs/rate_limiter_test.exs index b8d6aff89..f8251b5c7 100644 --- a/test/plugs/rate_limiter_test.exs +++ b/test/plugs/rate_limiter_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.RateLimiterTest do use ExUnit.Case, async: true use Plug.Test diff --git a/test/plugs/set_locale_plug_test.exs b/test/plugs/set_locale_plug_test.exs new file mode 100644 index 000000000..b6c4c1cea --- /dev/null +++ b/test/plugs/set_locale_plug_test.exs @@ -0,0 +1,46 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Plugs.SetLocalePlugTest do + use ExUnit.Case, async: true + use Plug.Test + + alias Pleroma.Plugs.SetLocalePlug + alias Plug.Conn + + test "default locale is `en`" do + conn = + :get + |> conn("/cofe") + |> SetLocalePlug.call([]) + + assert "en" == Gettext.get_locale() + assert %{locale: "en"} == conn.assigns + end + + test "use supported locale from `accept-language`" do + conn = + :get + |> conn("/cofe") + |> Conn.put_req_header( + "accept-language", + "ru, fr-CH, fr;q=0.9, en;q=0.8, *;q=0.5" + ) + |> SetLocalePlug.call([]) + + assert "ru" == Gettext.get_locale() + assert %{locale: "ru"} == conn.assigns + end + + test "use default locale if locale from `accept-language` is not supported" do + conn = + :get + |> conn("/cofe") + |> Conn.put_req_header("accept-language", "tlh") + |> SetLocalePlug.call([]) + + assert "en" == Gettext.get_locale() + assert %{locale: "en"} == conn.assigns + end +end |
