aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Verdone <spiral@arcseconds.net>2019-07-22 16:46:20 +0200
committerMike Verdone <spiral@arcseconds.net>2019-07-24 14:45:14 +0200
commit704960b3c135d2e050308c68f5ccf5d7b7df40f8 (patch)
tree85c5e602683014b42147dd582113fafff578c4eb /test
parent378f5f0fbe21c2533719fed9afe8313586fda5d5 (diff)
downloadpleroma-704960b3c135d2e050308c68f5ccf5d7b7df40f8.tar.gz
Add support for activity expiration to common and Masto API
The "expires_at" parameter accepts an ISO8601-formatted date which defines when the activity will expire. At this point the API will not give you any feedback about if your post will expire or not.
Diffstat (limited to 'test')
-rw-r--r--test/support/factory.ex10
-rw-r--r--test/web/common_api/common_api_test.exs17
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs19
3 files changed, 42 insertions, 4 deletions
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 7b52b1328..63fe3a66d 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -143,12 +143,14 @@ defmodule Pleroma.Factory do
end
defp expiration_offset_by_minutes(attrs, minutes) do
+ scheduled_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.minutes(minutes), :millisecond)
+ |> NaiveDateTime.truncate(:second)
+
%Pleroma.ActivityExpiration{}
|> Map.merge(attrs)
- |> Map.put(
- :scheduled_at,
- NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(minutes), :millisecond)
- )
+ |> Map.put(:scheduled_at, scheduled_at)
end
def expiration_in_the_past_factory(attrs \\ %{}) do
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 16b3f121d..210314a4a 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -160,6 +160,23 @@ defmodule Pleroma.Web.CommonAPITest do
Pleroma.Config.put([:instance, :limit], limit)
end
+
+ test "it can handle activities that expire" do
+ user = insert(:user)
+
+ expires_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.truncate(:second)
+ |> NaiveDateTime.add(1_000_000, :second)
+
+ expires_at_iso8601 = expires_at |> NaiveDateTime.to_iso8601()
+
+ assert {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "chai", "expires_at" => expires_at_iso8601})
+
+ assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
+ assert expiration.scheduled_at == expires_at
+ end
end
describe "reactions" do
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b5279412f..24482a4a2 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Ecto.Changeset
alias Pleroma.Activity
+ alias Pleroma.ActivityExpiration
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
@@ -151,6 +152,24 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => third_id} = json_response(conn_three, 200)
refute id == third_id
+
+ # An activity that will expire:
+ expires_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.minutes(120), :millisecond)
+ |> NaiveDateTime.truncate(:second)
+
+ conn_four =
+ conn
+ |> post("api/v1/statuses", %{
+ "status" => "oolong",
+ "expires_at" => expires_at
+ })
+
+ assert %{"id" => fourth_id} = json_response(conn_four, 200)
+ assert activity = Activity.get_by_id(fourth_id)
+ assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
+ assert expiration.scheduled_at == expires_at
end
test "replying to a status", %{conn: conn} do