From 0ef0aed205f7298d82649f55615193baac4b3667 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 16 Dec 2020 10:39:36 +0100 Subject: 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. --- test/support/helpers.ex | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/support/helpers.ex') 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") -- cgit v1.2.3