闭社主体 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.

77 lines
2.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::Activitypub::ActivitiesController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. describe 'GET #show' do
  6. describe 'normal status' do
  7. public_status = nil
  8. before do
  9. public_status = Status.create!(account: user.account, text: 'Hello world', visibility: :public)
  10. @request.env['HTTP_ACCEPT'] = 'application/activity+json'
  11. get :show_status, params: { id: public_status.id }
  12. end
  13. it 'returns http success' do
  14. expect(response).to have_http_status(:success)
  15. end
  16. it 'sets Content-Type header to AS2' do
  17. expect(response.header['Content-Type']).to include 'application/activity+json'
  18. end
  19. it 'sets Access-Control-Allow-Origin header to *' do
  20. expect(response.header['Access-Control-Allow-Origin']).to eq '*'
  21. end
  22. it 'returns http success' do
  23. json_data = JSON.parse(response.body)
  24. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  25. expect(json_data).to include('type' => 'Create')
  26. expect(json_data).to include('id' => @request.url)
  27. expect(json_data).to include('type' => 'Create')
  28. expect(json_data).to include('object' => api_activitypub_note_url(public_status))
  29. expect(json_data).to include('url' => TagManager.instance.url_for(public_status))
  30. end
  31. end
  32. describe 'reblog' do
  33. original = nil
  34. reblog = nil
  35. before do
  36. original = Status.create!(account: user.account, text: 'Hello world', visibility: :public)
  37. reblog = Status.create!(account: user.account, reblog_of_id: original.id, visibility: :public)
  38. @request.env['HTTP_ACCEPT'] = 'application/activity+json'
  39. get :show_status, params: { id: reblog.id }
  40. end
  41. it 'returns http success' do
  42. expect(response).to have_http_status(:success)
  43. end
  44. it 'sets Content-Type header to AS2' do
  45. expect(response.header['Content-Type']).to include 'application/activity+json'
  46. end
  47. it 'sets Access-Control-Allow-Origin header to *' do
  48. expect(response.header['Access-Control-Allow-Origin']).to eq '*'
  49. end
  50. it 'returns http success' do
  51. json_data = JSON.parse(response.body)
  52. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  53. expect(json_data).to include('type' => 'Announce')
  54. expect(json_data).to include('id' => @request.url)
  55. expect(json_data).to include('type' => 'Announce')
  56. expect(json_data).to include('object' => api_activitypub_status_url(original))
  57. expect(json_data).to include('url' => TagManager.instance.url_for(reblog))
  58. end
  59. end
  60. end
  61. end