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