You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::ProcessAccountService, type: :service do
  3. subject { described_class.new }
  4. context 'property values' do
  5. let(:payload) do
  6. {
  7. id: 'https://foo.test',
  8. type: 'Actor',
  9. inbox: 'https://foo.test/inbox',
  10. attachment: [
  11. { type: 'PropertyValue', name: 'Pronouns', value: 'They/them' },
  12. { type: 'PropertyValue', name: 'Occupation', value: 'Unit test' },
  13. { type: 'PropertyValue', name: 'non-string', value: ['foo', 'bar'] },
  14. ],
  15. }.with_indifferent_access
  16. end
  17. it 'parses out of attachment' do
  18. account = subject.call('alice', 'example.com', payload)
  19. expect(account.fields).to be_a Array
  20. expect(account.fields.size).to eq 2
  21. expect(account.fields[0]).to be_a Account::Field
  22. expect(account.fields[0].name).to eq 'Pronouns'
  23. expect(account.fields[0].value).to eq 'They/them'
  24. expect(account.fields[1]).to be_a Account::Field
  25. expect(account.fields[1].name).to eq 'Occupation'
  26. expect(account.fields[1].value).to eq 'Unit test'
  27. end
  28. end
  29. context 'when account is not suspended' do
  30. let!(:account) { Fabricate(:account, username: 'alice', domain: 'example.com') }
  31. let(:payload) do
  32. {
  33. id: 'https://foo.test',
  34. type: 'Actor',
  35. inbox: 'https://foo.test/inbox',
  36. suspended: true,
  37. }.with_indifferent_access
  38. end
  39. before do
  40. allow(Admin::SuspensionWorker).to receive(:perform_async)
  41. end
  42. subject { described_class.new.call('alice', 'example.com', payload) }
  43. it 'suspends account remotely' do
  44. expect(subject.suspended?).to be true
  45. expect(subject.suspension_origin_remote?).to be true
  46. end
  47. it 'queues suspension worker' do
  48. subject
  49. expect(Admin::SuspensionWorker).to have_received(:perform_async)
  50. end
  51. end
  52. context 'when account is suspended' do
  53. let!(:account) { Fabricate(:account, username: 'alice', domain: 'example.com', display_name: '') }
  54. let(:payload) do
  55. {
  56. id: 'https://foo.test',
  57. type: 'Actor',
  58. inbox: 'https://foo.test/inbox',
  59. suspended: false,
  60. name: 'Hoge',
  61. }.with_indifferent_access
  62. end
  63. before do
  64. allow(Admin::UnsuspensionWorker).to receive(:perform_async)
  65. account.suspend!(origin: suspension_origin)
  66. end
  67. subject { described_class.new.call('alice', 'example.com', payload) }
  68. context 'locally' do
  69. let(:suspension_origin) { :local }
  70. it 'does not unsuspend it' do
  71. expect(subject.suspended?).to be true
  72. end
  73. it 'does not update any attributes' do
  74. expect(subject.display_name).to_not eq 'Hoge'
  75. end
  76. end
  77. context 'remotely' do
  78. let(:suspension_origin) { :remote }
  79. it 'unsuspends it' do
  80. expect(subject.suspended?).to be false
  81. end
  82. it 'queues unsuspension worker' do
  83. subject
  84. expect(Admin::UnsuspensionWorker).to have_received(:perform_async)
  85. end
  86. it 'updates attributes' do
  87. expect(subject.display_name).to eq 'Hoge'
  88. end
  89. end
  90. end
  91. end