aboutsummaryrefslogtreecommitdiff
path: root/test/support/helpers.ex
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-12-16 10:39:36 +0100
committerlain <lain@soykaf.club>2020-12-16 10:39:36 +0100
commit3dd5e11724e30db98842d58b6cedfff73b94d6ae (patch)
tree76de1ba4ec044f1022cdfff6ccc42ef46bf0164e /test/support/helpers.ex
parent6bb4f4e1721d30762978b59a1aed11137223c183 (diff)
downloadpleroma-3dd5e11724e30db98842d58b6cedfff73b94d6ae.tar.gz
Tests: Add a helper method to reduce sleeping times in test.
This will 'time travel', i.e. change the inserted_at and update_at fields of the object in question. This is used to backdate things were we used sleeping before to ensure time differences.
Diffstat (limited to 'test/support/helpers.ex')
-rw-r--r--test/support/helpers.ex8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
index 224034521..15e8cbd9d 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -55,6 +55,14 @@ defmodule Pleroma.Tests.Helpers do
clear_config: 2
]
+ def time_travel(entity, seconds) do
+ new_time = NaiveDateTime.add(entity.inserted_at, seconds)
+
+ entity
+ |> Ecto.Changeset.change(%{inserted_at: new_time, updated_at: new_time})
+ |> Pleroma.Repo.update()
+ end
+
def to_datetime(%NaiveDateTime{} = naive_datetime) do
naive_datetime
|> DateTime.from_naive!("Etc/UTC")