summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2021-02-01 18:22:26 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2021-02-01 18:22:26 +0300
commit0dc68c157f9e1cb1ef53223faeb9aa8d924e3094 (patch)
treee53f2d8a9e7b7cd9b9192760058c7e5c2475fbeb /test
parent08a2cb750de0fb7cdbdd044071cc10ad7f0096aa (diff)
fix for scheduled post with poll
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs40
-rw-r--r--test/pleroma/workers/scheduled_activity_worker_test.exs21
2 files changed, 51 insertions, 10 deletions
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
index a647cd57f..7819bc4f0 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -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
diff --git a/test/pleroma/workers/scheduled_activity_worker_test.exs b/test/pleroma/workers/scheduled_activity_worker_test.exs
index 6e11642d5..5558d5b5f 100644
--- a/test/pleroma/workers/scheduled_activity_worker_test.exs
+++ b/test/pleroma/workers/scheduled_activity_worker_test.exs
@@ -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"
- end
- test "adds log message if ScheduledActivity isn't find" do
- clear_config([ScheduledActivity, :enabled], true)
+ object =
+ Pleroma.Activity
+ |> Repo.get(activity_id)
+ |> Pleroma.Object.normalize()
+
+ assert object.data["content"] == "hi"
+ end
+ 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