Make test output easier to read.
[akkoma] / test / web / ostatus / ostatus_controller_test.exs
1 defmodule Pleroma.Web.OStatus.OStatusControllerTest do
2 use Pleroma.Web.ConnCase
3 import Pleroma.Factory
4 alias Pleroma.{User, Repo}
5 alias Pleroma.Web.OStatus.ActivityRepresenter
6
7 test "decodes a salmon", %{conn: conn} do
8 user = insert(:user)
9 salmon = File.read!("test/fixtures/salmon.xml")
10 conn = conn
11 |> put_req_header("content-type", "application/atom+xml")
12 |> post("/users/#{user.nickname}/salmon", salmon)
13
14 assert response(conn, 200)
15 end
16
17 test "decodes a salmon with a changed magic key", %{conn: conn} do
18 user = insert(:user)
19 salmon = File.read!("test/fixtures/salmon.xml")
20 conn = conn
21 |> put_req_header("content-type", "application/atom+xml")
22 |> post("/users/#{user.nickname}/salmon", salmon)
23
24 assert response(conn, 200)
25
26 # Set a wrong magic-key for a user so it has to refetch
27 salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
28 info = salmon_user.info
29 |> Map.put("magic_key", "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB") # Wrong key
30 Repo.update(User.info_changeset(salmon_user, %{info: info}))
31
32 conn = build_conn()
33 |> put_req_header("content-type", "application/atom+xml")
34 |> post("/users/#{user.nickname}/salmon", salmon)
35
36 assert response(conn, 200)
37 end
38
39 test "gets a feed", %{conn: conn} do
40 note_activity = insert(:note_activity)
41 user = User.get_cached_by_ap_id(note_activity.data["actor"])
42
43 conn = conn
44 |> get("/users/#{user.nickname}/feed.atom")
45
46 assert response(conn, 200)
47 end
48
49 test "gets an object", %{conn: conn} do
50 note_activity = insert(:note_activity)
51 user = User.get_by_ap_id(note_activity.data["actor"])
52 [_, uuid] = hd Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"])
53 url = "/objects/#{uuid}"
54
55 conn = conn
56 |> get(url)
57
58 expected = ActivityRepresenter.to_simple_form(note_activity, user, true)
59 |> ActivityRepresenter.wrap_with_entry
60 |> :xmerl.export_simple(:xmerl_xml)
61 |> to_string
62
63 assert response(conn, 200) == expected
64 end
65
66 test "gets an activity", %{conn: conn} do
67 note_activity = insert(:note_activity)
68 [_, uuid] = hd Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])
69 url = "/activities/#{uuid}"
70
71 conn = conn
72 |> get(url)
73
74 assert response(conn, 200)
75 end
76
77 test "gets a notice", %{conn: conn} do
78 note_activity = insert(:note_activity)
79 url = "/notice/#{note_activity.id}"
80
81 conn = conn
82 |> get(url)
83
84 assert response(conn, 200)
85 end
86 end