logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

frontend_test.exs (2055B)


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