X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fmastodon_api%2Fmastodon_api_controller_test.exs;h=8d79c96b1d558a329df2dfac7fb870716af7c141;hb=8b0c222b436d9473f868087fb4eaf78a0b1e7052;hp=5d39c25c617540f32719e80ea894989efbb42628;hpb=6ff583e5e10e59fe76cb51ce3d04587307af9eae;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 5d39c25c6..8d79c96b1 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -63,19 +63,53 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do test "posting a status", %{conn: conn} do user = insert(:user) - conn = + idempotency_key = "Pikachu rocks!" + + conn_one = conn |> assign(:user, user) + |> put_req_header("idempotency-key", idempotency_key) |> post("/api/v1/statuses", %{ "status" => "cofe", "spoiler_text" => "2hu", "sensitive" => "false" }) + {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key) + # Six hours + assert ttl > :timer.seconds(6 * 60 * 60 - 1) + assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} = - json_response(conn, 200) + json_response(conn_one, 200) assert Repo.get(Activity, id) + + conn_two = + conn + |> assign(:user, user) + |> put_req_header("idempotency-key", idempotency_key) + |> post("/api/v1/statuses", %{ + "status" => "cofe", + "spoiler_text" => "2hu", + "sensitive" => "false" + }) + + assert %{"id" => second_id} = json_response(conn_two, 200) + + assert id == second_id + + conn_three = + conn + |> assign(:user, user) + |> post("/api/v1/statuses", %{ + "status" => "cofe", + "spoiler_text" => "2hu", + "sensitive" => "false" + }) + + assert %{"id" => third_id} = json_response(conn_three, 200) + + refute id == third_id end test "posting a sensitive status", %{conn: conn} do @@ -264,6 +298,24 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do end end + describe "unreblogging" do + test "unreblogs and returns the unreblogged status", %{conn: conn} do + activity = insert(:note_activity) + user = insert(:user) + + {:ok, _, _} = CommonAPI.repeat(activity.id, user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/unreblog") + + assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200) + + assert to_string(activity.id) == id + end + end + describe "favoriting" do test "favs a status and returns it", %{conn: conn} do activity = insert(:note_activity) @@ -316,6 +368,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert id == to_string(note_two.id) end + test "unimplemented pinned statuses feature", %{conn: conn} do + note = insert(:note_activity) + user = User.get_by_ap_id(note.data["actor"]) + + conn = + conn + |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true") + + assert json_response(conn, 200) == [] + end + test "gets an users media", %{conn: conn} do note = insert(:note_activity) user = User.get_by_ap_id(note.data["actor"]) @@ -546,16 +609,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do test "account search", %{conn: conn} do user = insert(:user) - _user_two = insert(:user, %{nickname: "shp@shitposter.club"}) + user_two = insert(:user, %{nickname: "shp@shitposter.club"}) user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) - conn = + results = + conn + |> assign(:user, user) + |> get("/api/v1/accounts/search", %{"q" => "shp"}) + |> json_response(200) + + result_ids = for result <- results, do: result["acct"] + + assert user_two.nickname in result_ids + assert user_three.nickname in result_ids + + results = conn |> assign(:user, user) |> get("/api/v1/accounts/search", %{"q" => "2hu"}) + |> json_response(200) - assert [account] = json_response(conn, 200) - assert account["id"] == to_string(user_three.id) + result_ids = for result <- results, do: result["acct"] + + assert user_three.nickname in result_ids end test "search", %{conn: conn} do @@ -579,7 +655,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert results = json_response(conn, 200) - [account] = results["accounts"] + [account | _] = results["accounts"] assert account["id"] == to_string(user_three.id) assert results["hashtags"] == []