X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fmastodon_api%2Fmastodon_api_controller_test.exs;h=7f6c9fb88c6f6ba0ded890a0c51230da9cb01c28;hb=380e9fba21123467b41629828f97d5f2c257a128;hp=aec0f851cf2717fe1ea35fc0a61553ef9acc44f7;hpb=52ac7dce5c460d27d946d26070eb123e89af2914;p=akkoma diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index aec0f851c..7f6c9fb88 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do use Pleroma.Web.ConnCase @@ -292,7 +296,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert %{} = json_response(conn, 200) - assert Repo.get(Activity, activity.id) == nil + refute Repo.get(Activity, activity.id) end test "when you didn't create it", %{conn: conn} do @@ -836,6 +840,26 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert [%{"id" => id}] = json_response(conn, 200) assert id == to_string(image_post.id) end + + test "gets a user's statuses without reblogs", %{conn: conn} do + user = insert(:user) + {:ok, post} = CommonAPI.post(user, %{"status" => "HI!!!"}) + {:ok, _, _} = CommonAPI.repeat(post.id, user) + + conn = + conn + |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "true"}) + + assert [%{"id" => id}] = json_response(conn, 200) + assert id == to_string(post.id) + + conn = + conn + |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "1"}) + + assert [%{"id" => id}] = json_response(conn, 200) + assert id == to_string(post.id) + end end describe "user relationships" do @@ -1429,4 +1453,99 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do user = User.get_cached_by_ap_id(user.ap_id) assert user.info.settings == %{"programming" => "socks"} end + + describe "pinned posts" do + test "returns pinned posts", %{conn: conn} do + Pleroma.Config.put([:instance, :max_pinned_posts], 1) + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"}) + {:ok, _} = CommonAPI.pin(activity.id, user) + + result = + conn + |> assign(:user, user) + |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true") + |> Map.get(:resp_body) + |> Jason.decode!() + + id_str = Integer.to_string(activity.id) + + assert [%{"id" => ^id_str}] = result + end + + test "pin post", %{conn: conn} do + Pleroma.Config.put([:instance, :max_pinned_posts], 1) + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"}) + id_str = Integer.to_string(activity.id) + + assert %{"id" => ^id_str} = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/pin") + |> Map.get(:resp_body) + |> Jason.decode!() + + assert [%{"id" => ^id_str}] = + conn + |> assign(:user, user) + |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true") + |> Map.get(:resp_body) + |> Jason.decode!() + end + + test "unpin post", %{conn: conn} do + Pleroma.Config.put([:instance, :max_pinned_posts], 1) + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"}) + {:ok, _} = CommonAPI.pin(activity.id, user) + + id_str = Integer.to_string(activity.id) + user = User.get_by_ap_id(user.ap_id) + + assert %{"id" => ^id_str} = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/unpin") + |> Map.get(:resp_body) + |> Jason.decode!() + + assert [] = + conn + |> assign(:user, user) + |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true") + |> Map.get(:resp_body) + |> Jason.decode!() + end + + test "max pinned posts", %{conn: conn} do + Pleroma.Config.put([:instance, :max_pinned_posts], 1) + + user = insert(:user) + + {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"}) + {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"}) + + id_str_one = Integer.to_string(activity_one.id) + + assert %{"id" => ^id_str_one} = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{id_str_one}/pin") + |> Map.get(:resp_body) + |> Jason.decode!() + + user = User.get_by_ap_id(user.ap_id) + + assert %{"error" => "You have already pinned the maximum number of toots"} = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity_two.id}/pin") + |> Map.get(:resp_body) + |> Jason.decode!() + end + end end