Merge branch 'features/validators-video' into 'develop'
[akkoma] / test / tasks / frontend_test.exs
index 5cd4594e2aea66a152fbc154d557eeb290242f03..022ae51be1a7cb8864906889b26c5b39a782417e 100644 (file)
@@ -6,6 +6,8 @@ defmodule Pleroma.FrontendTest do
   use Pleroma.DataCase
   alias Mix.Tasks.Pleroma.Frontend
 
+  import ExUnit.CaptureIO, only: [capture_io: 1]
+
   @dir "test/frontend_static_test"
 
   setup do
@@ -22,16 +24,18 @@ defmodule Pleroma.FrontendTest do
       "pleroma" => %{
         "ref" => "fantasy",
         "name" => "pleroma",
-        "build_url" => "http://gensokyo.2hu/builds/${ref}",
-        "build_dir" => ""
+        "build_url" => "http://gensokyo.2hu/builds/${ref}"
       }
     })
 
     Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
-      %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
+      %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
+    end)
+
+    capture_io(fn ->
+      Frontend.run(["install", "pleroma"])
     end)
 
-    Frontend.run(["install", "pleroma"])
     assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
   end
 
@@ -44,8 +48,18 @@ defmodule Pleroma.FrontendTest do
       }
     })
 
-    Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
-    assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
+    folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
+    previously_existing = Path.join([folder, "temp"])
+    File.mkdir_p!(folder)
+    File.write!(previously_existing, "yey")
+    assert File.exists?(previously_existing)
+
+    capture_io(fn ->
+      Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
+    end)
+
+    assert File.exists?(Path.join([folder, "test.txt"]))
+    refute File.exists?(previously_existing)
   end
 
   test "it downloads and unzips unknown frontends" do
@@ -53,16 +67,18 @@ defmodule Pleroma.FrontendTest do
       %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
     end)
 
-    Frontend.run([
-      "install",
-      "unknown",
-      "--ref",
-      "baka",
-      "--build-url",
-      "http://gensokyo.2hu/madeup.zip",
-      "--build-dir",
-      ""
-    ])
+    capture_io(fn ->
+      Frontend.run([
+        "install",
+        "unknown",
+        "--ref",
+        "baka",
+        "--build-url",
+        "http://gensokyo.2hu/madeup.zip",
+        "--build-dir",
+        ""
+      ])
+    end)
 
     assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
   end