Browse Source

Serializers spec coverage (#24017)

closed-social-glitch-2
Matt Jankowski 1 year ago
committed by GitHub
parent
commit
56bddfbfa3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 217 additions and 0 deletions
  1. +4
    -0
      .rubocop_todo.yml
  2. +7
    -0
      spec/fabricators/encrypted_message_fabricator.rb
  3. +20
    -0
      spec/serializers/activitypub/device_serializer_spec.rb
  4. +20
    -0
      spec/serializers/activitypub/one_time_key_serializer_spec.rb
  5. +20
    -0
      spec/serializers/activitypub/undo_like_serializer_spec.rb
  6. +20
    -0
      spec/serializers/activitypub/vote_serializer_spec.rb
  7. +20
    -0
      spec/serializers/rest/encrypted_message_serializer_spec.rb
  8. +20
    -0
      spec/serializers/rest/instance_serializer_spec.rb
  9. +20
    -0
      spec/serializers/rest/keys/claim_result_serializer_spec.rb
  10. +20
    -0
      spec/serializers/rest/keys/device_serializer_spec.rb
  11. +20
    -0
      spec/serializers/rest/keys/query_result_serializer_spec.rb
  12. +26
    -0
      spec/serializers/rest/suggestion_serializer_spec.rb

+ 4
- 0
.rubocop_todo.yml View File

@ -698,7 +698,11 @@ RSpec/FilePath:
- 'spec/lib/activitypub/tag_manager_spec.rb'
- 'spec/lib/ostatus/tag_manager_spec.rb'
- 'spec/lib/sanitize_config_spec.rb'
- 'spec/serializers/activitypub/device_serializer_spec.rb'
- 'spec/serializers/activitypub/note_serializer_spec.rb'
- 'spec/serializers/activitypub/one_time_key_serializer_spec.rb'
- 'spec/serializers/activitypub/undo_like_serializer_spec.rb'
- 'spec/serializers/activitypub/vote_serializer_spec.rb'
- 'spec/serializers/activitypub/update_poll_serializer_spec.rb'
- 'spec/services/activitypub/fetch_featured_collection_service_spec.rb'
- 'spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb'

+ 7
- 0
spec/fabricators/encrypted_message_fabricator.rb View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
Fabricator(:encrypted_message) do
device
from_account { Fabricate(:account) }
from_device_id { Faker::Number.number(digits: 5) }
end

+ 20
- 0
spec/serializers/activitypub/device_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe ActivityPub::DeviceSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { Fabricate(:device) }
describe 'type' do
it 'returns correct serialized type' do
expect(serialization['type']).to eq('Device')
end
end
end

+ 20
- 0
spec/serializers/activitypub/one_time_key_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe ActivityPub::OneTimeKeySerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { Fabricate(:one_time_key) }
describe 'type' do
it 'returns correct serialized type' do
expect(serialization['type']).to eq('Curve25519Key')
end
end
end

+ 20
- 0
spec/serializers/activitypub/undo_like_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe ActivityPub::UndoLikeSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { Fabricate(:favourite) }
describe 'type' do
it 'returns correct serialized type' do
expect(serialization['type']).to eq('Undo')
end
end
end

+ 20
- 0
spec/serializers/activitypub/vote_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe ActivityPub::VoteSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { Fabricate(:poll_vote) }
describe 'type' do
it 'returns correct serialized type' do
expect(serialization['type']).to eq('Create')
end
end
end

+ 20
- 0
spec/serializers/rest/encrypted_message_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe REST::EncryptedMessageSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { Fabricate(:encrypted_message) }
describe 'account' do
it 'returns the associated account' do
expect(serialization['account_id']).to eq(record.from_account.id.to_s)
end
end
end

+ 20
- 0
spec/serializers/rest/instance_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe REST::InstanceSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { InstancePresenter.new }
describe 'usage' do
it 'returns recent usage data' do
expect(serialization['usage']).to eq({ 'users' => { 'active_month' => 0 } })
end
end
end

+ 20
- 0
spec/serializers/rest/keys/claim_result_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe REST::Keys::ClaimResultSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { Keys::ClaimService::Result.new(Account.new(id: 123), 456) }
describe 'account' do
it 'returns the associated account' do
expect(serialization['account_id']).to eq('123')
end
end
end

+ 20
- 0
spec/serializers/rest/keys/device_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe REST::Keys::DeviceSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { Device.new(name: 'Device name') }
describe 'name' do
it 'returns the name' do
expect(serialization['name']).to eq('Device name')
end
end
end

+ 20
- 0
spec/serializers/rest/keys/query_result_serializer_spec.rb View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
describe REST::Keys::QueryResultSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) { Keys::QueryService::Result.new(Account.new(id: 123), []) }
describe 'account' do
it 'returns the associated account id' do
expect(serialization['account_id']).to eq('123')
end
end
end

+ 26
- 0
spec/serializers/rest/suggestion_serializer_spec.rb View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
require 'rails_helper'
describe REST::SuggestionSerializer do
let(:serialization) do
JSON.parse(
ActiveModelSerializers::SerializableResource.new(
record, serializer: described_class
).to_json
)
end
let(:record) do
AccountSuggestions::Suggestion.new(
account: account,
source: 'SuggestionSource'
)
end
let(:account) { Fabricate(:account) }
describe 'account' do
it 'returns the associated account' do
expect(serialization['account']['id']).to eq(account.id.to_s)
end
end
end

Loading…
Cancel
Save