StatusController: Ignore nil scheduled_at parameters.

This commit is contained in:
lain 2020-04-22 14:26:19 +02:00
parent c466e739b6
commit c10485db16
2 changed files with 13 additions and 1 deletions

View File

@ -127,7 +127,8 @@ def index(%{assigns: %{user: user}} = conn, %{"ids" => ids} = params) do
def create( def create(
%{assigns: %{user: user}} = conn, %{assigns: %{user: user}} = conn,
%{"status" => _, "scheduled_at" => scheduled_at} = params %{"status" => _, "scheduled_at" => scheduled_at} = params
) do )
when not is_nil(scheduled_at) do
params = Map.put(params, "in_reply_to_status_id", params["in_reply_to_id"]) params = Map.put(params, "in_reply_to_status_id", params["in_reply_to_id"])
with {:far_enough, true} <- {:far_enough, ScheduledActivity.far_enough?(scheduled_at)}, with {:far_enough, true} <- {:far_enough, ScheduledActivity.far_enough?(scheduled_at)},

View File

@ -302,6 +302,17 @@ test "creates a scheduled activity", %{conn: conn} do
assert [] == Repo.all(Activity) assert [] == Repo.all(Activity)
end end
test "ignores nil values", %{conn: conn} do
conn =
post(conn, "/api/v1/statuses", %{
"status" => "not scheduled",
"scheduled_at" => nil
})
assert result = json_response(conn, 200)
assert Activity.get_by_id(result["id"])
end
test "creates a scheduled activity with a media attachment", %{user: user, conn: conn} do test "creates a scheduled activity with a media attachment", %{user: user, conn: conn} do
scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond) scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)