forked from AkkomaGang/akkoma
81 lines
2.1 KiB
Elixir
81 lines
2.1 KiB
Elixir
defmodule Pleroma.Feed.UpdatesTest do
|
|
use Pleroma.DataCase
|
|
use Oban.Testing, repo: Pleroma.Repo
|
|
|
|
alias Pleroma.Feed.Subscriptions
|
|
alias Pleroma.Feed.Updates
|
|
|
|
@subscription_lease_seconds 5
|
|
@content_type_text_plain [{"content-type", "text/plain"}]
|
|
@html_body """
|
|
<!doctype html>
|
|
<html lang=en>
|
|
<head>
|
|
<meta charset=utf-8>
|
|
<title>blah</title>
|
|
</head>
|
|
<body>
|
|
<p>I'm the content</p>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
describe "updates" do
|
|
test "publishing update dispatches jobs" do
|
|
topic_url = "https://localhost/publisher/topic/123"
|
|
callback_url = "http://localhost/subscriber/callback"
|
|
|
|
Tesla.Mock.mock(fn
|
|
%{url: ^topic_url} = req ->
|
|
Tesla.Mock.Agent.add_hit(:publisher, req)
|
|
|
|
%Tesla.Env{
|
|
status: 200,
|
|
body: @html_body,
|
|
headers: [
|
|
{"content-type", "text/html; charset=UTF-8"}
|
|
]
|
|
}
|
|
|
|
%{method: :get, url: ^callback_url, query: query} = req ->
|
|
Tesla.Mock.Agent.add_hit(:subscriber, req)
|
|
|
|
query = Map.new(query)
|
|
|
|
if Map.has_key?(query, "hub.challenge") do
|
|
%Tesla.Env{
|
|
status: 200,
|
|
body: Map.get(query, "hub.challenge"),
|
|
headers: @content_type_text_plain
|
|
}
|
|
else
|
|
%Tesla.Env{status: 400, body: "no challenge", headers: @content_type_text_plain}
|
|
end
|
|
|
|
_not_matched ->
|
|
%Tesla.Env{
|
|
status: 404,
|
|
body: "not found",
|
|
headers: @content_type_text_plain
|
|
}
|
|
end)
|
|
|
|
assert {:ok, _} =
|
|
Subscriptions.subscribe(
|
|
:websub,
|
|
topic_url,
|
|
callback_url,
|
|
@subscription_lease_seconds
|
|
)
|
|
|
|
assert {:ok, update} = Updates.publish(topic_url)
|
|
|
|
assert Tesla.Mock.Agent.hits(:subscriber) == 1
|
|
|
|
assert [job] = all_enqueued(worker: Pleroma.Workers.DispatchFeedUpdateWorker)
|
|
assert job.args["update_id"] == update.id
|
|
assert job.args["callback_url"] == callback_url
|
|
end
|
|
end
|
|
end
|