summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml3
-rw-r--r--changelog.d/ci-git-fetch.skip0
-rw-r--r--changelog.d/fix-test-failures.skip0
-rw-r--r--changelog.d/notifications-marker.change1
-rw-r--r--lib/mix/tasks/pleroma/test_runner.ex25
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/marker_controller.ex10
-rw-r--r--test/mix/tasks/pleroma/uploads_test.exs17
-rw-r--r--test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs35
8 files changed, 63 insertions, 28 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index eaa9d3b25..1e04dae76 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,6 +9,7 @@ variables: &global_variables
DB_HOST: postgres
DB_PORT: "5432"
MIX_ENV: test
+ GIT_STRATEGY: fetch
workflow:
rules:
@@ -133,7 +134,7 @@ unit-testing-1.13.4-otp-25:
script: &testing_script
- mix ecto.create
- mix ecto.migrate
- - mix pleroma.test_runner --cover --preload-modules
+ - mix test --cover --preload-modules
coverage: '/^Line total: ([^ ]*%)$/'
artifacts:
reports:
diff --git a/changelog.d/ci-git-fetch.skip b/changelog.d/ci-git-fetch.skip
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/changelog.d/ci-git-fetch.skip
diff --git a/changelog.d/fix-test-failures.skip b/changelog.d/fix-test-failures.skip
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/changelog.d/fix-test-failures.skip
diff --git a/changelog.d/notifications-marker.change b/changelog.d/notifications-marker.change
new file mode 100644
index 000000000..9e350a95c
--- /dev/null
+++ b/changelog.d/notifications-marker.change
@@ -0,0 +1 @@
+Fix 'Setting a marker should mark notifications as read' \ No newline at end of file
diff --git a/lib/mix/tasks/pleroma/test_runner.ex b/lib/mix/tasks/pleroma/test_runner.ex
deleted file mode 100644
index 69fefb001..000000000
--- a/lib/mix/tasks/pleroma/test_runner.ex
+++ /dev/null
@@ -1,25 +0,0 @@
-defmodule Mix.Tasks.Pleroma.TestRunner do
- @shortdoc "Retries tests once if they fail"
-
- use Mix.Task
-
- def run(args \\ []) do
- case System.cmd("mix", ["test"] ++ args, into: IO.stream(:stdio, :line)) do
- {_, 0} ->
- :ok
-
- _ ->
- retry(args)
- end
- end
-
- def retry(args) do
- case System.cmd("mix", ["test", "--failed"] ++ args, into: IO.stream(:stdio, :line)) do
- {_, 0} ->
- :ok
-
- _ ->
- exit(1)
- end
- end
-end
diff --git a/lib/pleroma/web/mastodon_api/controllers/marker_controller.ex b/lib/pleroma/web/mastodon_api/controllers/marker_controller.ex
index 4ad30f330..42b2a201d 100644
--- a/lib/pleroma/web/mastodon_api/controllers/marker_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/marker_controller.ex
@@ -4,6 +4,7 @@
defmodule Pleroma.Web.MastodonAPI.MarkerController do
use Pleroma.Web, :controller
+
alias Pleroma.Web.Plugs.OAuthScopesPlug
plug(Pleroma.Web.ApiSpec.CastAndValidate)
@@ -30,9 +31,16 @@ defmodule Pleroma.Web.MastodonAPI.MarkerController do
def upsert(%{assigns: %{user: user}, body_params: params} = conn, _) do
params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
- with {:ok, result} <- Pleroma.Marker.upsert(user, params),
+ with {:ok, _} <- mark_notifications_read(user, params),
+ {:ok, result} <- Pleroma.Marker.upsert(user, params),
markers <- Map.values(result) do
render(conn, "markers.json", %{markers: markers})
end
end
+
+ defp mark_notifications_read(user, %{"notifications" => %{last_read_id: last_read_id}}) do
+ Pleroma.Notification.set_read_up_to(user, last_read_id)
+ end
+
+ defp mark_notifications_read(_, _), do: {:ok, :noop}
end
diff --git a/test/mix/tasks/pleroma/uploads_test.exs b/test/mix/tasks/pleroma/uploads_test.exs
index d4ea89501..f3d5aa64f 100644
--- a/test/mix/tasks/pleroma/uploads_test.exs
+++ b/test/mix/tasks/pleroma/uploads_test.exs
@@ -3,12 +3,14 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UploadsTest do
+ alias Pleroma.Config
alias Pleroma.Upload
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: false
import Mock
setup_all do
+ prep_uploads()
Mix.shell(Mix.Shell.Process)
on_exit(fn ->
@@ -18,6 +20,8 @@ defmodule Mix.Tasks.Pleroma.UploadsTest do
:ok
end
+ setup do: clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
+
describe "running migrate_local" do
test "uploads migrated" do
with_mock Upload,
@@ -53,4 +57,15 @@ defmodule Mix.Tasks.Pleroma.UploadsTest do
end
end
end
+
+ defp prep_uploads do
+ upload_dir = Config.get([Pleroma.Uploaders.Local, :uploads])
+
+ if not File.exists?(upload_dir) || File.ls!(upload_dir) == [] do
+ File.mkdir_p(upload_dir)
+
+ Path.join([upload_dir, "file.txt"])
+ |> File.touch()
+ end
+ end
end
diff --git a/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
index d8f7b2638..4050528ff 100644
--- a/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs
@@ -5,6 +5,10 @@
defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
use Pleroma.Web.ConnCase, async: true
+ alias Pleroma.Notification
+ alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
+
import Pleroma.Factory
describe "GET /api/v1/markers" do
@@ -127,5 +131,36 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
assert response == %{"error" => "Insufficient permissions: write:statuses."}
end
+
+ test "marks notifications as read", %{conn: conn} do
+ user1 = insert(:user)
+ token = insert(:oauth_token, user: user1, scopes: ["write:statuses"])
+
+ user2 = insert(:user)
+ {:ok, _activity1} = CommonAPI.post(user2, %{status: "hi @#{user1.nickname}"})
+ {:ok, _activity2} = CommonAPI.post(user2, %{status: "hi @#{user1.nickname}"})
+ {:ok, _activity3} = CommonAPI.post(user2, %{status: "HIE @#{user1.nickname}"})
+
+ [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
+
+ refute Repo.get(Notification, notification1.id).seen
+ refute Repo.get(Notification, notification2.id).seen
+ refute Repo.get(Notification, notification3.id).seen
+
+ conn
+ |> assign(:user, user1)
+ |> assign(:token, token)
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/markers", %{
+ notifications: %{last_read_id: to_string(notification2.id)}
+ })
+ |> json_response_and_validate_schema(200)
+
+ [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
+
+ assert Repo.get(Notification, notification1.id).seen
+ assert Repo.get(Notification, notification2.id).seen
+ refute Repo.get(Notification, notification3.id).seen
+ end
end
end