about summary refs log tree commit diff
path: root/spec/serializers
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2023-04-14 19:22:47 -0500
committerStarfall <us@starfall.systems>2023-04-14 19:22:47 -0500
commit4fe1689de43f4404eb9530fcfbcbfb26d6c1c13a (patch)
tree6811b845bb7f4966b10dcefa3dea404246f161c7 /spec/serializers
parent65c1e53a32cabcdbb7bca57002bb0f6acdebe07e (diff)
parentbed63f6dae0879ac840066b031229e0d139089cd (diff)
Merge remote-tracking branch 'glitch/main' HEAD main
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/activitypub/device_serializer_spec.rb20
-rw-r--r--spec/serializers/activitypub/note_serializer_spec.rb (renamed from spec/serializers/activitypub/note_spec.rb)4
-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/update_poll_serializer_spec.rb (renamed from spec/serializers/activitypub/update_poll_spec.rb)4
-rw-r--r--spec/serializers/activitypub/vote_serializer_spec.rb20
-rw-r--r--spec/serializers/rest/account_serializer_spec.rb47
-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
13 files changed, 257 insertions, 4 deletions
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/note_spec.rb b/spec/serializers/activitypub/note_serializer_spec.rb
index 55bfbc16b..7ea47baef 100644
--- a/spec/serializers/activitypub/note_spec.rb
+++ b/spec/serializers/activitypub/note_serializer_spec.rb
@@ -3,6 +3,8 @@
 require 'rails_helper'
 
 describe ActivityPub::NoteSerializer do
+  subject { JSON.parse(@serialization.to_json) }
+
   let!(:account) { Fabricate(:account) }
   let!(:other)   { Fabricate(:account) }
   let!(:parent)  { Fabricate(:status, account: account, visibility: :public) }
@@ -16,8 +18,6 @@ describe ActivityPub::NoteSerializer do
     @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter)
   end
 
-  subject { JSON.parse(@serialization.to_json) }
-
   it 'has a Note type' do
     expect(subject['type']).to eql('Note')
   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/update_poll_spec.rb b/spec/serializers/activitypub/update_poll_serializer_spec.rb
index f9e035eab..4360808b5 100644
--- a/spec/serializers/activitypub/update_poll_spec.rb
+++ b/spec/serializers/activitypub/update_poll_serializer_spec.rb
@@ -3,6 +3,8 @@
 require 'rails_helper'
 
 describe ActivityPub::UpdatePollSerializer do
+  subject { JSON.parse(@serialization.to_json) }
+
   let(:account) { Fabricate(:account) }
   let(:poll)    { Fabricate(:poll, account: account) }
   let!(:status) { Fabricate(:status, account: account, poll: poll) }
@@ -11,8 +13,6 @@ describe ActivityPub::UpdatePollSerializer do
     @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: ActivityPub::UpdatePollSerializer, adapter: ActivityPub::Adapter)
   end
 
-  subject { JSON.parse(@serialization.to_json) }
-
   it 'has a Update type' do
     expect(subject['type']).to eql('Update')
   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/account_serializer_spec.rb b/spec/serializers/rest/account_serializer_spec.rb
new file mode 100644
index 000000000..528639943
--- /dev/null
+++ b/spec/serializers/rest/account_serializer_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe REST::AccountSerializer do
+  subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer).to_json) }
+
+  let(:role)    { Fabricate(:user_role, name: 'Role', highlighted: true) }
+  let(:user)    { Fabricate(:user, role: role) }
+  let(:account) { user.account }
+
+  context 'when the account is suspended' do
+    before do
+      account.suspend!
+    end
+
+    it 'returns empty roles' do
+      expect(subject['roles']).to eq []
+    end
+  end
+
+  context 'when the account has a highlighted role' do
+    let(:role) { Fabricate(:user_role, name: 'Role', highlighted: true) }
+
+    it 'returns the expected role' do
+      expect(subject['roles'].first).to include({ 'name' => 'Role' })
+    end
+  end
+
+  context 'when the account has a non-highlighted role' do
+    let(:role) { Fabricate(:user_role, name: 'Role', highlighted: false) }
+
+    it 'returns empty roles' do
+      expect(subject['roles']).to eq []
+    end
+  end
+
+  context 'when the account is memorialized' do
+    before do
+      account.memorialize!
+    end
+
+    it 'marks it as such' do
+      expect(subject['memorial']).to be true
+    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