Add tests for ContactRetraction
This commit is contained in:
parent
c2b9b8ab54
commit
be8a1dfef4
4 changed files with 99 additions and 47 deletions
|
|
@ -63,7 +63,7 @@ describe "attack vectors", type: :request do
|
||||||
expect(contact).to be_sharing
|
expect(contact).to be_sharing
|
||||||
|
|
||||||
post_message(
|
post_message(
|
||||||
generate_payload(Diaspora::Federation::Entities.retraction(Retraction.for(contact)), alice, bob), bob
|
generate_payload(Diaspora::Federation::Entities.retraction(ContactRetraction.for(contact)), alice, bob), bob
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(bob.contacts(true).find_by(person_id: eve.person.id)).to be_sharing
|
expect(bob.contacts(true).find_by(person_id: eve.person.id)).to be_sharing
|
||||||
|
|
|
||||||
66
spec/lib/diaspora/federated/contact_retraction_spec.rb
Normal file
66
spec/lib/diaspora/federated/contact_retraction_spec.rb
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
describe ContactRetraction do
|
||||||
|
let(:contact) { FactoryGirl.build(:contact, sharing: true, receiving: true) }
|
||||||
|
let(:retraction) { ContactRetraction.for(contact) }
|
||||||
|
|
||||||
|
describe "#subscribers" do
|
||||||
|
it "contains the contact person" do
|
||||||
|
expect(retraction.subscribers).to eq([contact.person])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#data" do
|
||||||
|
it "contains the hash with all data from the federation-retraction" do
|
||||||
|
federation_retraction_data = Diaspora::Federation::Entities.contact(contact).to_h
|
||||||
|
federation_retraction_data[:sharing] = false
|
||||||
|
federation_retraction_data[:following] = false
|
||||||
|
|
||||||
|
expect(retraction.data).to eq(federation_retraction_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".retraction_data_for" do
|
||||||
|
it "creates a retraction for a contact" do
|
||||||
|
contact = FactoryGirl.build(:contact, sharing: false, receiving: false)
|
||||||
|
expect(Diaspora::Federation::Entities).to receive(:contact).with(contact).and_call_original
|
||||||
|
data = ContactRetraction.retraction_data_for(contact)
|
||||||
|
|
||||||
|
expect(data[:author]).to eq(contact.user.diaspora_handle)
|
||||||
|
expect(data[:recipient]).to eq(contact.person.diaspora_handle)
|
||||||
|
expect(data[:sharing]).to be_falsey
|
||||||
|
expect(data[:following]).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".for" do
|
||||||
|
it "creates a retraction for a contact" do
|
||||||
|
expect(ContactRetraction).to receive(:retraction_data_for).with(contact)
|
||||||
|
ContactRetraction.for(contact)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "create contact entity with 'sharing' and 'following' set to false" do
|
||||||
|
data = ContactRetraction.for(contact).data
|
||||||
|
expect(data[:sharing]).to be_falsey
|
||||||
|
expect(data[:following]).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".defer_dispatch" do
|
||||||
|
it "queues a job to send the retraction later" do
|
||||||
|
contact = FactoryGirl.build(:contact, user: local_luke, person: remote_raphael)
|
||||||
|
retraction = ContactRetraction.for(contact)
|
||||||
|
federation_retraction_data = Diaspora::Federation::Entities.contact(contact).to_h
|
||||||
|
|
||||||
|
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
||||||
|
local_luke.id, "ContactRetraction", federation_retraction_data, [remote_raphael.id], {}
|
||||||
|
)
|
||||||
|
|
||||||
|
retraction.defer_dispatch(local_luke)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#public?" do
|
||||||
|
it "returns false for a contact retraction" do
|
||||||
|
expect(retraction.public?).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -18,15 +18,36 @@ describe Retraction do
|
||||||
|
|
||||||
describe "#data" do
|
describe "#data" do
|
||||||
it "contains the hash with all data from the federation-retraction" do
|
it "contains the hash with all data from the federation-retraction" do
|
||||||
federation_retraction_data = Diaspora::Federation::Entities.retraction_data_for(post)
|
expect(retraction.data[:target_guid]).to eq(post.guid)
|
||||||
|
expect(retraction.data[:target]).to eq(Diaspora::Federation::Entities.related_entity(post).to_h)
|
||||||
|
expect(retraction.data[:target_type]).to eq("Post")
|
||||||
|
expect(retraction.data[:author]).to eq(alice.diaspora_handle)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
expect(retraction.data).to eq(federation_retraction_data)
|
describe ".retraction_data_for" do
|
||||||
|
it "creates the retraction data for a post" do
|
||||||
|
data = Retraction.retraction_data_for(post)
|
||||||
|
expect(data[:target_guid]).to eq(post.guid)
|
||||||
|
expect(data[:target]).to eq(Diaspora::Federation::Entities.related_entity(post).to_h)
|
||||||
|
expect(data[:target_type]).to eq("Post")
|
||||||
|
expect(data[:author]).to eq(alice.diaspora_handle)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates the retraction data for a relayable" do
|
||||||
|
comment = FactoryGirl.create(:comment, author: alice.person, post: post)
|
||||||
|
|
||||||
|
data = Retraction.retraction_data_for(comment)
|
||||||
|
expect(data[:target_guid]).to eq(comment.guid)
|
||||||
|
expect(data[:target]).to eq(Diaspora::Federation::Entities.related_entity(comment).to_h)
|
||||||
|
expect(data[:target_type]).to eq("Comment")
|
||||||
|
expect(data[:author]).to eq(alice.diaspora_handle)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".for" do
|
describe ".for" do
|
||||||
it "creates a retraction for a post" do
|
it "creates a retraction for a post" do
|
||||||
expect(Diaspora::Federation::Entities).to receive(:retraction_data_for).with(post)
|
expect(Retraction).to receive(:retraction_data_for).with(post)
|
||||||
|
|
||||||
Retraction.for(post)
|
Retraction.for(post)
|
||||||
end
|
end
|
||||||
|
|
@ -34,18 +55,10 @@ describe Retraction do
|
||||||
it "creates a retraction for a relayable" do
|
it "creates a retraction for a relayable" do
|
||||||
comment = FactoryGirl.create(:comment, author: alice.person, post: post)
|
comment = FactoryGirl.create(:comment, author: alice.person, post: post)
|
||||||
|
|
||||||
expect(Diaspora::Federation::Entities).to receive(:retraction_data_for).with(comment)
|
expect(Retraction).to receive(:retraction_data_for).with(comment)
|
||||||
|
|
||||||
Retraction.for(comment)
|
Retraction.for(comment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a retraction for a contact" do
|
|
||||||
contact = FactoryGirl.build(:contact, receiving: false)
|
|
||||||
|
|
||||||
expect(Diaspora::Federation::Entities).to receive(:retraction_data_for).with(contact)
|
|
||||||
|
|
||||||
Retraction.for(contact)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".defer_dispatch" do
|
describe ".defer_dispatch" do
|
||||||
|
|
@ -55,7 +68,7 @@ describe Retraction do
|
||||||
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
||||||
|
|
||||||
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
||||||
local_luke.id, federation_retraction.to_h, [remote_raphael.id], service_types: []
|
local_luke.id, "Retraction", federation_retraction.to_h, [remote_raphael.id], service_types: []
|
||||||
)
|
)
|
||||||
|
|
||||||
retraction.defer_dispatch(local_luke)
|
retraction.defer_dispatch(local_luke)
|
||||||
|
|
@ -71,7 +84,7 @@ describe Retraction do
|
||||||
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
||||||
|
|
||||||
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
||||||
alice.id, federation_retraction.to_h, [], service_types: ["Services::Twitter"], tweet_id: "123"
|
alice.id, "Retraction", federation_retraction.to_h, [], service_types: ["Services::Twitter"], tweet_id: "123"
|
||||||
)
|
)
|
||||||
|
|
||||||
retraction.defer_dispatch(alice)
|
retraction.defer_dispatch(alice)
|
||||||
|
|
@ -82,7 +95,7 @@ describe Retraction do
|
||||||
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
||||||
|
|
||||||
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
||||||
alice.id, federation_retraction.to_h, [], service_types: []
|
alice.id, "Retraction", federation_retraction.to_h, [], service_types: []
|
||||||
)
|
)
|
||||||
|
|
||||||
retraction.defer_dispatch(alice)
|
retraction.defer_dispatch(alice)
|
||||||
|
|
@ -95,7 +108,7 @@ describe Retraction do
|
||||||
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
||||||
|
|
||||||
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
||||||
local_luke.id, federation_retraction.to_h, [remote_raphael.id], {}
|
local_luke.id, "Retraction", federation_retraction.to_h, [remote_raphael.id], {}
|
||||||
)
|
)
|
||||||
|
|
||||||
retraction.defer_dispatch(local_luke)
|
retraction.defer_dispatch(local_luke)
|
||||||
|
|
@ -110,7 +123,7 @@ describe Retraction do
|
||||||
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
||||||
|
|
||||||
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
||||||
local_luke.id, federation_retraction.to_h, [remote_raphael.id], {}
|
local_luke.id, "Retraction", federation_retraction.to_h, [remote_raphael.id], {}
|
||||||
)
|
)
|
||||||
|
|
||||||
retraction.defer_dispatch(local_luke)
|
retraction.defer_dispatch(local_luke)
|
||||||
|
|
@ -121,7 +134,7 @@ describe Retraction do
|
||||||
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
federation_retraction = Diaspora::Federation::Entities.retraction(retraction)
|
||||||
|
|
||||||
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
expect(Workers::DeferredRetraction).to receive(:perform_async).with(
|
||||||
local_luke.id, federation_retraction.to_h, [], {}
|
local_luke.id, "Retraction", federation_retraction.to_h, [], {}
|
||||||
)
|
)
|
||||||
|
|
||||||
retraction.defer_dispatch(local_luke, false)
|
retraction.defer_dispatch(local_luke, false)
|
||||||
|
|
@ -156,10 +169,5 @@ describe Retraction do
|
||||||
private_post = alice.post(:status_message, text: "destroy!", to: alice.aspects.first.id)
|
private_post = alice.post(:status_message, text: "destroy!", to: alice.aspects.first.id)
|
||||||
expect(Retraction.for(private_post).public?).to be_falsey
|
expect(Retraction.for(private_post).public?).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false for a contact retraction" do
|
|
||||||
contact = FactoryGirl.create(:contact, receiving: false)
|
|
||||||
expect(Retraction.for(contact).public?).to be_falsey
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ describe Diaspora::Federation::Entities do
|
||||||
|
|
||||||
it "builds a Contact for a Contact retraction" do
|
it "builds a Contact for a Contact retraction" do
|
||||||
target = FactoryGirl.create(:contact, receiving: false)
|
target = FactoryGirl.create(:contact, receiving: false)
|
||||||
retraction = Retraction.for(target)
|
retraction = ContactRetraction.for(target)
|
||||||
federation_entity = described_class.build(retraction)
|
federation_entity = described_class.build(retraction)
|
||||||
|
|
||||||
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Contact)
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Contact)
|
||||||
|
|
@ -297,26 +297,4 @@ describe Diaspora::Federation::Entities do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".retraction_data_for" do
|
|
||||||
it "returns the data for a Photo retraction" do
|
|
||||||
target = FactoryGirl.create(:photo, author: alice.person)
|
|
||||||
retraction_data = described_class.retraction_data_for(target)
|
|
||||||
|
|
||||||
expect(retraction_data[:author]).to eq(target.author.diaspora_handle)
|
|
||||||
expect(retraction_data[:target_guid]).to eq(target.guid)
|
|
||||||
expect(retraction_data[:target_type]).to eq("Photo")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the data for a Contact entity" do
|
|
||||||
target = FactoryGirl.create(:contact, receiving: false)
|
|
||||||
retraction_data = described_class.retraction_data_for(target)
|
|
||||||
|
|
||||||
expect(retraction_data[:author]).to eq(target.user.diaspora_handle)
|
|
||||||
expect(retraction_data[:recipient]).to eq(target.person.diaspora_handle)
|
|
||||||
expect(retraction_data[:sharing]).to be_falsey
|
|
||||||
expect(retraction_data[:following]).to be_falsey
|
|
||||||
expect(retraction_data[:target_type]).to eq("Contact")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue