diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-02-12 17:28:15 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-02-12 17:30:15 +0100 |
commit | 720ff55262fec0abc630a613a4f3564b98b689dc (patch) | |
tree | 75a93b493dcec4cacd62f0ffcb55ad43891855c4 /spec/services/favourite_service_spec.rb | |
parent | 446267d1bfaba0f596544186361553118615e942 (diff) |
Adding more unit tests. Fixing Salmon slaps XML
Diffstat (limited to 'spec/services/favourite_service_spec.rb')
-rw-r--r-- | spec/services/favourite_service_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/services/favourite_service_spec.rb b/spec/services/favourite_service_spec.rb index eb961c28e..36f1b64d4 100644 --- a/spec/services/favourite_service_spec.rb +++ b/spec/services/favourite_service_spec.rb @@ -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 |