add test for metrics controller
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Fri, 16 Dec 2022 10:56:17 +0000 (10:56 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Fri, 16 Dec 2022 10:56:17 +0000 (10:56 +0000)
test/pleroma/web/akkoma_api/metrics_controller_test.exs [new file with mode: 0644]
test/pleroma/web/o_auth/o_auth_controller_test.exs

diff --git a/test/pleroma/web/akkoma_api/metrics_controller_test.exs b/test/pleroma/web/akkoma_api/metrics_controller_test.exs
new file mode 100644 (file)
index 0000000..4b7214e
--- /dev/null
@@ -0,0 +1,24 @@
+defmodule Pleroma.Web.AkkomaAPI.MetricsControllerTest do
+  use Pleroma.Web.ConnCase, async: true
+
+  import Pleroma.Factory
+  alias Pleroma.Akkoma.FrontendSettingsProfile
+
+  describe "GET /api/v1/akkoma/metrics" do
+    test "should return metrics when the user has admin:metrics" do
+      %{conn: conn} = oauth_access(["admin:metrics"])
+      resp = conn
+      |> get("/api/v1/akkoma/metrics")
+      |> text_response(200)
+
+      assert resp =~ "# HELP"
+    end
+
+    test "should not allow users that do not have the admin:metrics scope" do
+      %{conn: conn} = oauth_access(["read:metrics"])
+      resp = conn
+      |> get("/api/v1/akkoma/metrics")
+      |> json_response(403)
+    end
+  end
+end
index 19a7dea60ef84e081806a804e7f4dd8f0d5d8c62..d3cc0acb2a39316a058804af3a12268563310644 100644 (file)
@@ -770,7 +770,6 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
       app = insert(:oauth_app)
       oauth_token = insert(:oauth_token, user: user, app: app)
       redirect_uri = OAuthController.default_redirect_uri(app)
-      IO.inspect(app)
 
       conn =
         build_conn()