DEV: Format `UserStatus#ends_at` as a ISO8601 timestamp (#23796)
…as we do when publishing a mesage bus update: 07c93918ec/app/models/user.rb (L871-L871)
This commit is contained in:
parent
1251757d48
commit
8421327845
|
@ -3,6 +3,10 @@
|
||||||
class UserStatusSerializer < ApplicationSerializer
|
class UserStatusSerializer < ApplicationSerializer
|
||||||
attributes :description, :emoji, :ends_at, :message_bus_last_id
|
attributes :description, :emoji, :ends_at, :message_bus_last_id
|
||||||
|
|
||||||
|
def ends_at
|
||||||
|
object.ends_at&.iso8601
|
||||||
|
end
|
||||||
|
|
||||||
def message_bus_last_id
|
def message_bus_last_id
|
||||||
MessageBus.last_id("/user-status")
|
MessageBus.last_id("/user-status")
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,7 @@ RSpec.describe UserStatusController do
|
||||||
it "returns user status" do
|
it "returns user status" do
|
||||||
status = "off to dentist"
|
status = "off to dentist"
|
||||||
status_emoji = "tooth"
|
status_emoji = "tooth"
|
||||||
ends_at = "2100-01-01T18:00:00.000Z"
|
ends_at = "2100-01-01T18:00:00Z"
|
||||||
user.set_status!(status, status_emoji, DateTime.parse(ends_at))
|
user.set_status!(status, status_emoji, DateTime.parse(ends_at))
|
||||||
|
|
||||||
get "/user-status.json"
|
get "/user-status.json"
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
RSpec.describe UserStatusSerializer do
|
||||||
|
fab!(:user) { Fabricate(:user) }
|
||||||
|
fab!(:user_status) do
|
||||||
|
Fabricate(
|
||||||
|
:user_status,
|
||||||
|
user: user,
|
||||||
|
set_at: Time.parse("2023-09-29T02:20:00Z"),
|
||||||
|
ends_at: Time.parse("2023-09-29T03:25:00Z"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#ends_at" do
|
||||||
|
it "is formatted as a ISO8601 timestamp" do
|
||||||
|
serialized = described_class.new(user_status, scope: Guardian.new(user), root: false).as_json
|
||||||
|
expect(serialized[:ends_at]).to eq("2023-09-29T03:25:00Z")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue