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