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.

137 lines
4.3 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::CollectionsController, type: :controller do
  4. let!(:account) { Fabricate(:account) }
  5. let(:remote_account) { nil }
  6. before do
  7. allow(controller).to receive(:signed_request_account).and_return(remote_account)
  8. Fabricate(:status_pin, account: account)
  9. Fabricate(:status_pin, account: account)
  10. Fabricate(:status, account: account, visibility: :private)
  11. end
  12. describe 'GET #show' do
  13. context 'when id is "featured"' do
  14. context 'without signature' do
  15. let(:remote_account) { nil }
  16. before do
  17. get :show, params: { id: 'featured', account_username: account.username }
  18. end
  19. it 'returns http success' do
  20. expect(response).to have_http_status(200)
  21. end
  22. it 'returns application/activity+json' do
  23. expect(response.content_type).to eq 'application/activity+json'
  24. end
  25. it 'returns public Cache-Control header' do
  26. expect(response.headers['Cache-Control']).to include 'public'
  27. end
  28. it 'returns orderedItems with pinned statuses' do
  29. json = body_as_json
  30. expect(json[:orderedItems]).to be_an Array
  31. expect(json[:orderedItems].size).to eq 2
  32. end
  33. end
  34. context 'with signature' do
  35. let(:remote_account) { Fabricate(:account, domain: 'example.com') }
  36. context do
  37. before do
  38. get :show, params: { id: 'featured', account_username: account.username }
  39. end
  40. it 'returns http success' do
  41. expect(response).to have_http_status(200)
  42. end
  43. it 'returns application/activity+json' do
  44. expect(response.content_type).to eq 'application/activity+json'
  45. end
  46. it 'returns public Cache-Control header' do
  47. expect(response.headers['Cache-Control']).to include 'public'
  48. end
  49. it 'returns orderedItems with pinned statuses' do
  50. json = body_as_json
  51. expect(json[:orderedItems]).to be_an Array
  52. expect(json[:orderedItems].size).to eq 2
  53. end
  54. end
  55. context 'in authorized fetch mode' do
  56. before do
  57. allow(controller).to receive(:authorized_fetch_mode?).and_return(true)
  58. end
  59. context 'when signed request account is blocked' do
  60. before do
  61. account.block!(remote_account)
  62. get :show, params: { id: 'featured', account_username: account.username }
  63. end
  64. it 'returns http success' do
  65. expect(response).to have_http_status(200)
  66. end
  67. it 'returns application/activity+json' do
  68. expect(response.content_type).to eq 'application/activity+json'
  69. end
  70. it 'returns private Cache-Control header' do
  71. expect(response.headers['Cache-Control']).to include 'private'
  72. end
  73. it 'returns empty orderedItems' do
  74. json = body_as_json
  75. expect(json[:orderedItems]).to be_an Array
  76. expect(json[:orderedItems].size).to eq 0
  77. end
  78. end
  79. context 'when signed request account is domain blocked' do
  80. before do
  81. account.block_domain!(remote_account.domain)
  82. get :show, params: { id: 'featured', account_username: account.username }
  83. end
  84. it 'returns http success' do
  85. expect(response).to have_http_status(200)
  86. end
  87. it 'returns application/activity+json' do
  88. expect(response.content_type).to eq 'application/activity+json'
  89. end
  90. it 'returns private Cache-Control header' do
  91. expect(response.headers['Cache-Control']).to include 'private'
  92. end
  93. it 'returns empty orderedItems' do
  94. json = body_as_json
  95. expect(json[:orderedItems]).to be_an Array
  96. expect(json[:orderedItems].size).to eq 0
  97. end
  98. end
  99. end
  100. end
  101. end
  102. context 'when id is not "featured"' do
  103. it 'returns http not found' do
  104. get :show, params: { id: 'hoge', account_username: account.username }
  105. expect(response).to have_http_status(404)
  106. end
  107. end
  108. end
  109. end