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)
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"]})
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"]})
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 |> post("/api/v1/markers", %{
66 home: %{last_read_id: "777"},
67 notifications: %{"last_read_id" => "69420"}
73 "last_read_id" => "69420",
76 "pleroma" => %{"unread_count" => 0}
81 test "updates exist marker", %{conn: conn} do
83 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
85 {:ok, %{"notifications" => marker}} =
86 Pleroma.Marker.upsert(
88 %{"notifications" => %{"last_read_id" => "69477"}}
93 |> assign(:user, user)
94 |> assign(:token, token)
95 |> post("/api/v1/markers", %{
96 home: %{last_read_id: "777"},
97 notifications: %{"last_read_id" => "69888"}
101 assert response == %{
102 "notifications" => %{
103 "last_read_id" => "69888",
104 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
106 "pleroma" => %{"unread_count" => 0}
111 test "creates a marker with missed scopes", %{conn: conn} do
113 token = insert(:oauth_token, user: user, scopes: [])
117 |> assign(:user, user)
118 |> assign(:token, token)
119 |> post("/api/v1/markers", %{
120 home: %{last_read_id: "777"},
121 notifications: %{"last_read_id" => "69420"}
123 |> json_response(403)
125 assert response == %{"error" => "Insufficient permissions: write:statuses."}