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 Pleroma.Web.PleromaAPI.BackupControllerTest do
6 use Pleroma.Web.ConnCase
8 alias Pleroma.UnstubbedConfigMock, as: ConfigMock
9 alias Pleroma.User.Backup
10 alias Pleroma.Web.PleromaAPI.BackupView
13 clear_config([Pleroma.Upload, :uploader])
14 clear_config([Backup, :limit_days])
17 |> Mox.stub_with(Pleroma.Config)
19 oauth_access(["read:backups"])
22 test "GET /api/v1/pleroma/backups", %{user: user, conn: conn} do
23 assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id}}} = Backup.create(user)
25 backup = Backup.get(backup_id)
29 |> get("/api/v1/pleroma/backups")
30 |> json_response_and_validate_schema(:ok)
34 "content_type" => "application/zip",
42 assert url == BackupView.download_url(backup)
44 Pleroma.Tests.ObanHelpers.perform_all()
53 |> get("/api/v1/pleroma/backups")
54 |> json_response_and_validate_schema(:ok)
57 test "POST /api/v1/pleroma/backups", %{user: _user, conn: conn} do
60 "content_type" => "application/zip",
68 |> post("/api/v1/pleroma/backups")
69 |> json_response_and_validate_schema(:ok)
71 Pleroma.Tests.ObanHelpers.perform_all()
80 |> get("/api/v1/pleroma/backups")
81 |> json_response_and_validate_schema(:ok)
83 days = Pleroma.Config.get([Backup, :limit_days])
85 assert %{"error" => "Last export was less than #{days} days ago"} ==
87 |> post("/api/v1/pleroma/backups")
88 |> json_response_and_validate_schema(400)
91 test "Backup without email address" do
92 user = Pleroma.Factory.insert(:user, email: nil)
93 %{conn: conn} = oauth_access(["read:backups"], user: user)
95 assert is_nil(user.email)
99 "content_type" => "application/zip",
102 "processed" => false,
107 |> post("/api/v1/pleroma/backups")
108 |> json_response_and_validate_schema(:ok)