summaryrefslogtreecommitdiff
path: root/test/repo_test.exs
diff options
context:
space:
mode:
authorMark Felder <feld@FreeBSD.org>2020-10-09 11:26:10 -0500
committerMark Felder <feld@FreeBSD.org>2020-10-09 11:26:10 -0500
commit04b514c567aa664d2606313d17be69e665a7f1af (patch)
tree13f46fd39d8a90837b031b1081b7e20696d6823a /test/repo_test.exs
parent55562ca9362d66553ea3638c91174bbeb6c637f1 (diff)
parentd239bd3ca4348d38c12ab54c7e2e9cb2b825cc3c (diff)
downloadpleroma-04b514c567aa664d2606313d17be69e665a7f1af.tar.gz
pleroma-04b514c567aa664d2606313d17be69e665a7f1af.zip
Merge branch 'develop' into feature/gen-magic
Diffstat (limited to 'test/repo_test.exs')
-rw-r--r--test/repo_test.exs32
1 files changed, 31 insertions, 1 deletions
diff --git a/test/repo_test.exs b/test/repo_test.exs
index 92e827c95..155791be2 100644
--- a/test/repo_test.exs
+++ b/test/repo_test.exs
@@ -37,7 +37,9 @@ defmodule Pleroma.RepoTest do
test "get one-to-many assoc from repo" do
user = insert(:user)
- notification = refresh_record(insert(:notification, user: user))
+
+ notification =
+ refresh_record(insert(:notification, user: user, activity: insert(:note_activity)))
assert Repo.get_assoc(user, :notifications) == {:ok, [notification]}
end
@@ -47,4 +49,32 @@ defmodule Pleroma.RepoTest do
assert Repo.get_assoc(token, :user) == {:error, :not_found}
end
end
+
+ describe "chunk_stream/3" do
+ test "fetch records one-by-one" do
+ users = insert_list(50, :user)
+
+ {fetch_users, 50} =
+ from(t in User)
+ |> Repo.chunk_stream(5)
+ |> Enum.reduce({[], 0}, fn %User{} = user, {acc, count} ->
+ {acc ++ [user], count + 1}
+ end)
+
+ assert users == fetch_users
+ end
+
+ test "fetch records in bulk" do
+ users = insert_list(50, :user)
+
+ {fetch_users, 10} =
+ from(t in User)
+ |> Repo.chunk_stream(5, :batches)
+ |> Enum.reduce({[], 0}, fn users, {acc, count} ->
+ {acc ++ users, count + 1}
+ end)
+
+ assert users == fetch_users
+ end
+ end
end