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=14f8c3c42cf47cb1971078dc15412e36a698eda3;hpb=e981280fa74ddccb02c7deb27bd5cc5e85f9fc8f;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 14f8c3c42..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 @@ -575,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 @@ -608,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"] == []