1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ExportTest do
10 alias Pleroma.Web.CommonAPI
12 test "it exports user data" do
13 user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
15 {:ok, %{object: %{data: %{"id" => id1}}} = status1} =
16 CommonAPI.post(user, %{status: "status1"})
18 {:ok, %{object: %{data: %{"id" => id2}}} = status2} =
19 CommonAPI.post(user, %{status: "status2"})
21 {:ok, %{object: %{data: %{"id" => id3}}} = status3} =
22 CommonAPI.post(user, %{status: "status3"})
24 CommonAPI.favorite(user, status1.id)
25 CommonAPI.favorite(user, status2.id)
27 Bookmark.create(user.id, status2.id)
28 Bookmark.create(user.id, status3.id)
30 assert {:ok, path} = Pleroma.Export.run(user)
31 assert {:ok, zipfile} = :zip.zip_open(String.to_charlist(path), [:memory])
32 assert {:ok, {'actor.json', json}} = :zip.zip_get('actor.json', zipfile)
36 "https://www.w3.org/ns/activitystreams",
37 "http://localhost:4001/schemas/litepub-0.1.jsonld",
38 %{"@language" => "und"}
40 "bookmarks" => "bookmarks.json",
41 "followers" => "http://cofe.io/users/cofe/followers",
42 "following" => "http://cofe.io/users/cofe/following",
43 "id" => "http://cofe.io/users/cofe",
44 "inbox" => "http://cofe.io/users/cofe/inbox",
45 "likes" => "likes.json",
47 "outbox" => "http://cofe.io/users/cofe/outbox",
48 "preferredUsername" => "cofe",
50 "id" => "http://cofe.io/users/cofe#main-key",
51 "owner" => "http://cofe.io/users/cofe"
54 "url" => "http://cofe.io/users/cofe"
55 } = Jason.decode!(json)
57 assert {:ok, {'outbox.json', json}} = :zip.zip_get('outbox.json', zipfile)
60 "@context" => "https://www.w3.org/ns/activitystreams",
61 "id" => "outbox.json",
65 "actor" => "http://cofe.io/users/cofe",
66 "content" => "status1",
73 "actor" => "http://cofe.io/users/cofe",
74 "content" => "status2"
78 "actor" => "http://cofe.io/users/cofe",
80 "content" => "status3"
85 "type" => "OrderedCollection"
86 } = Jason.decode!(json)
88 assert {:ok, {'likes.json', json}} = :zip.zip_get('likes.json', zipfile)
91 "@context" => "https://www.w3.org/ns/activitystreams",
93 "orderedItems" => [^id1, ^id2],
95 "type" => "OrderedCollection"
96 } = Jason.decode!(json)
98 assert {:ok, {'bookmarks.json', json}} = :zip.zip_get('bookmarks.json', zipfile)
101 "@context" => "https://www.w3.org/ns/activitystreams",
102 "id" => "bookmarks.json",
103 "orderedItems" => [^id2, ^id3],
105 "type" => "OrderedCollection"
106 } = Jason.decode!(json)
108 :zip.zip_close(zipfile)
112 test "it uploads an exported backup archive" do
113 user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
115 {:ok, status1} = CommonAPI.post(user, %{status: "status1"})
116 {:ok, status2} = CommonAPI.post(user, %{status: "status2"})
117 {:ok, status3} = CommonAPI.post(user, %{status: "status3"})
118 CommonAPI.favorite(user, status1.id)
119 CommonAPI.favorite(user, status2.id)
120 Bookmark.create(user.id, status2.id)
121 Bookmark.create(user.id, status3.id)
123 assert {:ok, path} = Pleroma.Export.run(user)
124 assert {:ok, %Pleroma.Upload{}} = Pleroma.Export.upload(path)