2019-09-27 08:35:45 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
2019-11-20 08:25:00 +01:00
|
|
|
use Pleroma.Web.ConnCase
|
2019-09-27 08:35:45 +02:00
|
|
|
|
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.ScheduledActivity
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
test "shows scheduled activities" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
|
|
|
|
2019-09-27 08:35:45 +02:00
|
|
|
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()
|
|
|
|
scheduled_activity_id4 = insert(:scheduled_activity, user: user).id |> to_string()
|
|
|
|
|
|
|
|
# min_id
|
2019-12-19 15:23:27 +01:00
|
|
|
conn_res = get(conn, "/api/v1/scheduled_statuses?limit=2&min_id=#{scheduled_activity_id1}")
|
2019-09-27 08:35:45 +02:00
|
|
|
|
|
|
|
result = json_response(conn_res, 200)
|
|
|
|
assert [%{"id" => ^scheduled_activity_id3}, %{"id" => ^scheduled_activity_id2}] = result
|
|
|
|
|
|
|
|
# since_id
|
2019-12-19 15:23:27 +01:00
|
|
|
conn_res = get(conn, "/api/v1/scheduled_statuses?limit=2&since_id=#{scheduled_activity_id1}")
|
2019-09-27 08:35:45 +02:00
|
|
|
|
|
|
|
result = json_response(conn_res, 200)
|
|
|
|
assert [%{"id" => ^scheduled_activity_id4}, %{"id" => ^scheduled_activity_id3}] = result
|
|
|
|
|
|
|
|
# max_id
|
2019-12-19 15:23:27 +01:00
|
|
|
conn_res = get(conn, "/api/v1/scheduled_statuses?limit=2&max_id=#{scheduled_activity_id4}")
|
2019-09-27 08:35:45 +02:00
|
|
|
|
|
|
|
result = json_response(conn_res, 200)
|
|
|
|
assert [%{"id" => ^scheduled_activity_id3}, %{"id" => ^scheduled_activity_id2}] = result
|
|
|
|
end
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
test "shows a scheduled activity" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
2019-09-27 08:35:45 +02:00
|
|
|
scheduled_activity = insert(:scheduled_activity, user: user)
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
res_conn = get(conn, "/api/v1/scheduled_statuses/#{scheduled_activity.id}")
|
2019-09-27 08:35:45 +02:00
|
|
|
|
|
|
|
assert %{"id" => scheduled_activity_id} = json_response(res_conn, 200)
|
|
|
|
assert scheduled_activity_id == scheduled_activity.id |> to_string()
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
res_conn = get(conn, "/api/v1/scheduled_statuses/404")
|
2019-09-27 08:35:45 +02:00
|
|
|
|
|
|
|
assert %{"error" => "Record not found"} = json_response(res_conn, 404)
|
|
|
|
end
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
test "updates a scheduled activity" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
2019-09-27 08:35:45 +02:00
|
|
|
scheduled_activity = insert(:scheduled_activity, user: user)
|
|
|
|
|
|
|
|
new_scheduled_at =
|
|
|
|
NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
|
|
|
|
|
|
|
|
res_conn =
|
2019-12-19 15:23:27 +01:00
|
|
|
put(conn, "/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{
|
2019-09-27 08:35:45 +02:00
|
|
|
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)
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
res_conn = put(conn, "/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at})
|
2019-09-27 08:35:45 +02:00
|
|
|
|
|
|
|
assert %{"error" => "Record not found"} = json_response(res_conn, 404)
|
|
|
|
end
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
test "deletes a scheduled activity" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
2019-09-27 08:35:45 +02:00
|
|
|
scheduled_activity = insert(:scheduled_activity, user: user)
|
|
|
|
|
|
|
|
res_conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
|
|
|
|
|
|
|
|
assert %{} = json_response(res_conn, 200)
|
|
|
|
assert nil == Repo.get(ScheduledActivity, scheduled_activity.id)
|
|
|
|
|
|
|
|
res_conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
|
|
|
|
|
|
|
|
assert %{"error" => "Record not found"} = json_response(res_conn, 404)
|
|
|
|
end
|
|
|
|
end
|