about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatt Jankowski <matt@jankowski.online>2023-03-10 06:12:51 -0500
committerGitHub <noreply@github.com>2023-03-10 12:12:51 +0100
commit56bddfbfa39956ea3a8c52721eb364b1120634f6 (patch)
tree7370999f6b3d5a4cb07fdf2e029cdfc0644df00b
parent53309fa31a4106500e2da80b845fad08d7d09900 (diff)
Serializers spec coverage (#24017)
-rw-r--r--.rubocop_todo.yml4
-rw-r--r--spec/fabricators/encrypted_message_fabricator.rb7
-rw-r--r--spec/serializers/activitypub/device_serializer_spec.rb20
-rw-r--r--spec/serializers/activitypub/one_time_key_serializer_spec.rb20
-rw-r--r--spec/serializers/activitypub/undo_like_serializer_spec.rb20
-rw-r--r--spec/serializers/activitypub/vote_serializer_spec.rb20
-rw-r--r--spec/serializers/rest/encrypted_message_serializer_spec.rb20
-rw-r--r--spec/serializers/rest/instance_serializer_spec.rb20
-rw-r--r--spec/serializers/rest/keys/claim_result_serializer_spec.rb20
-rw-r--r--spec/serializers/rest/keys/device_serializer_spec.rb20
-rw-r--r--spec/serializers/rest/keys/query_result_serializer_spec.rb20
-rw-r--r--spec/serializers/rest/suggestion_serializer_spec.rb26
12 files changed, 217 insertions, 0 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index b53f655bd..90e644856 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -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'
diff --git a/spec/fabricators/encrypted_message_fabricator.rb b/spec/fabricators/encrypted_message_fabricator.rb
new file mode 100644
index 000000000..43b310514
--- /dev/null
+++ b/spec/fabricators/encrypted_message_fabricator.rb
@@ -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
diff --git a/spec/serializers/activitypub/device_serializer_spec.rb b/spec/serializers/activitypub/device_serializer_spec.rb
new file mode 100644
index 000000000..2a3be8212
--- /dev/null
+++ b/spec/serializers/activitypub/device_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/activitypub/one_time_key_serializer_spec.rb b/spec/serializers/activitypub/one_time_key_serializer_spec.rb
new file mode 100644
index 000000000..6fe1f0618
--- /dev/null
+++ b/spec/serializers/activitypub/one_time_key_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/activitypub/undo_like_serializer_spec.rb b/spec/serializers/activitypub/undo_like_serializer_spec.rb
new file mode 100644
index 000000000..43cf7192e
--- /dev/null
+++ b/spec/serializers/activitypub/undo_like_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/activitypub/vote_serializer_spec.rb b/spec/serializers/activitypub/vote_serializer_spec.rb
new file mode 100644
index 000000000..c329542d7
--- /dev/null
+++ b/spec/serializers/activitypub/vote_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/rest/encrypted_message_serializer_spec.rb b/spec/serializers/rest/encrypted_message_serializer_spec.rb
new file mode 100644
index 000000000..e0e70a3b8
--- /dev/null
+++ b/spec/serializers/rest/encrypted_message_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/rest/instance_serializer_spec.rb b/spec/serializers/rest/instance_serializer_spec.rb
new file mode 100644
index 000000000..15a5de18d
--- /dev/null
+++ b/spec/serializers/rest/instance_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/rest/keys/claim_result_serializer_spec.rb b/spec/serializers/rest/keys/claim_result_serializer_spec.rb
new file mode 100644
index 000000000..cf9416f03
--- /dev/null
+++ b/spec/serializers/rest/keys/claim_result_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/rest/keys/device_serializer_spec.rb b/spec/serializers/rest/keys/device_serializer_spec.rb
new file mode 100644
index 000000000..c15e197cb
--- /dev/null
+++ b/spec/serializers/rest/keys/device_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/rest/keys/query_result_serializer_spec.rb b/spec/serializers/rest/keys/query_result_serializer_spec.rb
new file mode 100644
index 000000000..983780ae9
--- /dev/null
+++ b/spec/serializers/rest/keys/query_result_serializer_spec.rb
@@ -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
diff --git a/spec/serializers/rest/suggestion_serializer_spec.rb b/spec/serializers/rest/suggestion_serializer_spec.rb
new file mode 100644
index 000000000..b3c086208
--- /dev/null
+++ b/spec/serializers/rest/suggestion_serializer_spec.rb
@@ -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