akkoma/test/pleroma/web/pleroma_api/views/backup_view_test.exs

58 lines
1.5 KiB
Elixir
Raw Normal View History

2021-01-07 12:06:22 -07:00
# Pleroma: A lightweight social networking server
2022-02-25 23:11:42 -07:00
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2021-01-07 12:06:22 -07:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.BackupViewTest do
use Pleroma.DataCase, async: true
alias Pleroma.User.Backup
alias Pleroma.Web.PleromaAPI.BackupView
import Pleroma.Factory
test "it renders the ID" do
user = insert(:user)
backup = Backup.new(user)
result = BackupView.render("show.json", backup: backup)
assert result.id == backup.id
end
2022-12-16 12:10:48 -07:00
test "it renders the state and processed_number" do
user = insert(:user)
backup = Backup.new(user)
result = BackupView.render("show.json", backup: backup)
assert result.state == to_string(backup.state)
assert result.processed_number == backup.processed_number
end
test "it renders failed state with legacy records" do
backup = %Backup{
id: 0,
content_type: "application/zip",
file_name: "dummy",
file_size: 1,
state: :invalid,
processed: true,
processed_number: 1,
inserted_at: NaiveDateTime.utc_now()
}
result = BackupView.render("show.json", backup: backup)
assert result.state == "complete"
backup = %Backup{
id: 0,
content_type: "application/zip",
file_name: "dummy",
file_size: 1,
state: :invalid,
processed: false,
processed_number: 1,
inserted_at: NaiveDateTime.utc_now()
}
result = BackupView.render("show.json", backup: backup)
assert result.state == "failed"
end
2021-01-07 12:06:22 -07:00
end