2020-08-07 13:10:34 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-08-07 13:10:34 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-02 07:29:36 +00:00
|
|
|
defmodule Mix.Tasks.Pleroma.FrontendTest do
|
2020-08-07 13:10:34 +00:00
|
|
|
use Pleroma.DataCase
|
|
|
|
alias Mix.Tasks.Pleroma.Frontend
|
|
|
|
|
2020-08-07 13:27:41 +00:00
|
|
|
import ExUnit.CaptureIO, only: [capture_io: 1]
|
|
|
|
|
2020-08-07 13:10:34 +00:00
|
|
|
@dir "test/frontend_static_test"
|
|
|
|
|
|
|
|
setup do
|
|
|
|
File.mkdir_p!(@dir)
|
|
|
|
clear_config([:instance, :static_dir], @dir)
|
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
File.rm_rf(@dir)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it downloads and unzips a known frontend" do
|
|
|
|
clear_config([:frontends, :available], %{
|
|
|
|
"pleroma" => %{
|
|
|
|
"ref" => "fantasy",
|
|
|
|
"name" => "pleroma",
|
2020-08-07 14:03:06 +00:00
|
|
|
"build_url" => "http://gensokyo.2hu/builds/${ref}"
|
2020-08-07 13:10:34 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
|
2020-08-07 14:03:06 +00:00
|
|
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
|
2020-08-07 13:10:34 +00:00
|
|
|
end)
|
|
|
|
|
2020-08-07 13:27:41 +00:00
|
|
|
capture_io(fn ->
|
|
|
|
Frontend.run(["install", "pleroma"])
|
|
|
|
end)
|
|
|
|
|
2020-08-07 13:10:34 +00:00
|
|
|
assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it also works given a file" do
|
|
|
|
clear_config([:frontends, :available], %{
|
|
|
|
"pleroma" => %{
|
|
|
|
"ref" => "fantasy",
|
|
|
|
"name" => "pleroma",
|
|
|
|
"build_dir" => ""
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-03 09:40:17 +00:00
|
|
|
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)
|
|
|
|
|
2020-08-07 13:27:41 +00:00
|
|
|
capture_io(fn ->
|
|
|
|
Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
|
|
|
|
end)
|
|
|
|
|
2020-09-03 09:40:17 +00:00
|
|
|
assert File.exists?(Path.join([folder, "test.txt"]))
|
|
|
|
refute File.exists?(previously_existing)
|
2020-08-07 13:10:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it downloads and unzips unknown frontends" do
|
|
|
|
Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
|
|
|
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
|
|
|
|
end)
|
|
|
|
|
2020-08-07 13:27:41 +00:00
|
|
|
capture_io(fn ->
|
|
|
|
Frontend.run([
|
|
|
|
"install",
|
|
|
|
"unknown",
|
|
|
|
"--ref",
|
|
|
|
"baka",
|
|
|
|
"--build-url",
|
|
|
|
"http://gensokyo.2hu/madeup.zip",
|
|
|
|
"--build-dir",
|
|
|
|
""
|
|
|
|
])
|
|
|
|
end)
|
2020-08-07 13:10:34 +00:00
|
|
|
|
|
|
|
assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
|
|
|
|
end
|
|
|
|
end
|