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")
26 |> json_response_and_validate_schema(200)
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"]})
48 |> json_response_and_validate_schema(403)
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 |> put_req_header("content-type", "application/json")
64 |> post("/api/v1/markers", %{
65 home: %{last_read_id: "777"},
66 notifications: %{"last_read_id" => "69420"}
68 |> json_response_and_validate_schema(200)
72 "last_read_id" => "69420",
79 test "updates exist marker", %{conn: conn} do
81 token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
83 {:ok, %{"notifications" => marker}} =
84 Pleroma.Marker.upsert(
86 %{"notifications" => %{"last_read_id" => "69477"}}
91 |> assign(:user, user)
92 |> assign(:token, token)
93 |> put_req_header("content-type", "application/json")
94 |> post("/api/v1/markers", %{
95 home: %{last_read_id: "777"},
96 notifications: %{"last_read_id" => "69888"}
98 |> json_response_and_validate_schema(200)
100 assert response == %{
101 "notifications" => %{
102 "last_read_id" => "69888",
103 "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
109 test "creates a marker with missed scopes", %{conn: conn} do
111 token = insert(:oauth_token, user: user, scopes: [])
115 |> assign(:user, user)
116 |> assign(:token, token)
117 |> put_req_header("content-type", "application/json")
118 |> post("/api/v1/markers", %{
119 home: %{last_read_id: "777"},
120 notifications: %{"last_read_id" => "69420"}
122 |> json_response_and_validate_schema(403)
124 assert response == %{"error" => "Insufficient permissions: write:statuses."}