added tests
authorMaksim Pechnikov <parallel588@gmail.com>
Thu, 28 Nov 2019 06:02:23 +0000 (09:02 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Thu, 28 Nov 2019 06:02:23 +0000 (09:02 +0300)
test/workers/cron/clear_oauth_token_worker_test.exs [new file with mode: 0644]
test/workers/cron/purge_expired_activities_worker_test.exs [new file with mode: 0644]
test/workers/cron/scheduled_activity_worker_test.exs [new file with mode: 0644]

diff --git a/test/workers/cron/clear_oauth_token_worker_test.exs b/test/workers/cron/clear_oauth_token_worker_test.exs
new file mode 100644 (file)
index 0000000..adea473
--- /dev/null
@@ -0,0 +1,22 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Workers.Cron.ClearOauthTokenWorkerTest do
+  use Pleroma.DataCase
+
+  import Pleroma.Factory
+  alias Pleroma.Workers.Cron.ClearOauthTokenWorker
+
+  clear_config([:oauth2, :clean_expired_tokens])
+
+  test "deletes expired tokens" do
+    insert(:oauth_token,
+      valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), -60 * 10)
+    )
+
+    Pleroma.Config.put([:oauth2, :clean_expired_tokens], true)
+    ClearOauthTokenWorker.perform(:opts, :job)
+    assert Pleroma.Repo.all(Pleroma.Web.OAuth.Token) == []
+  end
+end
diff --git a/test/workers/cron/purge_expired_activities_worker_test.exs b/test/workers/cron/purge_expired_activities_worker_test.exs
new file mode 100644 (file)
index 0000000..07980bc
--- /dev/null
@@ -0,0 +1,34 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Workers.Cron.PurgeExpiredActivitiesWorkerTest do
+  use Pleroma.DataCase
+  alias Pleroma.ActivityExpiration
+  import Pleroma.Factory
+
+  clear_config([ActivityExpiration, :enabled])
+
+  test "deletes an expiration activity" do
+    Pleroma.Config.put([ActivityExpiration, :enabled], true)
+    activity = insert(:note_activity)
+
+    naive_datetime =
+      NaiveDateTime.add(
+        NaiveDateTime.utc_now(),
+        -:timer.minutes(2),
+        :millisecond
+      )
+
+    expiration =
+      insert(
+        :expiration_in_the_past,
+        %{activity_id: activity.id, scheduled_at: naive_datetime}
+      )
+
+    Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
+
+    refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
+    refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
+  end
+end
diff --git a/test/workers/cron/scheduled_activity_worker_test.exs b/test/workers/cron/scheduled_activity_worker_test.exs
new file mode 100644 (file)
index 0000000..6f17d6f
--- /dev/null
@@ -0,0 +1,37 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Workers.Cron.ScheduledActivityWorkerTest do
+  use Pleroma.DataCase
+  alias Pleroma.ScheduledActivity
+  import Pleroma.Factory
+
+  clear_config([ScheduledActivity, :enabled])
+
+  test "creates a status from the scheduled activity" do
+    Pleroma.Config.put([ScheduledActivity, :enabled], true)
+    user = insert(:user)
+
+    naive_datetime =
+      NaiveDateTime.add(
+        NaiveDateTime.utc_now(),
+        -:timer.minutes(2),
+        :millisecond
+      )
+
+    scheduled_activity =
+      insert(
+        :scheduled_activity,
+        scheduled_at: naive_datetime,
+        user: user,
+        params: %{status: "hi"}
+      )
+
+    Pleroma.Workers.Cron.ScheduledActivityWorker.perform(:opts, :pid)
+
+    refute Repo.get(ScheduledActivity, scheduled_activity.id)
+    activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
+    assert Pleroma.Object.normalize(activity).data["content"] == "hi"
+  end
+end