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.

156 lines
5.9 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::ActivityPub::OutboxController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. describe 'GET #show' do
  6. before do
  7. @request.headers['ACCEPT'] = 'application/activity+json'
  8. end
  9. describe 'collection with small number of statuses' do
  10. public_status = nil
  11. before do
  12. public_status = Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public)
  13. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :private)
  14. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :unlisted)
  15. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :direct)
  16. get :show, params: { id: user.account.id }
  17. end
  18. it 'returns http success' do
  19. expect(response).to have_http_status(:success)
  20. end
  21. it 'sets Content-Type header to AS2' do
  22. expect(response.header['Content-Type']).to include 'application/activity+json'
  23. end
  24. it 'returns AS2 JSON body' do
  25. json_data = JSON.parse(response.body)
  26. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  27. expect(json_data).to include('id' => @request.url)
  28. expect(json_data).to include('type' => 'OrderedCollection')
  29. expect(json_data).to include('totalItems' => 1)
  30. expect(json_data).to include('current')
  31. expect(json_data).to include('first')
  32. expect(json_data).to include('last')
  33. end
  34. end
  35. describe 'collection with large number of statuses' do
  36. before do
  37. 30.times do
  38. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public)
  39. end
  40. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :private)
  41. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :unlisted)
  42. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :direct)
  43. get :show, params: { id: user.account.id }
  44. end
  45. it 'returns http success' do
  46. expect(response).to have_http_status(:success)
  47. end
  48. it 'sets Content-Type header to AS2' do
  49. expect(response.header['Content-Type']).to include 'application/activity+json'
  50. end
  51. it 'returns AS2 JSON body' do
  52. json_data = JSON.parse(response.body)
  53. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  54. expect(json_data).to include('id' => @request.url)
  55. expect(json_data).to include('type' => 'OrderedCollection')
  56. expect(json_data).to include('totalItems' => 30)
  57. expect(json_data).to include('current')
  58. expect(json_data).to include('first')
  59. expect(json_data).to include('last')
  60. end
  61. end
  62. describe 'page with small number of statuses' do
  63. statuses = []
  64. before do
  65. 5.times do
  66. statuses << Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public)
  67. end
  68. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :private)
  69. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :unlisted)
  70. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :direct)
  71. get :show, params: { id: user.account.id, max_id: statuses.last.id + 1 }
  72. end
  73. it 'returns http success' do
  74. expect(response).to have_http_status(:success)
  75. end
  76. it 'sets Content-Type header to AS2' do
  77. expect(response.header['Content-Type']).to include 'application/activity+json'
  78. end
  79. it 'returns AS2 JSON body' do
  80. json_data = JSON.parse(response.body)
  81. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  82. expect(json_data).to include('id' => @request.url)
  83. expect(json_data).to include('type' => 'OrderedCollectionPage')
  84. expect(json_data).to include('partOf')
  85. expect(json_data).to include('items')
  86. expect(json_data['items'].length).to eq(5)
  87. expect(json_data).to include('prev')
  88. expect(json_data).to include('next')
  89. expect(json_data).to include('current')
  90. expect(json_data).to include('first')
  91. expect(json_data).to include('last')
  92. end
  93. end
  94. describe 'page with large number of statuses' do
  95. statuses = []
  96. before do
  97. 30.times do
  98. statuses << Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public)
  99. end
  100. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :private)
  101. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :unlisted)
  102. Fabricate(:status, account: user.account, text: 'Hello world', visibility: :direct)
  103. get :show, params: { id: user.account.id, max_id: statuses.last.id + 1 }
  104. end
  105. it 'returns http success' do
  106. expect(response).to have_http_status(:success)
  107. end
  108. it 'sets Content-Type header to AS2' do
  109. expect(response.header['Content-Type']).to include 'application/activity+json'
  110. end
  111. it 'returns AS2 JSON body' do
  112. json_data = JSON.parse(response.body)
  113. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  114. expect(json_data).to include('id' => @request.url)
  115. expect(json_data).to include('type' => 'OrderedCollectionPage')
  116. expect(json_data).to include('partOf')
  117. expect(json_data).to include('items')
  118. expect(json_data['items'].length).to eq(20)
  119. expect(json_data).to include('prev')
  120. expect(json_data).to include('next')
  121. expect(json_data).to include('current')
  122. expect(json_data).to include('first')
  123. expect(json_data).to include('last')
  124. end
  125. end
  126. end
  127. end