summaryrefslogtreecommitdiff
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-21 16:31:23 +0100
commit0ef0aed205f7298d82649f55615193baac4b3667 (patch)
tree623c29ae77e064b5db371fad1f2f38ff2c3064d4 /test/support/helpers.ex
parentba1997583842bf18949334e4f2d9c05946fc4b17 (diff)
downloadpleroma-0ef0aed205f7298d82649f55615193baac4b3667.tar.gz
pleroma-0ef0aed205f7298d82649f55615193baac4b3667.zip
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")