1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
6 use Pleroma.Web.ConnCase
7 alias Pleroma.Web.ApiSpec
10 import OpenApiSpex.TestAssertions
12 describe "GET /api/v1/markers" do
13 test "gets markers with correct scopes", %{conn: conn} do
15 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
17 {:ok, %{"notifications" => marker}} =
18 Pleroma.Marker.upsert(
20 %{"notifications" => %{"last_read_id" => "69420"}}
25 |> assign(:user, user)
26 |> assign(:token, token)
27 |> get("/api/v1/markers?timeline[]=notifications")
32 "last_read_id" => "69420",
33 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
38 assert_schema(response, "MarkersResponse", ApiSpec.spec())
41 test "gets markers with missed scopes", %{conn: conn} do
43 token = insert(:oauth_token, user: user, scopes: [])
45 Pleroma.Marker.upsert(user, %{"notifications" => %{"last_read_id" => "69420"}})
49 |> assign(:user, user)
50 |> assign(:token, token)
51 |> get("/api/v1/markers", %{timeline: ["notifications"]})
54 assert response == %{"error" => "Insufficient permissions: read:statuses."}
58 describe "POST /api/v1/markers" do
59 test "creates a marker with correct scopes", %{conn: conn} do
61 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
65 |> assign(:user, user)
66 |> assign(:token, token)
67 |> put_req_header("content-type", "application/json")
68 |> post("/api/v1/markers", %{
69 home: %{last_read_id: "777"},
70 notifications: %{"last_read_id" => "69420"}
76 "last_read_id" => "69420",
82 assert_schema(response, "MarkersResponse", ApiSpec.spec())
85 test "updates exist marker", %{conn: conn} do
87 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
89 {:ok, %{"notifications" => marker}} =
90 Pleroma.Marker.upsert(
92 %{"notifications" => %{"last_read_id" => "69477"}}
97 |> assign(:user, user)
98 |> assign(:token, token)
99 |> put_req_header("content-type", "application/json")
100 |> post("/api/v1/markers", %{
101 home: %{last_read_id: "777"},
102 notifications: %{"last_read_id" => "69888"}
104 |> json_response(200)
106 assert response == %{
107 "notifications" => %{
108 "last_read_id" => "69888",
109 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
114 assert_schema(response, "MarkersResponse", ApiSpec.spec())
117 test "creates a marker with missed scopes", %{conn: conn} do
119 token = insert(:oauth_token, user: user, scopes: [])
123 |> assign(:user, user)
124 |> assign(:token, token)
125 |> post("/api/v1/markers", %{
126 home: %{last_read_id: "777"},
127 notifications: %{"last_read_id" => "69420"}
129 |> json_response(403)
131 assert response == %{"error" => "Insufficient permissions: write:statuses."}