Merge branch 'develop' into 'feature/2164-unify-api-arguments'
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
cd5ff7a943
12 changed files with 168 additions and 7 deletions
|
|
@ -47,6 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
assert result["pleroma"]["metadata"]["federation"]
|
||||
assert result["pleroma"]["metadata"]["fields_limits"]
|
||||
assert result["pleroma"]["vapid_public_key"]
|
||||
assert result["pleroma"]["stats"]["mau"] == 0
|
||||
|
||||
assert email == from_config_email
|
||||
assert thumbnail == from_config_thumbnail
|
||||
|
|
|
|||
|
|
@ -263,6 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
fake_conn =
|
||||
conn
|
||||
|> assign(:user, refresh_record(conn.assigns.user))
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" =>
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
|
|||
[participation] = Participation.for_user(user)
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
|
||||
assert user in participation.recipients
|
||||
assert refresh_record(user) in participation.recipients
|
||||
assert other_user in participation.recipients
|
||||
end
|
||||
|
||||
|
|
|
|||
58
test/pleroma/web/plugs/user_tracking_plug_test.exs
Normal file
58
test/pleroma/web/plugs/user_tracking_plug_test.exs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.UserTrackingPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.Plugs.UserTrackingPlug
|
||||
|
||||
test "updates last_active_at for a new user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
assert is_nil(user.last_active_at)
|
||||
|
||||
test_started_at = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert user.last_active_at >= test_started_at
|
||||
assert user.last_active_at <= NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
||||
end
|
||||
|
||||
test "doesn't update last_active_at if it was updated recently", %{conn: conn} do
|
||||
last_active_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(-:timer.hours(1), :millisecond)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
user = insert(:user, %{last_active_at: last_active_at})
|
||||
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert user.last_active_at == last_active_at
|
||||
end
|
||||
|
||||
test "skips updating last_active_at if user ID is nil", %{conn: conn} do
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, %Pleroma.User{})
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert is_nil(user.last_active_at)
|
||||
end
|
||||
|
||||
test "does nothing if user is not present", %{conn: conn} do
|
||||
%{assigns: assigns} = UserTrackingPlug.call(conn, %{})
|
||||
|
||||
refute Map.has_key?(assigns, :user)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue