remove `unread_conversation_count` from User
[akkoma] / test / web / activity_pub / object_validators / attachment_validator_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Web.ActivityPub.ActivityPub
9 alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
10
11 import Pleroma.Factory
12
13 describe "attachments" do
14 test "works with honkerific attachments" do
15 attachment = %{
16 "mediaType" => "",
17 "name" => "",
18 "summary" => "298p3RG7j27tfsZ9RQ.jpg",
19 "type" => "Document",
20 "url" => "https://honk.tedunangst.com/d/298p3RG7j27tfsZ9RQ.jpg"
21 }
22
23 assert {:ok, attachment} =
24 AttachmentValidator.cast_and_validate(attachment)
25 |> Ecto.Changeset.apply_action(:insert)
26
27 assert attachment.mediaType == "application/octet-stream"
28 end
29
30 test "it turns mastodon attachments into our attachments" do
31 attachment = %{
32 "url" =>
33 "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
34 "type" => "Document",
35 "name" => nil,
36 "mediaType" => "image/jpeg"
37 }
38
39 {:ok, attachment} =
40 AttachmentValidator.cast_and_validate(attachment)
41 |> Ecto.Changeset.apply_action(:insert)
42
43 assert [
44 %{
45 href:
46 "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
47 type: "Link",
48 mediaType: "image/jpeg"
49 }
50 ] = attachment.url
51
52 assert attachment.mediaType == "image/jpeg"
53 end
54
55 test "it handles our own uploads" do
56 user = insert(:user)
57
58 file = %Plug.Upload{
59 content_type: "image/jpg",
60 path: Path.absname("test/fixtures/image.jpg"),
61 filename: "an_image.jpg"
62 }
63
64 {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
65
66 {:ok, attachment} =
67 attachment.data
68 |> AttachmentValidator.cast_and_validate()
69 |> Ecto.Changeset.apply_action(:insert)
70
71 assert attachment.mediaType == "image/jpeg"
72 end
73 end
74 end