Ensure datetime/date are serialized to correct format (#33086)
This commit is contained in:
parent
a8edc82471
commit
5cf37248cc
28 changed files with 515 additions and 5 deletions
|
|
@ -5,6 +5,14 @@ require 'rails_helper'
|
|||
RSpec.describe REST::Admin::AccountSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
context 'when created_at is populated' do
|
||||
let(:record) { Fabricate :account, user: Fabricate(:user) }
|
||||
|
||||
it 'parses as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe 'created_by_application_id' do
|
||||
context 'when account is application-created' do
|
||||
let(:record) { Fabricate :account, user: Fabricate(:user, created_by_application: application) }
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ RSpec.describe REST::Admin::CohortSerializer do
|
|||
'data' => be_a(Array),
|
||||
'period' => /2024-01-01/
|
||||
)
|
||||
expect { DateTime.rfc3339(subject['period']) }.to_not raise_error
|
||||
subject['data'].each { |datum| expect { DateTime.rfc3339(datum['date']) }.to_not raise_error }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
15
spec/serializers/rest/admin/domain_allow_serializer_spec.rb
Normal file
15
spec/serializers/rest/admin/domain_allow_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::Admin::DomainAllowSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { Fabricate(:domain_allow) }
|
||||
|
||||
context 'when created_at is populated' do
|
||||
it 'parses as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
15
spec/serializers/rest/admin/domain_block_serializer_spec.rb
Normal file
15
spec/serializers/rest/admin/domain_block_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::Admin::DomainBlockSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { Fabricate(:domain_block) }
|
||||
|
||||
context 'when created_at is populated' do
|
||||
it 'parses as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::Admin::EmailDomainBlockSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { Fabricate(:email_domain_block) }
|
||||
|
||||
context 'when created_at is populated' do
|
||||
it 'parses as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
23
spec/serializers/rest/admin/ip_block_serializer_spec.rb
Normal file
23
spec/serializers/rest/admin/ip_block_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::Admin::IpBlockSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { Fabricate(:ip_block) }
|
||||
|
||||
context 'when created_at is populated' do
|
||||
it 'parses as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'when expires_at is populated' do
|
||||
let(:record) { Fabricate(:ip_block, expires_at: DateTime.new(2024, 11, 28, 16, 20, 0)) }
|
||||
|
||||
it 'parses as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['expires_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
15
spec/serializers/rest/admin/ip_serializer_spec.rb
Normal file
15
spec/serializers/rest/admin/ip_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::Admin::IpSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { UserIp.new(used_at: 3.days.ago) }
|
||||
|
||||
context 'when used_at is populated' do
|
||||
it 'parses as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['used_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
18
spec/serializers/rest/admin/measure_serializer_spec.rb
Normal file
18
spec/serializers/rest/admin/measure_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::Admin::MeasureSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
let(:params) { ActionController::Parameters.new({ instance_accounts: [123] }) }
|
||||
let(:record) { Admin::Metrics::Measure::ActiveUsersMeasure.new(start_at, end_at, params) }
|
||||
|
||||
context 'when start_at is populated' do
|
||||
it 'parses as RFC 3339 datetime' do
|
||||
subject['data'].each { |datum| expect { DateTime.rfc3339(datum['date']) }.to_not raise_error }
|
||||
end
|
||||
end
|
||||
end
|
||||
27
spec/serializers/rest/admin/report_serializer_spec.rb
Normal file
27
spec/serializers/rest/admin/report_serializer_spec.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::Admin::ReportSerializer do
|
||||
subject { serialized_record_json(report, described_class) }
|
||||
|
||||
let(:report) { Fabricate(:report) }
|
||||
|
||||
context 'with created_at' do
|
||||
it 'is serialized as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['created_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'with action_taken_at' do
|
||||
let(:acting_account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
report.resolve!(acting_account)
|
||||
end
|
||||
|
||||
it 'is serialized as RFC 3339 datetime' do
|
||||
expect { DateTime.rfc3339(subject['action_taken_at']) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue