logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

frontend_test.exs (2303B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.FrontendTest do
  5. use Pleroma.DataCase
  6. alias Mix.Tasks.Pleroma.Frontend
  7. import ExUnit.CaptureIO, only: [capture_io: 1]
  8. @dir "test/frontend_static_test"
  9. setup do
  10. File.mkdir_p!(@dir)
  11. clear_config([:instance, :static_dir], @dir)
  12. on_exit(fn ->
  13. File.rm_rf(@dir)
  14. end)
  15. end
  16. test "it downloads and unzips a known frontend" do
  17. clear_config([:frontends, :available], %{
  18. "pleroma" => %{
  19. "ref" => "fantasy",
  20. "name" => "pleroma",
  21. "build_url" => "http://gensokyo.2hu/builds/${ref}"
  22. }
  23. })
  24. Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
  25. %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
  26. end)
  27. capture_io(fn ->
  28. Frontend.run(["install", "pleroma"])
  29. end)
  30. assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
  31. end
  32. test "it also works given a file" do
  33. clear_config([:frontends, :available], %{
  34. "pleroma" => %{
  35. "ref" => "fantasy",
  36. "name" => "pleroma",
  37. "build_dir" => ""
  38. }
  39. })
  40. folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
  41. previously_existing = Path.join([folder, "temp"])
  42. File.mkdir_p!(folder)
  43. File.write!(previously_existing, "yey")
  44. assert File.exists?(previously_existing)
  45. capture_io(fn ->
  46. Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
  47. end)
  48. assert File.exists?(Path.join([folder, "test.txt"]))
  49. refute File.exists?(previously_existing)
  50. end
  51. test "it downloads and unzips unknown frontends" do
  52. Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
  53. %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
  54. end)
  55. capture_io(fn ->
  56. Frontend.run([
  57. "install",
  58. "unknown",
  59. "--ref",
  60. "baka",
  61. "--build-url",
  62. "http://gensokyo.2hu/madeup.zip",
  63. "--build-dir",
  64. ""
  65. ])
  66. end)
  67. assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
  68. end
  69. end