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

113 lines
3.3 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::V1::Statuses::BookmarksController do
  4. render_views
  5. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  6. let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:bookmarks', application: app) }
  8. context 'with an oauth token' do
  9. before do
  10. allow(controller).to receive(:doorkeeper_token) { token }
  11. end
  12. describe 'POST #create' do
  13. let(:status) { Fabricate(:status, account: user.account) }
  14. before do
  15. post :create, params: { status_id: status.id }
  16. end
  17. context 'with public status' do
  18. it 'returns http success' do
  19. expect(response).to have_http_status(:success)
  20. end
  21. it 'updates the bookmarked attribute' do
  22. expect(user.account.bookmarked?(status)).to be true
  23. end
  24. it 'returns json with updated attributes' do
  25. hash_body = body_as_json
  26. expect(hash_body[:id]).to eq status.id.to_s
  27. expect(hash_body[:bookmarked]).to be true
  28. end
  29. end
  30. context 'with private status of not-followed account' do
  31. let(:status) { Fabricate(:status, visibility: :private) }
  32. it 'returns http not found' do
  33. expect(response).to have_http_status(404)
  34. end
  35. end
  36. end
  37. describe 'POST #destroy' do
  38. context 'with public status' do
  39. let(:status) { Fabricate(:status, account: user.account) }
  40. before do
  41. Bookmark.find_or_create_by!(account: user.account, status: status)
  42. post :destroy, params: { status_id: status.id }
  43. end
  44. it 'returns http success' do
  45. expect(response).to have_http_status(:success)
  46. end
  47. it 'updates the bookmarked attribute' do
  48. expect(user.account.bookmarked?(status)).to be false
  49. end
  50. it 'returns json with updated attributes' do
  51. hash_body = body_as_json
  52. expect(hash_body[:id]).to eq status.id.to_s
  53. expect(hash_body[:bookmarked]).to be false
  54. end
  55. end
  56. context 'with public status when blocked by its author' do
  57. let(:status) { Fabricate(:status) }
  58. before do
  59. Bookmark.find_or_create_by!(account: user.account, status: status)
  60. status.account.block!(user.account)
  61. post :destroy, params: { status_id: status.id }
  62. end
  63. it 'returns http success' do
  64. expect(response).to have_http_status(200)
  65. end
  66. it 'updates the bookmarked attribute' do
  67. expect(user.account.bookmarked?(status)).to be false
  68. end
  69. it 'returns json with updated attributes' do
  70. hash_body = body_as_json
  71. expect(hash_body[:id]).to eq status.id.to_s
  72. expect(hash_body[:bookmarked]).to be false
  73. end
  74. end
  75. context 'with private status that was not bookmarked' do
  76. let(:status) { Fabricate(:status, visibility: :private) }
  77. before do
  78. post :destroy, params: { status_id: status.id }
  79. end
  80. it 'returns http not found' do
  81. expect(response).to have_http_status(404)
  82. end
  83. end
  84. end
  85. end
  86. end