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.

73 lines
2.7 KiB

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