reactions_controller_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::Announcements::ReactionsController, type: :controller do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. let(:scopes) { 'write:favourites' }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  8. let!(:announcement) { Fabricate(:announcement) }
  9. describe 'PUT #update' do
  10. context 'without token' do
  11. it 'returns http unauthorized' do
  12. put :update, params: { announcement_id: announcement.id, id: '😂' }
  13. expect(response).to have_http_status :unauthorized
  14. end
  15. end
  16. context 'with token' do
  17. before do
  18. allow(controller).to receive(:doorkeeper_token) { token }
  19. put :update, params: { announcement_id: announcement.id, id: '😂' }
  20. end
  21. it 'returns http success' do
  22. expect(response).to have_http_status(200)
  23. end
  24. it 'creates reaction' do
  25. expect(announcement.announcement_reactions.find_by(name: '😂', account: user.account)).to_not be_nil
  26. end
  27. end
  28. end
  29. describe 'DELETE #destroy' do
  30. before do
  31. announcement.announcement_reactions.create!(account: user.account, name: '😂')
  32. end
  33. context 'without token' do
  34. it 'returns http unauthorized' do
  35. delete :destroy, params: { announcement_id: announcement.id, id: '😂' }
  36. expect(response).to have_http_status :unauthorized
  37. end
  38. end
  39. context 'with token' do
  40. before do
  41. allow(controller).to receive(:doorkeeper_token) { token }
  42. delete :destroy, params: { announcement_id: announcement.id, id: '😂' }
  43. end
  44. it 'returns http success' do
  45. expect(response).to have_http_status(200)
  46. end
  47. it 'creates reaction' do
  48. expect(announcement.announcement_reactions.find_by(name: '😂', account: user.account)).to be_nil
  49. end
  50. end
  51. end
  52. end