parent
446267d1bf
commit
720ff55262
@ -0,0 +1,49 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe AuthorizeFollowService do |
||||
let(:sender) { Fabricate(:account, username: 'alice') } |
||||
|
||||
subject { AuthorizeFollowService.new } |
||||
|
||||
describe 'local' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } |
||||
|
||||
before do |
||||
FollowRequest.create(account: bob, target_account: sender) |
||||
subject.call(bob, sender) |
||||
end |
||||
|
||||
it 'removes follow request' do |
||||
expect(bob.requested?(sender)).to be false |
||||
end |
||||
|
||||
it 'creates follow relation' do |
||||
expect(bob.following?(sender)).to be true |
||||
end |
||||
end |
||||
|
||||
describe 'remote' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account } |
||||
|
||||
before do |
||||
FollowRequest.create(account: bob, target_account: sender) |
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {}) |
||||
subject.call(bob, sender) |
||||
end |
||||
|
||||
it 'removes follow request' do |
||||
expect(bob.requested?(sender)).to be false |
||||
end |
||||
|
||||
it 'creates follow relation' do |
||||
expect(bob.following?(sender)).to be true |
||||
end |
||||
|
||||
it 'sends a follow request authorization salmon slap' do |
||||
expect(a_request(:post, "http://salmon.example.com/").with { |req| |
||||
xml = OStatus2::Salmon.new.unpack(req.body) |
||||
xml.match(TagManager::VERBS[:authorize]) |
||||
}).to have_been_made.once |
||||
end |
||||
end |
||||
end |
@ -1,5 +1,39 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe BlockService do |
||||
let(:sender) { Fabricate(:account, username: 'alice') } |
||||
|
||||
subject { BlockService.new } |
||||
|
||||
describe 'local' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } |
||||
|
||||
before do |
||||
subject.call(sender, bob) |
||||
end |
||||
|
||||
it 'creates a blocking relation' do |
||||
expect(sender.blocking?(bob)).to be true |
||||
end |
||||
end |
||||
|
||||
describe 'remote' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account } |
||||
|
||||
before do |
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {}) |
||||
subject.call(sender, bob) |
||||
end |
||||
|
||||
it 'creates a blocking relation' do |
||||
expect(sender.blocking?(bob)).to be true |
||||
end |
||||
|
||||
it 'sends a block salmon slap' do |
||||
expect(a_request(:post, "http://salmon.example.com/").with { |req| |
||||
xml = OStatus2::Salmon.new.unpack(req.body) |
||||
xml.match(TagManager::VERBS[:block]) |
||||
}).to have_been_made.once |
||||
end |
||||
end |
||||
end |
||||
|
@ -1,5 +1,41 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe FavouriteService do |
||||
let(:sender) { Fabricate(:account, username: 'alice') } |
||||
|
||||
subject { FavouriteService.new } |
||||
|
||||
describe 'local' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } |
||||
let(:status) { Fabricate(:status, account: bob) } |
||||
|
||||
before do |
||||
subject.call(sender, status) |
||||
end |
||||
|
||||
it 'creates a favourite' do |
||||
expect(status.favourites.first).to_not be_nil |
||||
end |
||||
end |
||||
|
||||
describe 'remote' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account } |
||||
let(:status) { Fabricate(:status, account: bob, uri: 'tag:example.com:blahblah') } |
||||
|
||||
before do |
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {}) |
||||
subject.call(sender, status) |
||||
end |
||||
|
||||
it 'creates a favourite' do |
||||
expect(status.favourites.first).to_not be_nil |
||||
end |
||||
|
||||
it 'sends a salmon slap' do |
||||
expect(a_request(:post, "http://salmon.example.com/").with { |req| |
||||
xml = OStatus2::Salmon.new.unpack(req.body) |
||||
xml.match(TagManager::VERBS[:favorite]) |
||||
}).to have_been_made.once |
||||
end |
||||
end |
||||
end |
||||
|
@ -1,9 +1,75 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe FollowService do |
||||
let(:sender) { Fabricate(:account, username: 'alice') } |
||||
|
||||
subject { FollowService.new } |
||||
|
||||
it 'creates a following relation' |
||||
it 'creates local account for remote user' |
||||
it 'sends follow to the remote user' |
||||
context 'local account' do |
||||
describe 'locked account' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob')).account } |
||||
|
||||
before do |
||||
subject.call(sender, bob.acct) |
||||
end |
||||
|
||||
it 'creates a follow request' do |
||||
expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil |
||||
end |
||||
end |
||||
|
||||
describe 'unlocked account' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } |
||||
|
||||
before do |
||||
subject.call(sender, bob.acct) |
||||
end |
||||
|
||||
it 'creates a following relation' do |
||||
expect(sender.following?(bob)).to be true |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'remote account' do |
||||
describe 'locked account' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account } |
||||
|
||||
before do |
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {}) |
||||
subject.call(sender, bob.acct) |
||||
end |
||||
|
||||
it 'creates a follow request' do |
||||
expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil |
||||
end |
||||
|
||||
it 'sends a follow request salmon slap' do |
||||
expect(a_request(:post, "http://salmon.example.com/").with { |req| |
||||
xml = OStatus2::Salmon.new.unpack(req.body) |
||||
xml.match(TagManager::VERBS[:request_friend]) |
||||
}).to have_been_made.once |
||||
end |
||||
end |
||||
|
||||
describe 'unlocked account' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account } |
||||
|
||||
before do |
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {}) |
||||
subject.call(sender, bob.acct) |
||||
end |
||||
|
||||
it 'creates a following relation' do |
||||
expect(sender.following?(bob)).to be true |
||||
end |
||||
|
||||
it 'sends a follow salmon slap' do |
||||
expect(a_request(:post, "http://salmon.example.com/").with { |req| |
||||
xml = OStatus2::Salmon.new.unpack(req.body) |
||||
xml.match(TagManager::VERBS[:follow]) |
||||
}).to have_been_made.once |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
@ -0,0 +1,49 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe RejectFollowService do |
||||
let(:sender) { Fabricate(:account, username: 'alice') } |
||||
|
||||
subject { RejectFollowService.new } |
||||
|
||||
describe 'local' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } |
||||
|
||||
before do |
||||
FollowRequest.create(account: bob, target_account: sender) |
||||
subject.call(bob, sender) |
||||
end |
||||
|
||||
it 'removes follow request' do |
||||
expect(bob.requested?(sender)).to be false |
||||
end |
||||
|
||||
it 'does not create follow relation' do |
||||
expect(bob.following?(sender)).to be false |
||||
end |
||||
end |
||||
|
||||
describe 'remote' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account } |
||||
|
||||
before do |
||||
FollowRequest.create(account: bob, target_account: sender) |
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {}) |
||||
subject.call(bob, sender) |
||||
end |
||||
|
||||
it 'removes follow request' do |
||||
expect(bob.requested?(sender)).to be false |
||||
end |
||||
|
||||
it 'does not create follow relation' do |
||||
expect(bob.following?(sender)).to be false |
||||
end |
||||
|
||||
it 'sends a follow request rejection salmon slap' do |
||||
expect(a_request(:post, "http://salmon.example.com/").with { |req| |
||||
xml = OStatus2::Salmon.new.unpack(req.body) |
||||
xml.match(TagManager::VERBS[:reject]) |
||||
}).to have_been_made.once |
||||
end |
||||
end |
||||
end |
@ -1,5 +1,41 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe UnblockService do |
||||
let(:sender) { Fabricate(:account, username: 'alice') } |
||||
|
||||
subject { UnblockService.new } |
||||
|
||||
describe 'local' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } |
||||
|
||||
before do |
||||
sender.block!(bob) |
||||
subject.call(sender, bob) |
||||
end |
||||
|
||||
it 'destroys the blocking relation' do |
||||
expect(sender.blocking?(bob)).to be false |
||||
end |
||||
end |
||||
|
||||
describe 'remote' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account } |
||||
|
||||
before do |
||||
sender.block!(bob) |
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {}) |
||||
subject.call(sender, bob) |
||||
end |
||||
|
||||
it 'destroys the blocking relation' do |
||||
expect(sender.following?(bob)).to be false |
||||
end |
||||
|
||||
it 'sends an unblock salmon slap' do |
||||
expect(a_request(:post, "http://salmon.example.com/").with { |req| |
||||
xml = OStatus2::Salmon.new.unpack(req.body) |
||||
xml.match(TagManager::VERBS[:unblock]) |
||||
}).to have_been_made.once |
||||
end |
||||
end |
||||
end |
||||
|
@ -1,8 +1,41 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe UnfollowService do |
||||
let(:sender) { Fabricate(:account, username: 'alice') } |
||||
|
||||
subject { UnfollowService.new } |
||||
|
||||
it 'destroys the following relation' |
||||
it 'sends remote interaction for remote user' |
||||
describe 'local' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } |
||||
|
||||
before do |
||||
sender.follow!(bob) |
||||
subject.call(sender, bob) |
||||
end |
||||
|
||||
it 'destroys the following relation' do |
||||
expect(sender.following?(bob)).to be false |
||||
end |
||||
end |
||||
|
||||
describe 'remote' do |
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account } |
||||
|
||||
before do |
||||
sender.follow!(bob) |
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {}) |
||||
subject.call(sender, bob) |
||||
end |
||||
|
||||
it 'destroys the following relation' do |
||||
expect(sender.following?(bob)).to be false |
||||
end |
||||
|
||||
it 'sends an unfollow salmon slap' do |
||||
expect(a_request(:post, "http://salmon.example.com/").with { |req| |
||||
xml = OStatus2::Salmon.new.unpack(req.body) |
||||
xml.match(TagManager::VERBS[:unfollow]) |
||||
}).to have_been_made.once |
||||
end |
||||
end |
||||
end |
||||
|
Loading…
Reference in new issue