Merge branch 'frontend-admin-api' into 'develop'
[akkoma] / test / pleroma / web / admin_api / controllers / frontend_controller_test.exs
index afe82ddf5c834a14166bd283fe6bf7c753378e60..94873f6dbc9afa4e5657eac3f04ddbdadec090eb 100644 (file)
@@ -4,13 +4,10 @@
 
 defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
   use Pleroma.Web.ConnCase
-  use Oban.Testing, repo: Pleroma.Repo
 
   import Pleroma.Factory
 
   alias Pleroma.Config
-  alias Pleroma.Tests.ObanHelpers
-  alias Pleroma.Workers.FrontendInstallerWorker
 
   @dir "test/frontend_static_test"
 
@@ -47,7 +44,7 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
     end
   end
 
-  describe "POST /api/pleroma/admin/frontends" do
+  describe "POST /api/pleroma/admin/frontends/install" do
     test "from available frontends", %{conn: conn} do
       clear_config([:frontends, :available], %{
         "pleroma" => %{
@@ -63,16 +60,9 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
 
       conn
       |> put_req_header("content-type", "application/json")
-      |> post("/api/pleroma/admin/frontends", %{name: "pleroma"})
+      |> post("/api/pleroma/admin/frontends/install", %{name: "pleroma"})
       |> json_response_and_validate_schema(:ok)
 
-      assert_enqueued(
-        worker: FrontendInstallerWorker,
-        args: %{"name" => "pleroma", "opts" => %{}}
-      )
-
-      ObanHelpers.perform(all_enqueued(worker: FrontendInstallerWorker))
-
       assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
 
       response =
@@ -102,22 +92,12 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
 
       conn
       |> put_req_header("content-type", "application/json")
-      |> post("/api/pleroma/admin/frontends", %{
+      |> post("/api/pleroma/admin/frontends/install", %{
         name: "pleroma",
         file: "test/fixtures/tesla_mock/frontend.zip"
       })
       |> json_response_and_validate_schema(:ok)
 
-      assert_enqueued(
-        worker: FrontendInstallerWorker,
-        args: %{
-          "name" => "pleroma",
-          "opts" => %{"file" => "test/fixtures/tesla_mock/frontend.zip"}
-        }
-      )
-
-      ObanHelpers.perform(all_enqueued(worker: FrontendInstallerWorker))
-
       assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
     end
 
@@ -128,7 +108,7 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
 
       conn
       |> put_req_header("content-type", "application/json")
-      |> post("/api/pleroma/admin/frontends", %{
+      |> post("/api/pleroma/admin/frontends/install", %{
         name: "unknown",
         ref: "baka",
         build_url: "http://gensokyo.2hu/madeup.zip",
@@ -136,9 +116,26 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
       })
       |> json_response_and_validate_schema(:ok)
 
-      ObanHelpers.perform(all_enqueued(worker: FrontendInstallerWorker))
-
       assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
     end
+
+    test "failing returns an error", %{conn: conn} do
+      Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
+        %Tesla.Env{status: 404, body: ""}
+      end)
+
+      result =
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/pleroma/admin/frontends/install", %{
+          name: "unknown",
+          ref: "baka",
+          build_url: "http://gensokyo.2hu/madeup.zip",
+          build_dir: ""
+        })
+        |> json_response_and_validate_schema(400)
+
+      assert result == %{"error" => "Could not download or unzip the frontend"}
+    end
   end
 end