2020-01-23 21:00:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-03-01 16:24:45 +00:00
|
|
|
RSpec.describe 'API V1 Announcements' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:scopes) { 'read' }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
2020-01-23 21:00:13 +00:00
|
|
|
|
|
|
|
let!(:announcement) { Fabricate(:announcement) }
|
|
|
|
|
2024-03-01 16:24:45 +00:00
|
|
|
describe 'GET /api/v1/announcements' do
|
2020-01-23 21:00:13 +00:00
|
|
|
context 'without token' do
|
|
|
|
it 'returns http unprocessable entity' do
|
2024-03-01 16:24:45 +00:00
|
|
|
get '/api/v1/announcements'
|
|
|
|
|
2024-09-20 13:13:04 +00:00
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2020-01-23 21:00:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with token' do
|
|
|
|
before do
|
2024-03-01 16:24:45 +00:00
|
|
|
get '/api/v1/announcements', headers: headers
|
2020-01-23 21:00:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
expect(response).to have_http_status(200)
|
2024-09-20 13:13:04 +00:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2020-01-23 21:00:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-01 16:24:45 +00:00
|
|
|
describe 'POST /api/v1/announcements/:id/dismiss' do
|
2020-01-23 21:00:13 +00:00
|
|
|
context 'without token' do
|
|
|
|
it 'returns http unauthorized' do
|
2024-03-01 16:24:45 +00:00
|
|
|
post "/api/v1/announcements/#{announcement.id}/dismiss"
|
|
|
|
|
2024-09-20 13:13:04 +00:00
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2020-01-23 21:00:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with token' do
|
|
|
|
let(:scopes) { 'write:accounts' }
|
|
|
|
|
|
|
|
before do
|
2024-03-01 16:24:45 +00:00
|
|
|
post "/api/v1/announcements/#{announcement.id}/dismiss", headers: headers
|
2020-01-23 21:00:13 +00:00
|
|
|
end
|
|
|
|
|
2023-10-13 12:42:09 +00:00
|
|
|
it 'dismisses announcement', :aggregate_failures do
|
2020-01-23 21:00:13 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2024-09-20 13:13:04 +00:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2020-01-23 21:00:13 +00:00
|
|
|
expect(announcement.announcement_mutes.find_by(account: user.account)).to_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|