add extra tests
Some checks failed
Some checks failed
This commit is contained in:
parent
5879862aa3
commit
373a358fec
7 changed files with 259 additions and 6 deletions
|
@ -114,14 +114,15 @@ defp in_reply_to_conversation(draft) do
|
|||
defp quote_id(%{params: %{quote_id: ""}} = draft), do: draft
|
||||
|
||||
defp quote_id(%{params: %{quote_id: id}} = draft) when is_binary(id) do
|
||||
quote = Activity.get_by_id(id)
|
||||
# only quote public/unlisted statuses
|
||||
visibility = CommonAPI.get_quoted_visibility(quote)
|
||||
|
||||
if visibility in ["public", "unlisted"] do
|
||||
with {:activity, %Activity{} = quote} <- {:activity, Activity.get_by_id(id)},
|
||||
visibility <- CommonAPI.get_quoted_visibility(quote),
|
||||
{:visibility, true} <- {:visibility, visibility in ["public", "unlisted"]} do
|
||||
%__MODULE__{draft | quote: Activity.get_by_id(id)}
|
||||
else
|
||||
add_error(draft, dgettext("errors", "You can only quote public or unlisted statuses"))
|
||||
{:activity, _} ->
|
||||
add_error(draft, dgettext("errors", "You can't quote a status that doesn't exist"))
|
||||
{:visibility, false} ->
|
||||
add_error(draft, dgettext("errors", "You can only quote public or unlisted statuses"))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
73
test/fixtures/fedibird/quote.json
vendored
Normal file
73
test/fixtures/fedibird/quote.json
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
{
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"sensitive": "as:sensitive",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"votersCount": "toot:votersCount",
|
||||
"fedibird": "http://fedibird.com/ns#",
|
||||
"quoteUri": "fedibird:quoteUri",
|
||||
"expiry": "fedibird:expiry",
|
||||
"references": {
|
||||
"@id": "fedibird:references",
|
||||
"@type": "@id"
|
||||
},
|
||||
"emojiReactions": {
|
||||
"@id": "fedibird:emojiReactions",
|
||||
"@type": "@id"
|
||||
}
|
||||
}
|
||||
],
|
||||
"id": "https://fedibird.com/users/akkoma_ap_integration_tester/statuses/108707679228362674",
|
||||
"type": "Note",
|
||||
"summary": null,
|
||||
"inReplyTo": null,
|
||||
"published": "2022-07-25T11:12:26Z",
|
||||
"url": "https://fedibird.com/@akkoma_ap_integration_tester/108707679228362674",
|
||||
"attributedTo": "https://fedibird.com/users/akkoma_ap_integration_tester",
|
||||
"to": [
|
||||
"https://fedibird.com/users/akkoma_ap_integration_tester/followers"
|
||||
],
|
||||
"cc": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"sensitive": false,
|
||||
"atomUri": "https://fedibird.com/users/akkoma_ap_integration_tester/statuses/108707679228362674",
|
||||
"inReplyToAtomUri": null,
|
||||
"conversation": "tag:fedibird.com,2022-07-25:objectId=108707679228389900:objectType=Conversation",
|
||||
"context": "https://fedibird.com/contexts/108707679228389900",
|
||||
"quoteUri": "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924",
|
||||
"_misskey_quote": "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924",
|
||||
"_misskey_content": "public quote",
|
||||
"content": "<p>public quote<span class=\"quote-inline\"><br/>QT: <a class=\"status-url-link\" data-status-account-acct=\"ArtMirror@example.com\" data-status-id=\"108703793483919195\" href=\"https://example.com/objects/24d9f2e1-32d2-4bd5-bdf2-8ea61d3fb5e8\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">example.com/objects/24d9f</span><span class=\"invisible\">2e1-32d2-4bd5-bdf2-8ea61d3fb5e8</span></a></span><span class=\"reference-link-inline\"> <a href=\"https://fedibird.com/@akkoma_ap_integration_tester/108707679228362674/references\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"status-link unhandled-link\" data-status-id=\"108707679228362674\">[参照]</a></span></p>",
|
||||
"contentMap": {
|
||||
"ja": "<p>public quote<span class=\"quote-inline\"><br/>QT: <a class=\"status-url-link\" data-status-account-acct=\"ArtMirror@example.com\" data-status-id=\"108703793483919195\" href=\"https://example.com/objects/24d9f2e1-32d2-4bd5-bdf2-8ea61d3fb5e8\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">example.com/objects/24d9f</span><span class=\"invisible\">2e1-32d2-4bd5-bdf2-8ea61d3fb5e8</span></a></span><span class=\"reference-link-inline\"> <a href=\"https://fedibird.com/@akkoma_ap_integration_tester/108707679228362674/references\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"status-link unhandled-link\" data-status-id=\"108707679228362674\">[参照]</a></span></p>"
|
||||
},
|
||||
"attachment": [],
|
||||
"tag": [],
|
||||
"replies": {
|
||||
"id": "https://fedibird.com/users/akkoma_ap_integration_tester/statuses/108707679228362674/replies",
|
||||
"type": "Collection",
|
||||
"first": {
|
||||
"type": "CollectionPage",
|
||||
"next": "https://fedibird.com/users/akkoma_ap_integration_tester/statuses/108707679228362674/replies?only_other_accounts=true&page=true",
|
||||
"partOf": "https://fedibird.com/users/akkoma_ap_integration_tester/statuses/108707679228362674/replies",
|
||||
"items": []
|
||||
}
|
||||
},
|
||||
"references": {
|
||||
"id": "https://fedibird.com/users/akkoma_ap_integration_tester/statuses/108707679228362674/references",
|
||||
"type": "Collection",
|
||||
"first": {
|
||||
"type": "CollectionPage",
|
||||
"partOf": "https://fedibird.com/users/akkoma_ap_integration_tester/statuses/108707679228362674/references",
|
||||
"items": [
|
||||
"https://example.com/objects/24d9f2e1-32d2-4bd5-bdf2-8ea61d3fb5e8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
50
test/fixtures/misskey/quote.json
vendored
Normal file
50
test/fixtures/misskey/quote.json
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"sensitive": "as:sensitive",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"quoteUrl": "as:quoteUrl",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"Emoji": "toot:Emoji",
|
||||
"featured": "toot:featured",
|
||||
"discoverable": "toot:discoverable",
|
||||
"schema": "http://schema.org#",
|
||||
"PropertyValue": "schema:PropertyValue",
|
||||
"value": "schema:value",
|
||||
"misskey": "https://misskey-hub.net/ns#",
|
||||
"_misskey_content": "misskey:_misskey_content",
|
||||
"_misskey_quote": "misskey:_misskey_quote",
|
||||
"_misskey_reaction": "misskey:_misskey_reaction",
|
||||
"_misskey_votes": "misskey:_misskey_votes",
|
||||
"_misskey_talk": "misskey:_misskey_talk",
|
||||
"isCat": "misskey:isCat",
|
||||
"vcard": "http://www.w3.org/2006/vcard/ns#"
|
||||
}
|
||||
],
|
||||
"id": "https://misskey.io/notes/934gok3482",
|
||||
"type": "Note",
|
||||
"attributedTo": "https://misskey.io/users/93492q0ip0",
|
||||
"summary": null,
|
||||
"content": "<p><span>i quompt u<br><br>RE: </span><a href=\"https://example.com/objects/30c543fb-a165-40dd-87fd-4e249ec5a40b\">https://example.com/objects/30c543fb-a165-40dd-87fd-4e249ec5a40b</a></p>",
|
||||
"_misskey_content": "i quompt u",
|
||||
"source": {
|
||||
"content": "i quompt u",
|
||||
"mediaType": "text/x.misskeymarkdown"
|
||||
},
|
||||
"_misskey_quote": "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924",
|
||||
"quoteUrl": "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924",
|
||||
"published": "2022-07-25T15:21:48.208Z",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://misskey.io/users/93492q0ip0/followers"
|
||||
],
|
||||
"inReplyTo": null,
|
||||
"attachment": [],
|
||||
"sensitive": false,
|
||||
"tag": []
|
||||
}
|
38
test/fixtures/quoted_status.json
vendored
Normal file
38
test/fixtures/quoted_status.json
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://example.com/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"actor": "https://example.com/users/user",
|
||||
"attachment": [
|
||||
{
|
||||
"mediaType": "image/png",
|
||||
"name": "",
|
||||
"type": "Document",
|
||||
"url": "https://example.com/media/4d6097ae20200ac371f51d24eae0a94cb4b424b6aff81dcc0f7411b1a74c796f.png"
|
||||
}
|
||||
],
|
||||
"attributedTo": "https://example.com/users/user",
|
||||
"cc": [
|
||||
"https://example.com/users/user/followers"
|
||||
],
|
||||
"content": "",
|
||||
"context": "https://example.com/contexts/c2c52511-977e-4168-996c-bcf006789dca",
|
||||
"conversation": "https://example.com/contexts/c2c52511-977e-4168-996c-bcf006789dca",
|
||||
"id": "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924",
|
||||
"published": "2022-07-24T17:25:51.614495Z",
|
||||
"sensitive": null,
|
||||
"source": {
|
||||
"content": "",
|
||||
"mediaType": "text/plain"
|
||||
},
|
||||
"summary": "",
|
||||
"tag": [],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Note"
|
||||
}
|
|
@ -143,5 +143,61 @@ test "a misskey MFM status with a _misskey_content field should work and be link
|
|||
}
|
||||
} = ArticleNotePageValidator.cast_and_validate(note)
|
||||
end
|
||||
|
||||
test "a misskey quote should work", _ do
|
||||
Tesla.Mock.mock(fn %{
|
||||
method: :get,
|
||||
url: "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924"
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/quoted_status.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
insert(:user, %{ap_id: "https://misskey.io/users/93492q0ip0"})
|
||||
insert(:user, %{ap_id: "https://example.com/users/user"})
|
||||
|
||||
note =
|
||||
"test/fixtures/misskey/quote.json"
|
||||
|> File.read!()
|
||||
|> Jason.decode!()
|
||||
|
||||
%{
|
||||
valid?: true,
|
||||
changes: %{
|
||||
quoteUri: "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924"
|
||||
}
|
||||
} = ArticleNotePageValidator.cast_and_validate(note)
|
||||
end
|
||||
|
||||
test "a fedibird quote should work", _ do
|
||||
Tesla.Mock.mock(fn %{
|
||||
method: :get,
|
||||
url: "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924"
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/quoted_status.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
insert(:user, %{ap_id: "https://fedibird.com/users/akkoma_ap_integration_tester"})
|
||||
insert(:user, %{ap_id: "https://example.com/users/user"})
|
||||
|
||||
note =
|
||||
"test/fixtures/fedibird/quote.json"
|
||||
|> File.read!()
|
||||
|> Jason.decode!()
|
||||
|
||||
%{
|
||||
valid?: true,
|
||||
changes: %{
|
||||
quoteUri: "https://example.com/objects/43479e20-c0f8-4f49-bf7f-13fab8234924"
|
||||
}
|
||||
} = ArticleNotePageValidator.cast_and_validate(note)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2030,5 +2030,16 @@ test "posting a quote of a deleted status", %{conn: conn} do
|
|||
})
|
||||
|> json_response_and_validate_schema(422)
|
||||
end
|
||||
|
||||
test "posting a quote of a status that doesn't exist", %{conn: conn} do
|
||||
assert %{"error" => "You can't quote a status that doesn't exist"} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "I fight for eorzea!",
|
||||
"quote_id" => "oops"
|
||||
})
|
||||
|> json_response_and_validate_schema(422)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -395,6 +395,30 @@ test "a reply" do
|
|||
assert status.in_reply_to_id == to_string(note.id)
|
||||
end
|
||||
|
||||
test "a quote" do
|
||||
note = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hehe", quote_id: note.id})
|
||||
|
||||
status = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert status.quote_id == to_string(note.id)
|
||||
|
||||
[status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
|
||||
|
||||
assert status.quote_id == to_string(note.id)
|
||||
end
|
||||
|
||||
test "a quote that we can't resolve" do
|
||||
note = insert(:note_activity, quoteUri: "oopsie")
|
||||
|
||||
status = StatusView.render("show.json", %{activity: note})
|
||||
|
||||
assert is_nil(status.quote_id)
|
||||
assert is_nil(status.quote)
|
||||
end
|
||||
|
||||
test "contains mentions" do
|
||||
user = insert(:user)
|
||||
mentioned = insert(:user)
|
||||
|
|
Loading…
Reference in a new issue