From c38f1aefb1200169e2603834fc7116f88d30843c Mon Sep 17 00:00:00 2001 From: Walter Huf Date: Fri, 28 Jul 2023 07:35:00 -0700 Subject: [PATCH] Add unit tests for Utils.user_name_string --- test/pleroma/web/metadata/utils_test.exs | 28 +++++++++++++++++++ .../web_finger/web_finger_controller_test.exs | 2 -- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index 665efb9ca..15aa1243b 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -77,4 +77,32 @@ defmodule Pleroma.Web.Metadata.UtilsTest do assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!" end end + + describe "user_name_string/1" do + test "it uses the Endpoint by default" do + Pleroma.Web.Endpoint.config_change( + [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}], + [] + ) + + user = insert(:user) + + assert Utils.user_name_string(user) == "#{user.name} (@#{user.nickname}@sub.example.com)" + end + + test "it uses any custom WebFinger domain" do + Pleroma.Web.Endpoint.config_change( + [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}], + [] + ) + + clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com") + + clear_config([Pleroma.Web.WebFinger, :domain], "example.com") + + user = insert(:user) + + assert Utils.user_name_string(user) == "#{user.name} (@#{user.nickname}@example.com)" + end + end end diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs index f2e8e4717..47e72662c 100644 --- a/test/pleroma/web/web_finger/web_finger_controller_test.exs +++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs @@ -61,8 +61,6 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do user = insert(:user, ap_id: "https://sub.example.com/users/bobby", nickname: "bobby") - assert Utils.user_name_string(user) == "#{user.name} (@bobby@example.com)" - response = build_conn() |> put_req_header("accept", "application/jrd+json")