announcements_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'API V1 Announcements' do
  4. let(:user) { Fabricate(:user) }
  5. let(:scopes) { 'read' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. let!(:announcement) { Fabricate(:announcement) }
  9. describe 'GET /api/v1/announcements' do
  10. context 'without token' do
  11. it 'returns http unprocessable entity' do
  12. get '/api/v1/announcements'
  13. expect(response).to have_http_status(422)
  14. expect(response.content_type)
  15. .to start_with('application/json')
  16. end
  17. end
  18. context 'with token' do
  19. before do
  20. get '/api/v1/announcements', headers: headers
  21. end
  22. it 'returns http success' do
  23. expect(response).to have_http_status(200)
  24. expect(response.content_type)
  25. .to start_with('application/json')
  26. end
  27. end
  28. end
  29. describe 'POST /api/v1/announcements/:id/dismiss' do
  30. context 'without token' do
  31. it 'returns http unauthorized' do
  32. post "/api/v1/announcements/#{announcement.id}/dismiss"
  33. expect(response).to have_http_status(401)
  34. expect(response.content_type)
  35. .to start_with('application/json')
  36. end
  37. end
  38. context 'with token' do
  39. let(:scopes) { 'write:accounts' }
  40. before do
  41. post "/api/v1/announcements/#{announcement.id}/dismiss", headers: headers
  42. end
  43. it 'dismisses announcement', :aggregate_failures do
  44. expect(response).to have_http_status(200)
  45. expect(response.content_type)
  46. .to start_with('application/json')
  47. expect(announcement.announcement_mutes.find_by(account: user.account)).to_not be_nil
  48. end
  49. end
  50. end
  51. end