tests: add tests for User + cache interactions
authorWilliam Pitcock <nenolod@dereferenced.org>
Thu, 1 Nov 2018 08:09:51 +0000 (08:09 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Thu, 1 Nov 2018 08:11:02 +0000 (08:11 +0000)
test/user_test.exs

index 05da24f8d22e534ce5781a25f74d65c6d3c349f9..9b3519ece5db372c0afa06cb8f1c012f8d95b7cd 100644 (file)
@@ -551,4 +551,31 @@ defmodule Pleroma.UserTest do
       assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
     end
   end
+
+  describe "caching" do
+    test "invalidate_cache works" do
+      user = insert(:user)
+      user_info = User.get_cached_user_info(user)
+
+      User.invalidate_cache(user)
+
+      {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
+      {:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}")
+      {:ok, nil} = Cachex.get(:user_cache, "user_info:#{user.id}")
+    end
+
+    test "User.delete() plugs any possible zombie objects" do
+      user = insert(:user)
+
+      {:ok, _} = User.delete(user)
+
+      {:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
+
+      assert cached_user != user
+
+      {:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}")
+
+      assert cached_user != user
+    end
+  end
 end