From 21dafa7cd029870c3dc60846ead23f1866bc4cd3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 1 Nov 2018 08:09:51 +0000 Subject: [PATCH] tests: add tests for User + cache interactions --- test/user_test.exs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/user_test.exs b/test/user_test.exs index 05da24f8d..9b3519ece 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -551,4 +551,31 @@ test "html_filter_policy returns TwitterText scrubber when rich-text is disabled 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