Merge upstream changes from stable #3

Merged
fedward merged 57 commits from AkkomaGang/akkoma:stable into stable 2022-11-15 15:35:25 +00:00
Showing only changes of commit a59d310982 - Show all commits

View file

@ -3,9 +3,10 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
use Pleroma.Web.ConnCase, async: true use Pleroma.Web.ConnCase, async: false
use Oban.Testing, repo: Pleroma.Repo use Oban.Testing, repo: Pleroma.Repo
import Mock
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Filter alias Pleroma.Filter
@ -53,25 +54,20 @@ test "a filter with expires_in", %{conn: conn, user: user} do
in_seconds = 600 in_seconds = 600
response = response =
conn with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
|> put_req_header("content-type", "application/json") conn
|> post("/api/v1/filters", %{ |> put_req_header("content-type", "application/json")
"phrase" => "knights", |> post("/api/v1/filters", %{
context: ["home"], "phrase" => "knights",
expires_in: in_seconds context: ["home"],
}) expires_in: in_seconds
|> json_response_and_validate_schema(200) })
|> json_response_and_validate_schema(200)
end
assert response["irreversible"] == false assert response["irreversible"] == false
expires_at = assert response["expires_at"] == "2017-03-17T17:19:58.000Z"
NaiveDateTime.utc_now()
|> NaiveDateTime.add(in_seconds)
assert NaiveDateTime.diff(
NaiveDateTime.from_iso8601!(response["expires_at"]),
expires_at
) < 5
filter = Filter.get(response["id"], user) filter = Filter.get(response["id"], user)
@ -183,26 +179,21 @@ test "with adding expires_at", %{conn: conn, user: user} do
in_seconds = 600 in_seconds = 600
response = response =
conn with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
|> put_req_header("content-type", "application/json") conn
|> put("/api/v1/filters/#{filter.filter_id}", %{ |> put_req_header("content-type", "application/json")
phrase: "nii", |> put("/api/v1/filters/#{filter.filter_id}", %{
context: ["public"], phrase: "nii",
expires_in: in_seconds, context: ["public"],
irreversible: true expires_in: in_seconds,
}) irreversible: true
|> json_response_and_validate_schema(200) })
|> json_response_and_validate_schema(200)
end
assert response["irreversible"] == true assert response["irreversible"] == true
expected_time = assert response["expires_at"] == "2017-03-17T17:19:58.000Z"
NaiveDateTime.utc_now()
|> NaiveDateTime.add(in_seconds)
assert NaiveDateTime.diff(
NaiveDateTime.from_iso8601!(response["expires_at"]),
expected_time
) < 5
filter = Filter.get(response["id"], user) filter = Filter.get(response["id"], user)