1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.FrontendTest do
7 alias Mix.Tasks.Pleroma.Frontend
9 import ExUnit.CaptureIO, only: [capture_io: 1]
11 @dir "test/frontend_static_test"
15 clear_config([:instance, :static_dir], @dir)
22 test "it downloads and unzips a known frontend" do
23 clear_config([:frontends, :available], %{
27 "build_url" => "http://gensokyo.2hu/builds/${ref}"
31 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
32 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
36 Frontend.run(["install", "pleroma"])
39 assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
42 test "it also works given a file" do
43 clear_config([:frontends, :available], %{
51 folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
52 previously_existing = Path.join([folder, "temp"])
54 File.write!(previously_existing, "yey")
55 assert File.exists?(previously_existing)
58 Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
61 assert File.exists?(Path.join([folder, "test.txt"]))
62 refute File.exists?(previously_existing)
65 test "it downloads and unzips unknown frontends" do
66 Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
67 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
77 "http://gensokyo.2hu/madeup.zip",
83 assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))