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
10 describe "GET /api/v1/markers" do
11 test "gets markers with correct scopes", %{conn: conn} do
13 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
14 insert_list(7, :notification, user: user, activity: insert(:note_activity))
16 {:ok, %{"notifications" => marker}} =
17 Pleroma.Marker.upsert(
19 %{"notifications" => %{"last_read_id" => "69420"}}
24 |> assign(:user, user)
25 |> assign(:token, token)
26 |> get("/api/v1/markers?timeline[]=notifications")
27 |> json_response_and_validate_schema(200)
31 "last_read_id" => "69420",
32 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
34 "pleroma" => %{"unread_count" => 7}
39 test "gets markers with missed scopes", %{conn: conn} do
41 token = insert(:oauth_token, user: user, scopes: [])
43 Pleroma.Marker.upsert(user, %{"notifications" => %{"last_read_id" => "69420"}})
47 |> assign(:user, user)
48 |> assign(:token, token)
49 |> get("/api/v1/markers", %{timeline: ["notifications"]})
50 |> json_response_and_validate_schema(403)
52 assert response == %{"error" => "Insufficient permissions: read:statuses."}
56 describe "POST /api/v1/markers" do
57 test "creates a marker with correct scopes", %{conn: conn} do
59 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
63 |> assign(:user, user)
64 |> assign(:token, token)
65 |> put_req_header("content-type", "application/json")
66 |> post("/api/v1/markers", %{
67 home: %{last_read_id: "777"},
68 notifications: %{"last_read_id" => "69420"}
70 |> json_response_and_validate_schema(200)
74 "last_read_id" => "69420",
77 "pleroma" => %{"unread_count" => 0}
82 test "updates exist marker", %{conn: conn} do
84 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
86 {:ok, %{"notifications" => marker}} =
87 Pleroma.Marker.upsert(
89 %{"notifications" => %{"last_read_id" => "69477"}}
94 |> assign(:user, user)
95 |> assign(:token, token)
96 |> put_req_header("content-type", "application/json")
97 |> post("/api/v1/markers", %{
98 home: %{last_read_id: "777"},
99 notifications: %{"last_read_id" => "69888"}
101 |> json_response_and_validate_schema(200)
103 assert response == %{
104 "notifications" => %{
105 "last_read_id" => "69888",
106 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
108 "pleroma" => %{"unread_count" => 0}
113 test "creates a marker with missed scopes", %{conn: conn} do
115 token = insert(:oauth_token, user: user, scopes: [])
119 |> assign(:user, user)
120 |> assign(:token, token)
121 |> put_req_header("content-type", "application/json")
122 |> post("/api/v1/markers", %{
123 home: %{last_read_id: "777"},
124 notifications: %{"last_read_id" => "69420"}
126 |> json_response_and_validate_schema(403)
128 assert response == %{"error" => "Insufficient permissions: write:statuses."}