add tests
authorMaksim Pechnikov <parallel588@gmail.com>
Fri, 23 Aug 2019 18:17:14 +0000 (21:17 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Sat, 24 Aug 2019 08:03:13 +0000 (11:03 +0300)
test/signature_test.exs
test/tasks/relay_test.exs
test/web/activity_pub/relay_test.exs

index 26337eaf9ee7da5e71f8d865edf8632513e443a5..d5bf63d7d43da2a15ceae2a1f40d17a5c464d2de 100644 (file)
@@ -8,6 +8,7 @@ defmodule Pleroma.SignatureTest do
   import ExUnit.CaptureLog
   import Pleroma.Factory
   import Tesla.Mock
+  import Mock
 
   alias Pleroma.Signature
 
@@ -114,4 +115,17 @@ defmodule Pleroma.SignatureTest do
                "https://example.com/users/1234"
     end
   end
+
+  describe "signed_date" do
+    test "it returns formatted current date" do
+      with_mock(NaiveDateTime, utc_now: fn -> ~N[2019-08-23 18:11:24.822233] end) do
+        assert Signature.signed_date() == "Fri, 23 Aug 2019 18:11:24 GMT"
+      end
+    end
+
+    test "it returns formatted date" do
+      assert Signature.signed_date(~N[2019-08-23 08:11:24.822233]) ==
+               "Fri, 23 Aug 2019 08:11:24 GMT"
+    end
+  end
 end
index 0d341c8d6c35bc4c552599a2530d5dbad573fc68..7bde56606ea20a2891fb4dcbc6d7dd7bcd46098d 100644 (file)
@@ -50,7 +50,8 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
       %User{ap_id: follower_id} = local_user = Relay.get_actor()
       target_user = User.get_cached_by_ap_id(target_instance)
       follow_activity = Utils.fetch_latest_follow(local_user, target_user)
-
+      User.follow(local_user, target_user)
+      assert "#{target_instance}/followers" in refresh_record(local_user).following
       Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
 
       cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
@@ -67,6 +68,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
       assert undo_activity.data["type"] == "Undo"
       assert undo_activity.data["actor"] == local_user.ap_id
       assert undo_activity.data["object"] == cancelled_activity.data
+      refute "#{target_instance}/followers" in refresh_record(local_user).following
     end
   end
 
index e10b808f7220eb45e2e1d35326ff09a3766f8b42..aeef91cda85ad1f53bccb9850c1c424e0606d689 100644 (file)
@@ -43,12 +43,15 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
       user = insert(:user)
       service_actor = Relay.get_actor()
       ActivityPub.follow(service_actor, user)
+      Pleroma.User.follow(service_actor, user)
+      assert "#{user.ap_id}/followers" in refresh_record(service_actor).following
       assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
       assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
       assert user.ap_id in activity.recipients
       assert activity.data["type"] == "Undo"
       assert activity.data["actor"] == service_actor.ap_id
       assert activity.data["to"] == [user.ap_id]
+      refute "#{user.ap_id}/followers" in refresh_record(service_actor).following
     end
   end