fix flaky test filter_controller_test.exs:200
This commit is contained in:
parent
0814d0e0cb
commit
5b2e3a303c
|
@ -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,6 +54,7 @@ test "a filter with expires_in", %{conn: conn, user: user} do
|
||||||
in_seconds = 600
|
in_seconds = 600
|
||||||
|
|
||||||
response =
|
response =
|
||||||
|
with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "application/json")
|
|> put_req_header("content-type", "application/json")
|
||||||
|> post("/api/v1/filters", %{
|
|> post("/api/v1/filters", %{
|
||||||
|
@ -61,16 +63,10 @@ test "a filter with expires_in", %{conn: conn, user: user} do
|
||||||
expires_in: in_seconds
|
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
|
||||||
|
assert response["expires_at"] == "2017-03-17T17:19:58.000Z"
|
||||||
expected_expiration =
|
|
||||||
NaiveDateTime.utc_now()
|
|
||||||
|> NaiveDateTime.add(in_seconds)
|
|
||||||
|
|
||||||
{:ok, actual_expiration} = NaiveDateTime.from_iso8601(response["expires_at"])
|
|
||||||
|
|
||||||
assert abs(NaiveDateTime.diff(expected_expiration, actual_expiration)) <= 5
|
|
||||||
|
|
||||||
filter = Filter.get(response["id"], user)
|
filter = Filter.get(response["id"], user)
|
||||||
|
|
||||||
|
@ -177,12 +173,12 @@ test "common" do
|
||||||
assert response["whole_word"] == true
|
assert response["whole_word"] == true
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag :erratic
|
|
||||||
test "with adding expires_at", %{conn: conn, user: user} do
|
test "with adding expires_at", %{conn: conn, user: user} do
|
||||||
filter = insert(:filter, user: user)
|
filter = insert(:filter, user: user)
|
||||||
in_seconds = 600
|
in_seconds = 600
|
||||||
|
|
||||||
response =
|
response =
|
||||||
|
with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "application/json")
|
|> put_req_header("content-type", "application/json")
|
||||||
|> put("/api/v1/filters/#{filter.filter_id}", %{
|
|> put("/api/v1/filters/#{filter.filter_id}", %{
|
||||||
|
@ -192,13 +188,10 @@ test "with adding expires_at", %{conn: conn, user: user} do
|
||||||
irreversible: true
|
irreversible: true
|
||||||
})
|
})
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
end
|
||||||
|
|
||||||
assert response["irreversible"] == true
|
assert response["irreversible"] == true
|
||||||
|
assert response["expires_at"] == "2017-03-17T17:19:58.000Z"
|
||||||
assert response["expires_at"] ==
|
|
||||||
NaiveDateTime.utc_now()
|
|
||||||
|> NaiveDateTime.add(in_seconds)
|
|
||||||
|> Pleroma.Web.CommonAPI.Utils.to_masto_date()
|
|
||||||
|
|
||||||
filter = Filter.get(response["id"], user)
|
filter = Filter.get(response["id"], user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue