Add coverage for misc serializers (#32781)

This commit is contained in:
Matt Jankowski 2024-11-07 10:37:26 -05:00 committed by GitHub
commit 870bb06994
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 344 additions and 0 deletions

View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe REST::Admin::AccountSerializer do
subject { serialized_record_json(record, described_class) }
describe 'created_by_application_id' do
context 'when account is application-created' do
let(:record) { Fabricate :account, user: Fabricate(:user, created_by_application: application) }
let(:application) { Fabricate :application }
it { is_expected.to include('created_by_application_id' => application.id.to_s) }
end
end
describe 'invited_by_account_id' do
context 'when account was invited' do
let(:record) { Fabricate :account, user: Fabricate(:user, invite: invite) }
let(:invite) { Fabricate :invite }
it { is_expected.to include('invited_by_account_id' => invite.user.account.id.to_s) }
end
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe REST::Admin::CohortSerializer do
subject { serialized_record_json(record, described_class) }
let(:record) { Admin::Metrics::Retention.new('2024-01-01', '2024-01-02', 'day').cohorts.first }
describe 'serialization' do
it 'returns expected values' do
expect(subject)
.to include(
'data' => be_a(Array),
'period' => /2024-01-01/
)
end
end
end

View file

@ -0,0 +1,33 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe REST::Admin::WebhookEventSerializer do
describe '.serializer_for' do
subject { described_class.serializer_for(model, {}) }
context 'with an Account model' do
let(:model) { Account.new }
it { is_expected.to eq(REST::Admin::AccountSerializer) }
end
context 'with a Report model' do
let(:model) { Report.new }
it { is_expected.to eq(REST::Admin::ReportSerializer) }
end
context 'with a Status model' do
let(:model) { Status.new }
it { is_expected.to eq(REST::StatusSerializer) }
end
context 'with an Array' do
let(:model) { [] }
it { is_expected.to eq(ActiveModel::Serializer::CollectionSerializer) }
end
end
end