api/masto/marker: fix datetime format for updated_at
Some checks failed
ci/woodpecker/push/docs Pipeline is pending
ci/woodpecker/push/publish/1 Pipeline is pending
ci/woodpecker/push/publish/2 Pipeline is pending
ci/woodpecker/push/publish/4 Pipeline is pending
ci/woodpecker/pr/test/2 Pipeline was successful
ci/woodpecker/pr/test/1 Pipeline failed
Some checks failed
ci/woodpecker/push/docs Pipeline is pending
ci/woodpecker/push/publish/1 Pipeline is pending
ci/woodpecker/push/publish/2 Pipeline is pending
ci/woodpecker/push/publish/4 Pipeline is pending
ci/woodpecker/pr/test/2 Pipeline was successful
ci/woodpecker/pr/test/1 Pipeline failed
Ref: https://docs.joinmastodon.org/api/datetime-format/ Fixes: #1087
This commit is contained in:
parent
bfc5de4131
commit
720785b4cc
4 changed files with 35 additions and 21 deletions
|
|
@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
## Unreleased
|
||||
|
||||
### Fixed
|
||||
- fix date-time format in `* /api/v1/markers` to strictly conform to Mastodon’s ISO 8061 subset
|
||||
|
||||
## 2026.03.1
|
||||
|
||||
### Fixed
|
||||
|
|
|
|||
|
|
@ -5,13 +5,15 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.MarkerView do
|
||||
use Pleroma.Web, :view
|
||||
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
|
||||
def render("markers.json", %{markers: markers}) do
|
||||
Map.new(markers, fn m ->
|
||||
{m.timeline,
|
||||
%{
|
||||
last_read_id: m.last_read_id,
|
||||
version: m.lock_version,
|
||||
updated_at: NaiveDateTime.to_iso8601(m.updated_at),
|
||||
updated_at: Utils.to_masto_date(m.updated_at),
|
||||
pleroma: %{
|
||||
unread_count: m.unread_count
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
|||
token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
|
||||
insert_list(7, :notification, user: user, activity: insert(:note_activity))
|
||||
|
||||
{:ok, %{"notifications" => marker}} =
|
||||
{:ok, %{"notifications" => _}} =
|
||||
Pleroma.Marker.upsert(
|
||||
user,
|
||||
%{"notifications" => %{"last_read_id" => "69420"}}
|
||||
|
|
@ -26,14 +26,14 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
|||
|> get("/api/v1/markers?timeline[]=notifications")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response == %{
|
||||
"notifications" => %{
|
||||
"last_read_id" => "69420",
|
||||
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
|
||||
"version" => 0,
|
||||
"pleroma" => %{"unread_count" => 7}
|
||||
}
|
||||
}
|
||||
%{
|
||||
"notifications" => %{
|
||||
"last_read_id" => "69420",
|
||||
"updated_at" => "" <> _,
|
||||
"version" => 0,
|
||||
"pleroma" => %{"unread_count" => 7}
|
||||
}
|
||||
} = response
|
||||
end
|
||||
|
||||
test "gets markers with missed scopes", %{conn: conn} do
|
||||
|
|
@ -83,7 +83,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
|||
user = insert(:user)
|
||||
token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
|
||||
|
||||
{:ok, %{"notifications" => marker}} =
|
||||
{:ok, %{"notifications" => _}} =
|
||||
Pleroma.Marker.upsert(
|
||||
user,
|
||||
%{"notifications" => %{"last_read_id" => "69477"}}
|
||||
|
|
@ -100,14 +100,14 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
|||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response == %{
|
||||
"notifications" => %{
|
||||
"last_read_id" => "69888",
|
||||
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
|
||||
"version" => 0,
|
||||
"pleroma" => %{"unread_count" => 0}
|
||||
}
|
||||
}
|
||||
%{
|
||||
"notifications" => %{
|
||||
"last_read_id" => "69888",
|
||||
"updated_at" => "" <> _,
|
||||
"version" => 0,
|
||||
"pleroma" => %{"unread_count" => 0}
|
||||
}
|
||||
} = response
|
||||
end
|
||||
|
||||
test "creates a marker with missed scopes", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -7,6 +7,15 @@ defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do
|
|||
alias Pleroma.Web.MastodonAPI.MarkerView
|
||||
import Pleroma.Factory
|
||||
|
||||
# Mastodon API only accepts a specific subset of ISO 8061
|
||||
# (and we additionally truncate precision, eeventhough milliseconds are allowed)
|
||||
defp expected_date(full_timestamp) do
|
||||
full_timestamp
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|> NaiveDateTime.to_iso8601()
|
||||
|> then(&(&1 <> ".000Z"))
|
||||
end
|
||||
|
||||
test "returns markers" do
|
||||
marker1 = insert(:marker, timeline: "notifications", last_read_id: "17", unread_count: 5)
|
||||
marker2 = insert(:marker, timeline: "home", last_read_id: "42")
|
||||
|
|
@ -14,13 +23,13 @@ defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do
|
|||
assert MarkerView.render("markers.json", %{markers: [marker1, marker2]}) == %{
|
||||
"home" => %{
|
||||
last_read_id: "42",
|
||||
updated_at: NaiveDateTime.to_iso8601(marker2.updated_at),
|
||||
updated_at: expected_date(marker2.updated_at),
|
||||
version: 0,
|
||||
pleroma: %{unread_count: 0}
|
||||
},
|
||||
"notifications" => %{
|
||||
last_read_id: "17",
|
||||
updated_at: NaiveDateTime.to_iso8601(marker1.updated_at),
|
||||
updated_at: expected_date(marker1.updated_at),
|
||||
version: 0,
|
||||
pleroma: %{unread_count: 5}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue