0
0
Fork 0

Ensure datetime/date are serialized to correct format (#33086)

This commit is contained in:
Nik Clayton 2024-12-14 16:50:41 +01:00 committed by GitHub
parent a8edc82471
commit 5cf37248cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 515 additions and 5 deletions

View file

@ -5,6 +5,7 @@ require 'rails_helper'
RSpec.describe REST::AccountSerializer do
subject { serialized_record_json(account, described_class) }
let(:default_datetime) { DateTime.new(2024, 11, 28, 16, 20, 0) }
let(:role) { Fabricate(:user_role, name: 'Role', highlighted: true) }
let(:user) { Fabricate(:user, role: role) }
let(:account) { user.account }
@ -44,4 +45,24 @@ RSpec.describe REST::AccountSerializer do
expect(subject['memorial']).to be true
end
end
context 'when created_at is populated' do
before do
account.account_stat.update!(created_at: default_datetime)
end
it 'parses as RFC 3339 datetime' do
expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error
end
end
context 'when last_status_at is populated' do
before do
account.account_stat.update!(last_status_at: default_datetime)
end
it 'is serialized as yyyy-mm-dd' do
expect(subject['last_status_at']).to eq('2024-11-28')
end
end
end