2020-01-24 08:00:13 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-03-02 03:24:45 +11:00
|
|
|
RSpec.describe 'API V1 Announcements Reactions' do
|
2020-01-24 08:00:13 +11:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:scopes) { 'write:favourites' }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
2024-03-02 03:24:45 +11:00
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
2020-01-24 08:00:13 +11:00
|
|
|
|
|
|
|
let!(:announcement) { Fabricate(:announcement) }
|
|
|
|
|
2024-03-02 03:24:45 +11:00
|
|
|
describe 'PUT /api/v1/announcements/:announcement_id/reactions/:id' do
|
2020-01-24 08:00:13 +11:00
|
|
|
context 'without token' do
|
|
|
|
it 'returns http unauthorized' do
|
2024-03-02 03:24:45 +11:00
|
|
|
put "/api/v1/announcements/#{announcement.id}/reactions/#{escaped_emoji}"
|
|
|
|
|
2024-09-20 23:13:04 +10:00
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2020-01-24 08:00:13 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with token' do
|
|
|
|
before do
|
2024-03-02 03:24:45 +11:00
|
|
|
put "/api/v1/announcements/#{announcement.id}/reactions/#{escaped_emoji}", headers: headers
|
2020-01-24 08:00:13 +11:00
|
|
|
end
|
|
|
|
|
2023-10-13 23:42:09 +11:00
|
|
|
it 'creates reaction', :aggregate_failures do
|
2020-01-24 08:00:13 +11:00
|
|
|
expect(response).to have_http_status(200)
|
2024-09-20 23:13:04 +10:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2020-01-24 08:00:13 +11:00
|
|
|
expect(announcement.announcement_reactions.find_by(name: '😂', account: user.account)).to_not be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-02 03:24:45 +11:00
|
|
|
describe 'DELETE /api/v1/announcements/:announcement_id/reactions/:id' do
|
2020-01-24 08:00:13 +11:00
|
|
|
before do
|
|
|
|
announcement.announcement_reactions.create!(account: user.account, name: '😂')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without token' do
|
|
|
|
it 'returns http unauthorized' do
|
2024-03-02 03:24:45 +11:00
|
|
|
delete "/api/v1/announcements/#{announcement.id}/reactions/#{escaped_emoji}"
|
2024-09-20 23:13:04 +10:00
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2020-01-24 08:00:13 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with token' do
|
|
|
|
before do
|
2024-03-02 03:24:45 +11:00
|
|
|
delete "/api/v1/announcements/#{announcement.id}/reactions/#{escaped_emoji}", headers: headers
|
2020-01-24 08:00:13 +11:00
|
|
|
end
|
|
|
|
|
2023-10-13 23:42:09 +11:00
|
|
|
it 'creates reaction', :aggregate_failures do
|
2020-01-24 08:00:13 +11:00
|
|
|
expect(response).to have_http_status(200)
|
2024-09-20 23:13:04 +10:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2020-01-24 08:00:13 +11:00
|
|
|
expect(announcement.announcement_reactions.find_by(name: '😂', account: user.account)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-03-02 03:24:45 +11:00
|
|
|
|
|
|
|
def escaped_emoji
|
|
|
|
CGI.escape('😂')
|
|
|
|
end
|
2020-01-24 08:00:13 +11:00
|
|
|
end
|