test: fix tests using verified routes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-12-01 12:06:18 +01:00
parent 6000c41364
commit 5fcf3d5267
11 changed files with 37 additions and 48 deletions

View File

@@ -18,7 +18,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
alias Mobilizon.Service.HTTP.ActivityPub.Mock
alias Mobilizon.Web.ActivityPub.ActorView
alias Mobilizon.Web.{Endpoint, PageView}
alias Mobilizon.Web.Router.Helpers, as: Routes
use Mobilizon.Web, :verified_routes
setup_all do
Mobilizon.Config.put([:instance, :federating], true)
@@ -412,7 +412,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
test "with the relay active, it returns the relay user", %{conn: conn} do
res =
conn
|> get(activity_pub_path(conn, :relay))
|> get(url(~p"/relay"))
|> json_response(200)
assert res["id"] =~ "/relay"
@@ -422,7 +422,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
Config.put([:instance, :allow_relay], false)
conn
|> get(activity_pub_path(conn, :relay))
|> get(url(~p"/relay"))
|> json_response(404)
|> assert

View File

@@ -1,7 +1,7 @@
defmodule Mobilizon.Web.ApplicationControllerTest do
use Mobilizon.Web.ConnCase
alias Mobilizon.Service.Auth.Applications
alias Mobilizon.Web.Router.Helpers, as: Routes
use Mobilizon.Web, :verified_routes
import Mobilizon.Factory
describe "create application" do
@@ -74,7 +74,9 @@ defmodule Mobilizon.Web.ApplicationControllerTest do
conn =
get(
conn,
"/oauth/authorize?client_id=hello&redirect_uri=#{URI.encode("https://somewhere.org/callback")}"
url(
~p"/oauth/authorize?client_id=hello&redirect_uri=#{URI.encode("https://somewhere.org/callback")}"
)
)
assert redirected_to(conn) =~
@@ -85,7 +87,9 @@ defmodule Mobilizon.Web.ApplicationControllerTest do
conn =
get(
conn,
"/oauth/authorize?client_id=hello&redirect_uri=#{URI.encode("https://somewhere.org/callback&state=something&scope=everything")}"
url(
~p"/oauth/authorize?client_id=hello&scope=everything&state=something&redirect_uri=#{URI.encode("https://somewhere.org/callback")}"
)
)
assert redirected_to(conn) =~ "/oauth/autorize_approve"

View File

@@ -4,8 +4,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
import Mobilizon.Factory
alias Mobilizon.Config
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Router.Helpers, as: Routes
use Mobilizon.Web, :verified_routes
describe "/@:preferred_username/feed/atom" do
test "it returns an RSS representation of the actor's public events if the actor is publicly visible",
@@ -24,11 +23,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn =
conn
|> get(
Endpoint
|> ~p"/@#{actor.preferred_username}/feed/atom"
|> URI.decode()
)
|> get(URI.decode(~p"/@#{actor.preferred_username}/feed/atom"))
assert response(conn, 200) =~ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
assert response_content_type(conn, :xml) =~ "charset=utf-8"
@@ -62,8 +57,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn =
conn
|> get(
Endpoint
|> ~p"/@#{actor.preferred_username}/feed/atom"
~p"/@#{actor.preferred_username}/feed/atom"
|> URI.decode()
)
@@ -78,8 +72,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn
|> put_req_header("accept", "application/atom+xml")
|> get(
Endpoint
|> ~p"/@#{actor.preferred_username}/feed/atom"
~p"/@#{actor.preferred_username}/feed/atom"
|> URI.decode()
)
@@ -196,8 +189,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn =
conn
|> get(
Endpoint
|> ~p"/events/#{event1.uuid}/export/ics"
~p"/events/#{event1.uuid}/export/ics"
|> URI.decode()
)
@@ -229,7 +221,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn =
conn
|> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}", "atom"))
|> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}/atom"))
assert response(conn, 200) =~ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
assert response_content_type(conn, :xml) =~ "charset=utf-8"
@@ -263,7 +255,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn =
conn
|> put_req_header("accept", "application/atom+xml")
|> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}", "atom"))
|> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}/atom"))
assert response(conn, 200) =~ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
assert response_content_type(conn, :xml) =~ "charset=utf-8"
@@ -305,7 +297,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn =
conn
|> put_req_header("accept", "text/calendar")
|> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}", "ics"))
|> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}/ics"))
assert response(conn, 200) =~ "BEGIN:VCALENDAR"
assert response_content_type(conn, :calendar) =~ "charset=utf-8"
@@ -335,7 +327,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn =
conn
|> put_req_header("accept", "text/calendar")
|> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}", "ics"))
|> get(URI.decode(~p"/events/going/#{ShortUUID.encode!(feed_token.token)}/ics"))
assert response(conn, 200) =~ "BEGIN:VCALENDAR"
assert response_content_type(conn, :calendar) =~ "charset=utf-8"
@@ -350,8 +342,7 @@ defmodule Mobilizon.Web.FeedControllerTest do
conn =
conn
|> get(
Endpoint
|> ~p"/events/going/not_existing/ics"
~p"/events/going/not_existing/ics"
|> URI.decode()
)

View File

@@ -3,20 +3,19 @@ defmodule Mobilizon.Web.NodeInfoControllerTest do
alias Mobilizon.Config
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Router.Helpers, as: Routes
use Mobilizon.Web, :verified_routes
test "Get node info schemas", %{conn: conn} do
conn = get(conn, node_info_path(conn, :schemas))
conn = get(conn, url(~p"/.well-known/nodeinfo"))
assert json_response(conn, 200) == %{
"links" => [
%{
"href" => ~p"/.well-known/nodeinfo/2.0Ã",
"href" => url(~p"/.well-known/nodeinfo/2.0"),
"rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0"
},
%{
"href" => ~p"/.well-known/nodeinfo/2.1",
"href" => url(~p"/.well-known/nodeinfo/2.1"),
"rel" => "http://nodeinfo.diaspora.software/ns/schema/2.1"
}
]
@@ -26,7 +25,7 @@ defmodule Mobilizon.Web.NodeInfoControllerTest do
test "Get node info", %{conn: conn} do
# We clear the cache because it might have been initialized by other tests
Cachex.clear(:statistics)
conn = get(conn, node_info_path(conn, :nodeinfo, "2.1"))
conn = get(conn, url(~p"/.well-known/nodeinfo/2.1"))
resp = json_response(conn, 200)
assert resp == %{
@@ -48,7 +47,7 @@ defmodule Mobilizon.Web.NodeInfoControllerTest do
end
test "Get node info with non supported version (1.0)", %{conn: conn} do
conn = get(conn, node_info_path(conn, :nodeinfo, "1.0"))
conn = get(conn, url(~p"/.well-known/nodeinfo/1.0"))
assert json_response(conn, 404) == %{"error" => "Nodeinfo schema version not handled"}
end

View File

@@ -5,8 +5,7 @@ defmodule Mobilizon.Web.PageControllerTest do
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.ActorSuspension
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.Router.Helpers, as: Routes
use Mobilizon.Web, :verified_routes
setup do
conn = build_conn() |> put_req_header("accept", "text/html")