logo

pleroma

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

backup_view_test.exs (1720B)


  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.Web.PleromaAPI.BackupViewTest do
  5. use Pleroma.DataCase, async: true
  6. alias Pleroma.UnstubbedConfigMock, as: ConfigMock
  7. alias Pleroma.User.Backup
  8. alias Pleroma.Web.PleromaAPI.BackupView
  9. import Mox
  10. import Pleroma.Factory
  11. setup do
  12. ConfigMock
  13. |> stub_with(Pleroma.Test.StaticConfig)
  14. :ok
  15. end
  16. test "it renders the ID" do
  17. user = insert(:user)
  18. backup = Backup.new(user)
  19. result = BackupView.render("show.json", backup: backup)
  20. assert result.id == backup.id
  21. end
  22. test "it renders the state and processed_number" do
  23. user = insert(:user)
  24. backup = Backup.new(user)
  25. result = BackupView.render("show.json", backup: backup)
  26. assert result.state == to_string(backup.state)
  27. assert result.processed_number == backup.processed_number
  28. end
  29. test "it renders failed state with legacy records" do
  30. backup = %Backup{
  31. id: 0,
  32. content_type: "application/zip",
  33. file_name: "dummy",
  34. file_size: 1,
  35. state: :invalid,
  36. processed: true,
  37. processed_number: 1,
  38. inserted_at: NaiveDateTime.utc_now()
  39. }
  40. result = BackupView.render("show.json", backup: backup)
  41. assert result.state == "complete"
  42. backup = %Backup{
  43. id: 0,
  44. content_type: "application/zip",
  45. file_name: "dummy",
  46. file_size: 1,
  47. state: :invalid,
  48. processed: false,
  49. processed_number: 1,
  50. inserted_at: NaiveDateTime.utc_now()
  51. }
  52. result = BackupView.render("show.json", backup: backup)
  53. assert result.state == "failed"
  54. end
  55. end