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.

69 lines
2.5 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 = Fabricate(:status, 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 'returns http success' do
  20. json_data = JSON.parse(response.body)
  21. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  22. expect(json_data).to include('type' => 'Create')
  23. expect(json_data).to include('id' => @request.url)
  24. expect(json_data).to include('type' => 'Create')
  25. expect(json_data).to include('object' => api_activitypub_note_url(public_status))
  26. expect(json_data).to include('url' => TagManager.instance.url_for(public_status))
  27. end
  28. end
  29. describe 'reblog' do
  30. original = nil
  31. reblog = nil
  32. before do
  33. original = Fabricate(:status, account: user.account, text: 'Hello world', visibility: :public)
  34. reblog = Fabricate(:status, account: user.account, reblog_of_id: original.id, visibility: :public)
  35. @request.env['HTTP_ACCEPT'] = 'application/activity+json'
  36. get :show_status, params: { id: reblog.id }
  37. end
  38. it 'returns http success' do
  39. expect(response).to have_http_status(:success)
  40. end
  41. it 'sets Content-Type header to AS2' do
  42. expect(response.header['Content-Type']).to include 'application/activity+json'
  43. end
  44. it 'returns http success' do
  45. json_data = JSON.parse(response.body)
  46. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  47. expect(json_data).to include('type' => 'Announce')
  48. expect(json_data).to include('id' => @request.url)
  49. expect(json_data).to include('type' => 'Announce')
  50. expect(json_data).to include('object' => api_activitypub_status_url(original))
  51. expect(json_data).to include('url' => TagManager.instance.url_for(reblog))
  52. end
  53. end
  54. end
  55. end