mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-23 06:58:58 +00:00
added tests
This commit is contained in:
parent
d55859f5a4
commit
1403a1441d
22
test/workers/cron/clear_oauth_token_worker_test.exs
Normal file
22
test/workers/cron/clear_oauth_token_worker_test.exs
Normal file
|
@ -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
|
34
test/workers/cron/purge_expired_activities_worker_test.exs
Normal file
34
test/workers/cron/purge_expired_activities_worker_test.exs
Normal file
|
@ -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
|
37
test/workers/cron/scheduled_activity_worker_test.exs
Normal file
37
test/workers/cron/scheduled_activity_worker_test.exs
Normal file
|
@ -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
|
Loading…
Reference in a new issue