Fix status.expires_in
validation
This commit is contained in:
parent
d056f7f722
commit
19516af74e
@ -62,6 +62,6 @@ defmodule Pleroma.ActivityExpiration do
|
|||||||
def expires_late_enough?(scheduled_at) do
|
def expires_late_enough?(scheduled_at) do
|
||||||
now = NaiveDateTime.utc_now()
|
now = NaiveDateTime.utc_now()
|
||||||
diff = NaiveDateTime.diff(scheduled_at, now, :millisecond)
|
diff = NaiveDateTime.diff(scheduled_at, now, :millisecond)
|
||||||
diff >= @min_activity_lifetime
|
diff > @min_activity_lifetime
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -121,6 +121,32 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||||||
NaiveDateTime.to_iso8601(expiration.scheduled_at)
|
NaiveDateTime.to_iso8601(expiration.scheduled_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it fails to create a status if `expires_in` is less or equal than an hour", %{
|
||||||
|
conn: conn
|
||||||
|
} do
|
||||||
|
# 1 hour
|
||||||
|
expires_in = 60 * 60
|
||||||
|
|
||||||
|
assert %{"error" => "Expiry date is too soon"} =
|
||||||
|
conn
|
||||||
|
|> post("api/v1/statuses", %{
|
||||||
|
"status" => "oolong",
|
||||||
|
"expires_in" => expires_in
|
||||||
|
})
|
||||||
|
|> json_response(422)
|
||||||
|
|
||||||
|
# 30 minutes
|
||||||
|
expires_in = 30 * 60
|
||||||
|
|
||||||
|
assert %{"error" => "Expiry date is too soon"} =
|
||||||
|
conn
|
||||||
|
|> post("api/v1/statuses", %{
|
||||||
|
"status" => "oolong",
|
||||||
|
"expires_in" => expires_in
|
||||||
|
})
|
||||||
|
|> json_response(422)
|
||||||
|
end
|
||||||
|
|
||||||
test "posting an undefined status with an attachment", %{user: user, conn: conn} do
|
test "posting an undefined status with an attachment", %{user: user, conn: conn} do
|
||||||
file = %Plug.Upload{
|
file = %Plug.Upload{
|
||||||
content_type: "image/jpg",
|
content_type: "image/jpg",
|
||||||
|
Loading…
Reference in New Issue
Block a user