闭社主体 forked from https://github.com/tootsuite/mastodon
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.

92 lines
3.4 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.env['HTTP_ACCEPT'] = 'application/activity+json'
  8. end
  9. describe 'small number of statuses' do
  10. public_status = nil
  11. before do
  12. public_status = Status.create!(account: user.account, text: 'Hello world', visibility: :public)
  13. Status.create!(account: user.account, text: 'Hello world', visibility: :private)
  14. Status.create!(account: user.account, text: 'Hello world', visibility: :unlisted)
  15. Status.create!(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 'sets Access-Control-Allow-Origin header to *' do
  25. expect(response.header['Access-Control-Allow-Origin']).to eq '*'
  26. end
  27. it 'returns AS2 JSON body' do
  28. json_data = JSON.parse(response.body)
  29. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  30. expect(json_data).to include('id' => @request.url)
  31. expect(json_data).to include('type' => 'OrderedCollection')
  32. expect(json_data).to include('totalItems' => 1)
  33. expect(json_data).to include('items')
  34. expect(json_data['items'].count).to eq(1)
  35. expect(json_data['items']).to include(api_activitypub_status_url(public_status))
  36. end
  37. end
  38. describe 'large number of statuses' do
  39. before do
  40. 30.times do
  41. Status.create!(account: user.account, text: 'Hello world', visibility: :public)
  42. end
  43. Status.create!(account: user.account, text: 'Hello world', visibility: :private)
  44. Status.create!(account: user.account, text: 'Hello world', visibility: :unlisted)
  45. Status.create!(account: user.account, text: 'Hello world', visibility: :direct)
  46. end
  47. describe 'first page' do
  48. before do
  49. get :show, params: { id: user.account.id }
  50. end
  51. it 'returns http success' do
  52. expect(response).to have_http_status(:success)
  53. end
  54. it 'sets Content-Type header to AS2' do
  55. expect(response.header['Content-Type']).to include 'application/activity+json'
  56. end
  57. it 'sets Access-Control-Allow-Origin header to *' do
  58. expect(response.header['Access-Control-Allow-Origin']).to eq '*'
  59. end
  60. it 'returns AS2 JSON body' do
  61. json_data = JSON.parse(response.body)
  62. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  63. expect(json_data).to include('id' => @request.url)
  64. expect(json_data).to include('type' => 'OrderedCollectionPage')
  65. expect(json_data).to include('totalItems' => 20)
  66. expect(json_data).to include('items')
  67. expect(json_data['items'].count).to eq(20)
  68. expect(json_data).to include('current' => @request.url)
  69. expect(json_data).to include('next')
  70. expect(json_data).to_not include('prev')
  71. end
  72. end
  73. end
  74. end
  75. end