announcements_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. end
  15. end
  16. context 'with token' do
  17. before do
  18. get '/api/v1/announcements', headers: headers
  19. end
  20. it 'returns http success' do
  21. expect(response).to have_http_status(200)
  22. end
  23. end
  24. end
  25. describe 'POST /api/v1/announcements/:id/dismiss' do
  26. context 'without token' do
  27. it 'returns http unauthorized' do
  28. post "/api/v1/announcements/#{announcement.id}/dismiss"
  29. expect(response).to have_http_status 401
  30. end
  31. end
  32. context 'with token' do
  33. let(:scopes) { 'write:accounts' }
  34. before do
  35. post "/api/v1/announcements/#{announcement.id}/dismiss", headers: headers
  36. end
  37. it 'dismisses announcement', :aggregate_failures do
  38. expect(response).to have_http_status(200)
  39. expect(announcement.announcement_mutes.find_by(account: user.account)).to_not be_nil
  40. end
  41. end
  42. end
  43. end