1 defmodule Pleroma.Akkoma.Translators.DeepLTest do
2 use Pleroma.DataCase, async: true
4 alias Pleroma.Akkoma.Translators.DeepL
6 describe "translating with deepl" do
8 clear_config([:deepl, :api_key], "deepl_api_key")
11 test "should work with the free tier" do
12 clear_config([:deepl, :tier], :free)
15 %{method: :post, url: "https://api-free.deepl.com/v2/translate"} = env ->
16 auth_header = Enum.find(env.headers, fn {k, _v} -> k == "authorization" end)
17 assert {"authorization", "DeepL-Auth-Key deepl_api_key"} = auth_header
25 "text" => "I will crush you",
26 "detected_source_language" => "ja"
33 assert {:ok, "ja", "I will crush you"} = DeepL.translate("ギュギュ握りつぶしちゃうぞ", "en")
36 test "should work with the pro tier" do
37 clear_config([:deepl, :tier], :pro)
40 %{method: :post, url: "https://api.deepl.com/v2/translate"} = env ->
41 auth_header = Enum.find(env.headers, fn {k, _v} -> k == "authorization" end)
42 assert {"authorization", "DeepL-Auth-Key deepl_api_key"} = auth_header
50 "text" => "I will crush you",
51 "detected_source_language" => "ja"
58 assert {:ok, "ja", "I will crush you"} = DeepL.translate("ギュギュ握りつぶしちゃうぞ", "en")
61 test "should gracefully fail if the API errors" do
62 clear_config([:deepl, :tier], :free)
65 %{method: :post, url: "https://api-free.deepl.com/v2/translate"} ->
72 assert {:error, "DeepL request failed (code 403)"} = DeepL.translate("ギュギュ握りつぶしちゃうぞ", "en")