aboutsummaryrefslogtreecommitdiff
path: root/test/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'test/tasks')
-rw-r--r--test/tasks/frontend_test.exs108
-rw-r--r--test/tasks/instance_test.exs18
2 files changed, 123 insertions, 3 deletions
diff --git a/test/tasks/frontend_test.exs b/test/tasks/frontend_test.exs
new file mode 100644
index 000000000..ba6bf7c40
--- /dev/null
+++ b/test/tasks/frontend_test.exs
@@ -0,0 +1,108 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.FrontendTest do
+ use ExUnit.Case
+ use Pleroma.Tests.Helpers
+
+ import Tesla.Mock, only: [mock_global: 1, json: 1]
+
+ @bundle_zip_path Path.absname("test/fixtures/tesla_mock/fe-bundle.zip")
+
+ @tmp "test/tmp"
+ @dir "#{@tmp}/instance_static"
+
+ setup_all do
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+
+ :ok
+ end
+
+ setup do
+ mock_global(fn
+ %{method: :get, url: "https://git.pleroma.social/api/v4/projects/" <> rest} ->
+ if String.ends_with?(rest, "repository/branches") do
+ "test/fixtures/tesla_mock/gitlab-api-pleroma-fe-branches.json"
+ else
+ "test/fixtures/tesla_mock/gitlab-api-pleroma-fe-releases.json"
+ end
+ |> Path.absname()
+ |> File.read!()
+ |> Jason.decode!()
+ |> json()
+
+ %{method: :get, url: _download_url} ->
+ %Tesla.Env{status: 200, body: File.read!(@bundle_zip_path)}
+ end)
+
+ File.mkdir_p!(@dir)
+ on_exit(fn -> File.rm_rf(@dir) end)
+
+ clear_config([:instance, :static_dir], @dir)
+
+ :ok
+ end
+
+ describe "Installations from local path" do
+ test "Frontends with standard dist structure" do
+ ~w(pleroma kenoma admin)
+ |> Enum.each(fn frontend ->
+ path = "test/fixtures/frontends/#{frontend}"
+ Mix.Tasks.Pleroma.Frontend.run(~w(install #{frontend} --path #{path}))
+
+ assert File.exists?("#{@dir}/frontends/#{frontend}/42/index.html")
+ refute File.exists?("#{@dir}/frontends/#{frontend}/42/package.json")
+ end)
+ end
+
+ test "Mastodon" do
+ path = "test/fixtures/frontends/mastodon"
+ Mix.Tasks.Pleroma.Frontend.run(~w(install mastodon --path #{path}))
+
+ assert File.exists?("#{@dir}/frontends/mastodon/__local__/sw.js")
+ assert File.exists?("#{@dir}/frontends/mastodon/__local__/packs/locales.js")
+ refute File.exists?("#{@dir}/frontends/mastodon/__local__/unused_file")
+ refute File.exists?("#{@dir}/frontends/mastodon/__local__/unused_dir")
+ end
+ end
+
+ describe "Installation from web source" do
+ test "develop" do
+ if Pleroma.Utils.command_available?("yarn") do
+ Mix.Tasks.Pleroma.Frontend.run([
+ "install",
+ "pleroma",
+ "--develop"
+ ])
+
+ assert File.exists?(Path.join([@dir, "frontends/pleroma/d5457c32/index.html"]))
+ end
+ end
+
+ test "stable" do
+ if Pleroma.Utils.command_available?("yarn") do
+ Mix.Tasks.Pleroma.Frontend.run(["install", "pleroma"])
+
+ assert File.exists?(Path.join([@dir, "frontends/pleroma/5d49edc8/index.html"]))
+ end
+ end
+
+ test "ref" do
+ if Pleroma.Utils.command_available?("yarn") do
+ Mix.Tasks.Pleroma.Frontend.run([
+ "install",
+ "pleroma",
+ "--ref",
+ "1.2.3"
+ ])
+
+ assert File.exists?(Path.join([@dir, "frontends/pleroma/1.2.3/index.html"]))
+ end
+ end
+ end
+end
diff --git a/test/tasks/instance_test.exs b/test/tasks/instance_test.exs
index 3b4c041d9..cad31c0da 100644
--- a/test/tasks/instance_test.exs
+++ b/test/tasks/instance_test.exs
@@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.InstanceTest do
+defmodule Mix.Tasks.Pleroma.InstanceTest do
use ExUnit.Case
setup do
@@ -63,7 +63,15 @@ defmodule Pleroma.InstanceTest do
"--uploads-dir",
"test/uploads",
"--static-dir",
- "./test/../test/instance/static/"
+ "./test/../test/instance_static/",
+ "--fe-primary",
+ "pleroma",
+ "--fe-mastodon",
+ "y",
+ "--fe-admin",
+ "y",
+ "--fe-static",
+ "y"
])
end
@@ -82,8 +90,12 @@ defmodule Pleroma.InstanceTest do
assert generated_config =~ "password: \"dbpass\""
assert generated_config =~ "configurable_from_database: true"
assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
+ assert generated_config =~ ~s(primary: %{"name" => "pleroma", "ref" => "42"})
+ assert generated_config =~ ~s(mastodon: %{"name" => "mastodon", "ref" => "42"})
+ assert generated_config =~ ~s(admin: %{"name" => "admin", "ref" => "42"})
+ assert generated_config =~ "static: true"
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
- assert File.exists?(Path.expand("./test/instance/static/robots.txt"))
+ assert File.exists?(Path.expand("./test/instance_static/robots.txt"))
end
defp generated_setup_psql do