Merge remote-tracking branch 'parent/main' into upstream-20241113
This commit is contained in:
commit
910eafda63
177 changed files with 1625 additions and 659 deletions
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::AccountRelationshipSeveranceEventSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { Fabricate.build :account_relationship_severance_event, id: 123 }
|
||||
|
||||
describe 'serialization' do
|
||||
it 'returns expected values' do
|
||||
expect(subject)
|
||||
.to include(
|
||||
'id' => be_a(String).and(eq('123'))
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
19
spec/serializers/rest/account_warning_serializer_spec.rb
Normal file
19
spec/serializers/rest/account_warning_serializer_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::AccountWarningSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { Fabricate :account_warning, id: 123, status_ids: [456, 789] }
|
||||
|
||||
describe 'serialization' do
|
||||
it 'returns expected values' do
|
||||
expect(subject)
|
||||
.to include(
|
||||
'id' => be_a(String).and(eq('123')),
|
||||
'status_ids' => be_a(Array).and(eq(['456', '789']))
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
25
spec/serializers/rest/admin/account_serializer_spec.rb
Normal file
25
spec/serializers/rest/admin/account_serializer_spec.rb
Normal 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
|
19
spec/serializers/rest/admin/cohort_serializer_spec.rb
Normal file
19
spec/serializers/rest/admin/cohort_serializer_spec.rb
Normal 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
|
33
spec/serializers/rest/admin/webhook_event_serializer_spec.rb
Normal file
33
spec/serializers/rest/admin/webhook_event_serializer_spec.rb
Normal 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
|
27
spec/serializers/rest/appeal_serializer_spec.rb
Normal file
27
spec/serializers/rest/appeal_serializer_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::AppealSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
describe 'state' do
|
||||
context 'when appeal is approved' do
|
||||
let(:record) { Fabricate.build :appeal, approved_at: 2.days.ago }
|
||||
|
||||
it { is_expected.to include('state' => 'approved') }
|
||||
end
|
||||
|
||||
context 'when appeal is rejected' do
|
||||
let(:record) { Fabricate.build :appeal, rejected_at: 2.days.ago }
|
||||
|
||||
it { is_expected.to include('state' => 'rejected') }
|
||||
end
|
||||
|
||||
context 'when appeal is not approved or rejected' do
|
||||
let(:record) { Fabricate.build :appeal, approved_at: nil, rejected_at: nil }
|
||||
|
||||
it { is_expected.to include('state' => 'pending') }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,15 +3,18 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::CustomEmojiSerializer do
|
||||
let(:serialization) { serialized_record_json(record, described_class) }
|
||||
let(:record) do
|
||||
Fabricate(:custom_emoji, shortcode: 'ohagi', aliases: aliases)
|
||||
end
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { Fabricate.build :custom_emoji, id: 123, category: Fabricate(:custom_emoji_category, name: 'Category Name'), aliases: aliases }
|
||||
let(:aliases) { [] }
|
||||
|
||||
context 'when empty aliases' do
|
||||
it 'returns normalized aliases' do
|
||||
expect(serialization['aliases']).to eq []
|
||||
describe 'serialization' do
|
||||
it 'returns expected values' do
|
||||
expect(subject)
|
||||
.to include(
|
||||
'category' => be_a(String).and(eq('Category Name')),
|
||||
'aliases' => be_a(Array).and(eq([]))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -19,7 +22,7 @@ RSpec.describe REST::CustomEmojiSerializer do
|
|||
let(:aliases) { nil }
|
||||
|
||||
it 'returns normalized aliases' do
|
||||
expect(serialization['aliases']).to eq []
|
||||
expect(subject['aliases']).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -27,7 +30,7 @@ RSpec.describe REST::CustomEmojiSerializer do
|
|||
let(:aliases) { [nil] }
|
||||
|
||||
it 'returns normalized aliases' do
|
||||
expect(serialization['aliases']).to eq []
|
||||
expect(subject['aliases']).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -35,7 +38,7 @@ RSpec.describe REST::CustomEmojiSerializer do
|
|||
let(:aliases) { ['neko'] }
|
||||
|
||||
it 'returns normalized aliases' do
|
||||
expect(serialization['aliases']).to eq ['neko']
|
||||
expect(subject['aliases']).to eq ['neko']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::ExtendedDescriptionSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
describe 'serialization' do
|
||||
context 'with text present' do
|
||||
let(:record) { ExtendedDescription.new text: 'Hello world', updated_at: Date.new(2024, 1, 1) }
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject)
|
||||
.to include(
|
||||
'content' => eq(<<~HTML),
|
||||
<p>Hello world</p>
|
||||
HTML
|
||||
'updated_at' => eq('2024-01-01')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with text missing' do
|
||||
let(:record) { ExtendedDescription.new text: nil, updated_at: Date.new(2024, 1, 1) }
|
||||
|
||||
it 'returns expected values' do
|
||||
expect(subject)
|
||||
.to include(
|
||||
'content' => eq(''),
|
||||
'updated_at' => eq('2024-01-01')
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
18
spec/serializers/rest/rule_serializer_spec.rb
Normal file
18
spec/serializers/rest/rule_serializer_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::RuleSerializer do
|
||||
subject { serialized_record_json(record, described_class) }
|
||||
|
||||
let(:record) { Fabricate.build :rule, id: 123 }
|
||||
|
||||
describe 'serialization' do
|
||||
it 'returns expected values' do
|
||||
expect(subject)
|
||||
.to include(
|
||||
'id' => be_a(String).and(eq('123'))
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue