1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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", "unread_count" => 7}}
23 |> assign(:user, user)
24 |> assign(:token, token)
25 |> get("/api/v1/markers", %{timeline: ["notifications"]})
30 "last_read_id" => "69420",
32 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
38 test "gets markers with missed scopes", %{conn: conn} do
40 token = insert(:oauth_token, user: user, scopes: [])
42 Pleroma.Marker.upsert(user, %{"notifications" => %{"last_read_id" => "69420"}})
46 |> assign(:user, user)
47 |> assign(:token, token)
48 |> get("/api/v1/markers", %{timeline: ["notifications"]})
51 assert response == %{"error" => "Insufficient permissions: read:statuses."}
55 describe "POST /api/v1/markers" do
56 test "creates a marker with correct scopes", %{conn: conn} do
58 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
62 |> assign(:user, user)
63 |> assign(:token, token)
64 |> post("/api/v1/markers", %{
65 home: %{last_read_id: "777"},
66 notifications: %{"last_read_id" => "69420"}
72 "last_read_id" => "69420",
80 test "updates exist marker", %{conn: conn} do
82 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
84 {:ok, %{"notifications" => marker}} =
85 Pleroma.Marker.upsert(
87 %{"notifications" => %{"last_read_id" => "69477"}}
92 |> assign(:user, user)
93 |> assign(:token, token)
94 |> post("/api/v1/markers", %{
95 home: %{last_read_id: "777"},
96 notifications: %{"last_read_id" => "69888"}
100 assert response == %{
101 "notifications" => %{
102 "last_read_id" => "69888",
104 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
110 test "creates a marker with missed scopes", %{conn: conn} do
112 token = insert(:oauth_token, user: user, scopes: [])
116 |> assign(:user, user)
117 |> assign(:token, token)
118 |> post("/api/v1/markers", %{
119 home: %{last_read_id: "777"},
120 notifications: %{"last_read_id" => "69420"}
122 |> json_response(403)
124 assert response == %{"error" => "Insufficient permissions: write:statuses."}