From 2e5c90593ec67076e7664f06da1156d5fa7a1e7a Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sun, 4 May 2025 16:47:17 +0100 Subject: [PATCH] Make test completely deterministic --- test/music_library_web/live/stats_live/index_test.exs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/music_library_web/live/stats_live/index_test.exs b/test/music_library_web/live/stats_live/index_test.exs index 93b1e648..8fa17d5b 100644 --- a/test/music_library_web/live/stats_live/index_test.exs +++ b/test/music_library_web/live/stats_live/index_test.exs @@ -8,7 +8,14 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do import MusicBrainz.Fixtures.Release defp fill_collection(_) do - records = Enum.map(1..19, fn _ -> record() end) + current_time = DateTime.utc_now() + + records = + Enum.map(1..19, fn i -> + purchased_at = DateTime.add(current_time, i, :second) + record(%{purchased_at: purchased_at}) + end) + %{collection: records} end @@ -45,8 +52,6 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do end test "it shows the latest purchase", %{conn: conn, collection: collection} do - # purchased_at has second precision, so finding the latest purchased using then - # highest purchased_at value doesn't work, as it picks the wrong value. latest_record = List.last(collection) session =