Merge branch 'docs_add_yunohost_installation' into 'develop'
[akkoma] / test / pleroma / web / admin_api / controllers / frontend_controller_test.exs
index db28a27b6de8a891dd4e4b2bed62bf95a70b5548..200682ba92d6dde618c305b04a0aa87de3219a3a 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
@@ -42,6 +42,20 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
 
       refute Enum.any?(response, fn frontend -> frontend["installed"] == true end)
     end
+
+    test "it lists available frontends when no frontend folder was created yet", %{conn: conn} do
+      File.rm_rf(@dir)
+
+      response =
+        conn
+        |> get("/api/pleroma/admin/frontends")
+        |> json_response_and_validate_schema(:ok)
+
+      assert Enum.map(response, & &1["name"]) ==
+               Enum.map(Config.get([:frontends, :available]), fn {_, map} -> map["name"] end)
+
+      refute Enum.any?(response, fn frontend -> frontend["installed"] == true end)
+    end
   end
 
   describe "POST /api/pleroma/admin/frontends/install" do
@@ -118,5 +132,24 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
 
       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