From: Maksim Pechnikov Date: Mon, 13 Jan 2020 09:41:07 +0000 (+0300) Subject: Merge branch 'develop' into issue/1383 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=b7908844f24f4ede4244261d43f30ed3724efbb7;p=akkoma Merge branch 'develop' into issue/1383 --- b7908844f24f4ede4244261d43f30ed3724efbb7 diff --cc config/config.exs index bbd8f7d78,d41abf090..8b8ecc833 --- a/config/config.exs +++ b/config/config.exs @@@ -51,9 -51,23 +51,9 @@@ config :pleroma, Pleroma.Repo telemetry_event: [Pleroma.Repo.Instrumenter], migration_lock: nil -scheduled_jobs = - with digest_config <- Application.get_env(:pleroma, :email_notifications)[:digest], - true <- digest_config[:active] do - [{digest_config[:schedule], {Pleroma.Daemons.DigestEmailDaemon, :perform, []}}] - else - _ -> [] - end - -config :pleroma, Pleroma.Scheduler, - global: true, - overlap: true, - timezone: :utc, - jobs: scheduled_jobs - config :pleroma, Pleroma.Captcha, enabled: true, - seconds_valid: 60, + seconds_valid: 300, method: Pleroma.Captcha.Native config :pleroma, Pleroma.Captcha.Kocaptcha, endpoint: "https://captcha.kotobank.ch" diff --cc test/web/mastodon_api/controllers/scheduled_activity_controller_test.exs index 478631a12,9666a7f2e..6317d1b47 --- a/test/web/mastodon_api/controllers/scheduled_activity_controller_test.exs +++ b/test/web/mastodon_api/controllers/scheduled_activity_controller_test.exs @@@ -9,12 -9,10 +9,13 @@@ defmodule Pleroma.Web.MastodonAPI.Sched alias Pleroma.ScheduledActivity import Pleroma.Factory + import Ecto.Query + + clear_config([ScheduledActivity, :enabled]) - test "shows scheduled activities", %{conn: conn} do - user = insert(:user) + test "shows scheduled activities" do + %{user: user, conn: conn} = oauth_access(["read:statuses"]) + scheduled_activity_id1 = insert(:scheduled_activity, user: user).id |> to_string() scheduled_activity_id2 = insert(:scheduled_activity, user: user).id |> to_string() scheduled_activity_id3 = insert(:scheduled_activity, user: user).id |> to_string() @@@ -69,81 -51,29 +54,61 @@@ assert %{"error" => "Record not found"} = json_response(res_conn, 404) end - test "updates a scheduled activity", %{conn: conn} do + test "updates a scheduled activity" do + Pleroma.Config.put([ScheduledActivity, :enabled], true) - user = insert(:user) + %{user: user, conn: conn} = oauth_access(["write:statuses"]) - scheduled_activity = insert(:scheduled_activity, user: user) - scheduled_at = - NaiveDateTime.add( - NaiveDateTime.utc_now(), - :timer.minutes(60), - :millisecond - ) - new_scheduled_at = - NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond) ++ scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60) + + {:ok, scheduled_activity} = + ScheduledActivity.create( + user, + %{ + scheduled_at: scheduled_at, + params: build(:note).data + } + ) + - scheduled_activity_job = - Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities")) ++ job = Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities")) + - assert scheduled_activity_job.args == %{"activity_id" => scheduled_activity.id} ++ assert job.args == %{"activity_id" => scheduled_activity.id} ++ assert DateTime.truncate(job.scheduled_at, :second) == to_datetime(scheduled_at) + - assert DateTime.truncate(scheduled_activity_job.scheduled_at, :second) == - to_datetime(scheduled_at) - - new_scheduled_at = - NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond) ++ new_scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 120) res_conn = - conn - |> assign(:user, user) - |> put("/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{ + put(conn, "/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{ scheduled_at: new_scheduled_at }) assert %{"scheduled_at" => expected_scheduled_at} = json_response(res_conn, 200) assert expected_scheduled_at == Pleroma.Web.CommonAPI.Utils.to_masto_date(new_scheduled_at) - scheduled_activity_job = refresh_record(scheduled_activity_job) ++ job = refresh_record(job) + - assert DateTime.truncate(scheduled_activity_job.scheduled_at, :second) == - to_datetime(new_scheduled_at) ++ assert DateTime.truncate(job.scheduled_at, :second) == to_datetime(new_scheduled_at) - res_conn = - conn - |> assign(:user, user) - |> put("/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at}) + res_conn = put(conn, "/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at}) assert %{"error" => "Record not found"} = json_response(res_conn, 404) end - test "deletes a scheduled activity", %{conn: conn} do + test "deletes a scheduled activity" do + Pleroma.Config.put([ScheduledActivity, :enabled], true) - user = insert(:user) + %{user: user, conn: conn} = oauth_access(["write:statuses"]) - scheduled_activity = insert(:scheduled_activity, user: user) ++ scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60) + + {:ok, scheduled_activity} = + ScheduledActivity.create( + user, + %{ - scheduled_at: - NaiveDateTime.add( - NaiveDateTime.utc_now(), - :timer.minutes(60), - :millisecond - ), ++ scheduled_at: scheduled_at, + params: build(:note).data + } + ) + - scheduled_activity_job = - Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities")) ++ job = Repo.one(from(j in Oban.Job, where: j.queue == "scheduled_activities")) + - assert scheduled_activity_job.args == %{"activity_id" => scheduled_activity.id} ++ assert job.args == %{"activity_id" => scheduled_activity.id} res_conn = conn @@@ -151,8 -81,7 +116,8 @@@ |> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}") assert %{} = json_response(res_conn, 200) - assert nil == Repo.get(ScheduledActivity, scheduled_activity.id) + refute Repo.get(ScheduledActivity, scheduled_activity.id) - refute Repo.get(Oban.Job, scheduled_activity_job.id) ++ refute Repo.get(Oban.Job, job.id) res_conn = conn diff --cc test/web/twitter_api/util_controller_test.exs index 43299e147,8418fd071..5d60c0d51 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@@ -6,11 -6,11 +6,9 @@@ defmodule Pleroma.Web.TwitterAPI.UtilCo use Pleroma.Web.ConnCase use Oban.Testing, repo: Pleroma.Repo - alias Pleroma.Repo alias Pleroma.Tests.ObanHelpers alias Pleroma.User -- alias Pleroma.Web.CommonAPI - import ExUnit.CaptureLog + - import ExUnit.CaptureLog import Pleroma.Factory import Mock