fix for scheduled post with poll
This commit is contained in:
parent
08a2cb750d
commit
0dc68c157f
6 changed files with 119 additions and 61 deletions
|
|
@ -515,7 +515,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end)
|
||||
|
||||
assert NaiveDateTime.diff(NaiveDateTime.from_iso8601!(response["poll"]["expires_at"]), time) in 420..430
|
||||
refute response["poll"]["expred"]
|
||||
assert response["poll"]["expired"] == false
|
||||
|
||||
question = Object.get_by_id(response["poll"]["id"])
|
||||
|
||||
|
|
@ -591,6 +591,44 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
%{"error" => error} = json_response_and_validate_schema(conn, 422)
|
||||
assert error == "Expiration date is too far in the future"
|
||||
end
|
||||
|
||||
test "scheduled poll", %{conn: conn} do
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
|
||||
scheduled_at =
|
||||
NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(6), :millisecond)
|
||||
|> NaiveDateTime.to_iso8601()
|
||||
|> Kernel.<>("Z")
|
||||
|
||||
%{"id" => scheduled_id} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "very cool poll",
|
||||
"poll" => %{
|
||||
"options" => ~w(a b c),
|
||||
"expires_in" => 420
|
||||
},
|
||||
"scheduled_at" => scheduled_at
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert {:ok, %{id: activity_id}} =
|
||||
perform_job(Pleroma.Workers.ScheduledActivityWorker, %{
|
||||
activity_id: scheduled_id
|
||||
})
|
||||
|
||||
assert Repo.all(Oban.Job) == []
|
||||
|
||||
object =
|
||||
Activity
|
||||
|> Repo.get(activity_id)
|
||||
|> Object.normalize()
|
||||
|
||||
assert object.data["content"] == "very cool poll"
|
||||
assert object.data["type"] == "Question"
|
||||
assert length(object.data["oneOf"]) == 3
|
||||
end
|
||||
end
|
||||
|
||||
test "get a status" do
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@ defmodule Pleroma.Workers.ScheduledActivityWorkerTest do
|
|||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
setup do: clear_config([ScheduledActivity, :enabled])
|
||||
setup do: clear_config([ScheduledActivity, :enabled], true)
|
||||
|
||||
test "creates a status from the scheduled activity" do
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
user = insert(:user)
|
||||
|
||||
naive_datetime =
|
||||
|
|
@ -32,18 +31,22 @@ defmodule Pleroma.Workers.ScheduledActivityWorkerTest do
|
|||
params: %{status: "hi"}
|
||||
)
|
||||
|
||||
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
|
||||
{:ok, %{id: activity_id}} =
|
||||
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => scheduled_activity.id}})
|
||||
|
||||
refute Repo.get(ScheduledActivity, scheduled_activity.id)
|
||||
activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
|
||||
assert Pleroma.Object.normalize(activity, fetch: false).data["content"] == "hi"
|
||||
|
||||
object =
|
||||
Pleroma.Activity
|
||||
|> Repo.get(activity_id)
|
||||
|> Pleroma.Object.normalize()
|
||||
|
||||
assert object.data["content"] == "hi"
|
||||
end
|
||||
|
||||
test "adds log message if ScheduledActivity isn't find" do
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
|
||||
test "error message for non-existent scheduled activity" do
|
||||
assert capture_log([level: :error], fn ->
|
||||
ScheduledActivityWorker.perform(%Oban.Job{args: %{"activity_id" => 42}})
|
||||
end) =~ "Couldn't find scheduled activity"
|
||||
end) =~ "Couldn't find scheduled activity: 42"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue