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

81 lines
3.0 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 = Status.create!(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 'sets Access-Control-Allow-Origin header to *' do
  21. expect(response.header['Access-Control-Allow-Origin']).to eq '*'
  22. end
  23. it 'returns http success' do
  24. json_data = JSON.parse(response.body)
  25. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  26. expect(json_data).to include('type' => 'Note')
  27. expect(json_data).to include('id' => @request.url)
  28. expect(json_data).to include('name' => 'Hello world')
  29. expect(json_data).to include('content' => 'Hello world')
  30. expect(json_data).to include('published')
  31. expect(json_data).to include('url' => TagManager.instance.url_for(public_status))
  32. end
  33. end
  34. describe 'reply' do
  35. original = nil
  36. reply = nil
  37. before do
  38. original = Status.create!(account: user_alice.account, text: 'Hello world', visibility: :public)
  39. reply = Status.create!(account: user_bob.account, text: 'Hello world', in_reply_to_id: original.id, visibility: :public)
  40. @request.env['HTTP_ACCEPT'] = 'application/activity+json'
  41. get :show, params: { id: reply.id }
  42. end
  43. it 'returns http success' do
  44. expect(response).to have_http_status(:success)
  45. end
  46. it 'sets Content-Type header to AS2' do
  47. expect(response.header['Content-Type']).to include 'application/activity+json'
  48. end
  49. it 'sets Access-Control-Allow-Origin header to *' do
  50. expect(response.header['Access-Control-Allow-Origin']).to eq '*'
  51. end
  52. it 'returns http success' do
  53. json_data = JSON.parse(response.body)
  54. expect(json_data).to include('@context' => 'https://www.w3.org/ns/activitystreams')
  55. expect(json_data).to include('type' => 'Note')
  56. expect(json_data).to include('id' => @request.url)
  57. expect(json_data).to include('name' => 'Hello world')
  58. expect(json_data).to include('content' => 'Hello world')
  59. expect(json_data).to include('published')
  60. expect(json_data).to include('url' => TagManager.instance.url_for(reply))
  61. expect(json_data).to include('inReplyTo' => api_activitypub_note_url(original))
  62. end
  63. end
  64. end
  65. end