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"])
15 {:ok, %{"notifications" => marker}} =
16 Pleroma.Marker.upsert(
18 %{"notifications" => %{"last_read_id" => "69420"}}
23 |> assign(:user, user)
24 |> assign(:token, token)
25 |> get("/api/v1/markers", %{timeline: ["notifications"]})
30 "last_read_id" => "69420",
31 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
37 test "gets markers with missed scopes", %{conn: conn} do
39 token = insert(:oauth_token, user: user, scopes: [])
41 Pleroma.Marker.upsert(user, %{"notifications" => %{"last_read_id" => "69420"}})
45 |> assign(:user, user)
46 |> assign(:token, token)
47 |> get("/api/v1/markers", %{timeline: ["notifications"]})
50 assert response == %{"error" => "Insufficient permissions: read:statuses."}
54 describe "POST /api/v1/markers" do
55 test "creates a marker with correct scopes", %{conn: conn} do
57 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
61 |> assign(:user, user)
62 |> assign(:token, token)
63 |> post("/api/v1/markers", %{
64 home: %{last_read_id: "777"},
65 notifications: %{"last_read_id" => "69420"}
71 "last_read_id" => "69420",
78 test "updates exist marker", %{conn: conn} do
80 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
82 {:ok, %{"notifications" => marker}} =
83 Pleroma.Marker.upsert(
85 %{"notifications" => %{"last_read_id" => "69477"}}
90 |> assign(:user, user)
91 |> assign(:token, token)
92 |> post("/api/v1/markers", %{
93 home: %{last_read_id: "777"},
94 notifications: %{"last_read_id" => "69888"}
100 "last_read_id" => "69888",
101 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
107 test "creates a marker with missed scopes", %{conn: conn} do
109 token = insert(:oauth_token, user: user, scopes: [])
113 |> assign(:user, user)
114 |> assign(:token, token)
115 |> post("/api/v1/markers", %{
116 home: %{last_read_id: "777"},
117 notifications: %{"last_read_id" => "69420"}
119 |> json_response(403)
121 assert response == %{"error" => "Insufficient permissions: write:statuses."}