tests: Replace 2 second sleep with offseting updated_at
This commit is contained in:
parent
8efacfed67
commit
c8046e1080
@ -5,7 +5,9 @@
|
|||||||
defmodule Pleroma.Conversation.ParticipationTest do
|
defmodule Pleroma.Conversation.ParticipationTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
alias Pleroma.Conversation
|
||||||
alias Pleroma.Conversation.Participation
|
alias Pleroma.Conversation.Participation
|
||||||
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
@ -98,7 +100,9 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||||||
assert participation.user_id == user.id
|
assert participation.user_id == user.id
|
||||||
assert participation.conversation_id == conversation.id
|
assert participation.conversation_id == conversation.id
|
||||||
|
|
||||||
|
# Needed because updated_at is accurate down to a second
|
||||||
:timer.sleep(1000)
|
:timer.sleep(1000)
|
||||||
|
|
||||||
# Creating again returns the same participation
|
# Creating again returns the same participation
|
||||||
{:ok, %Participation{} = participation_two} =
|
{:ok, %Participation{} = participation_two} =
|
||||||
Participation.create_for_user_and_conversation(user, conversation)
|
Participation.create_for_user_and_conversation(user, conversation)
|
||||||
@ -150,9 +154,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||||||
test "gets all the participations for a user, ordered by updated at descending" do
|
test "gets all the participations for a user, ordered by updated at descending" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
|
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
|
||||||
:timer.sleep(1000)
|
|
||||||
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
|
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
|
||||||
:timer.sleep(1000)
|
|
||||||
|
|
||||||
{:ok, activity_three} =
|
{:ok, activity_three} =
|
||||||
CommonAPI.post(user, %{
|
CommonAPI.post(user, %{
|
||||||
@ -161,6 +163,17 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||||||
"in_reply_to_status_id" => activity_one.id
|
"in_reply_to_status_id" => activity_one.id
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Offset participations because the accuracy of updated_at is down to a second
|
||||||
|
|
||||||
|
for {activity, offset} <- [{activity_two, 1}, {activity_three, 2}] do
|
||||||
|
conversation = Conversation.get_for_ap_id(activity.data["context"])
|
||||||
|
participation = Participation.for_user_and_conversation(user, conversation)
|
||||||
|
updated_at = NaiveDateTime.add(Map.get(participation, :updated_at), offset)
|
||||||
|
|
||||||
|
Ecto.Changeset.change(participation, %{updated_at: updated_at})
|
||||||
|
|> Repo.update!()
|
||||||
|
end
|
||||||
|
|
||||||
assert [participation_one, participation_two] = Participation.for_user(user)
|
assert [participation_one, participation_two] = Participation.for_user(user)
|
||||||
|
|
||||||
object2 = Pleroma.Object.normalize(activity_two)
|
object2 = Pleroma.Object.normalize(activity_two)
|
||||||
|
Loading…
Reference in New Issue
Block a user