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.

59 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::AnnouncementsController, type: :controller do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. let(:scopes) { 'read' }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  8. let!(:announcement) { Fabricate(:announcement) }
  9. describe 'GET #index' do
  10. context 'without token' do
  11. it 'returns http unprocessable entity' do
  12. get :index
  13. expect(response).to have_http_status :unprocessable_entity
  14. end
  15. end
  16. context 'with token' do
  17. before do
  18. allow(controller).to receive(:doorkeeper_token) { token }
  19. get :index
  20. end
  21. it 'returns http success' do
  22. expect(response).to have_http_status(200)
  23. end
  24. end
  25. end
  26. describe 'POST #dismiss' do
  27. context 'without token' do
  28. it 'returns http unauthorized' do
  29. post :dismiss, params: { id: announcement.id }
  30. expect(response).to have_http_status :unauthorized
  31. end
  32. end
  33. context 'with token' do
  34. let(:scopes) { 'write:accounts' }
  35. before do
  36. allow(controller).to receive(:doorkeeper_token) { token }
  37. post :dismiss, params: { id: announcement.id }
  38. end
  39. it 'returns http success' do
  40. expect(response).to have_http_status(200)
  41. end
  42. it 'dismisses announcement' do
  43. expect(announcement.announcement_mutes.find_by(account: user.account)).to_not be_nil
  44. end
  45. end
  46. end
  47. end