fix federation tests
This commit is contained in:
parent
3a5990c552
commit
dfe32a5e4b
5 changed files with 41 additions and 51 deletions
|
|
@ -15,28 +15,24 @@ def create_remote_user(pod)
|
|||
pod: Pod.find_or_create_by(url: "http://#{pod}"),
|
||||
diaspora_handle: "#{user.username}@#{pod}")
|
||||
)
|
||||
allow(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
.with(:fetch_private_key_by_diaspora_id, user.diaspora_handle) {
|
||||
user.encryption_key
|
||||
}
|
||||
allow(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||
:fetch_private_key, user.diaspora_handle
|
||||
) { user.encryption_key }
|
||||
end
|
||||
end
|
||||
|
||||
def create_relayable_entity(entity_name, target, diaspora_id, parent_author_key)
|
||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
.with(
|
||||
:fetch_author_private_key_by_entity_guid,
|
||||
FactoryGirl.build(entity_name).parent_type,
|
||||
target.guid
|
||||
)
|
||||
.and_return(parent_author_key)
|
||||
def create_relayable_entity(entity_name, parent, diaspora_id)
|
||||
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||
:fetch_private_key, alice.diaspora_handle
|
||||
).and_return(nil) if parent == local_parent
|
||||
|
||||
FactoryGirl.build(
|
||||
entity_name,
|
||||
conversation_guid: target.guid,
|
||||
parent_guid: target.guid,
|
||||
conversation_guid: parent.guid,
|
||||
parent_guid: parent.guid,
|
||||
author: diaspora_id,
|
||||
poll_answer_guid: target.respond_to?(:poll_answers) ? target.poll_answers.first.guid : nil
|
||||
poll_answer_guid: parent.respond_to?(:poll_answers) ? parent.poll_answers.first.guid : nil,
|
||||
parent: Diaspora::Federation::Entities.related_entity(parent)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@ require "integration/federation/shared_receive_stream_items"
|
|||
|
||||
describe "Receive federation messages feature" do
|
||||
before do
|
||||
allow(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
.with(:queue_public_receive, any_args).and_call_original
|
||||
allow(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
.with(:queue_private_receive, any_args).and_call_original
|
||||
allow(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||
:queue_public_receive, any_args
|
||||
).and_call_original
|
||||
allow(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||
:queue_private_receive, any_args
|
||||
).and_call_original
|
||||
end
|
||||
|
||||
let(:sender) { remote_user_on_pod_b }
|
||||
|
|
@ -80,10 +82,9 @@ describe "Receive federation messages feature" do
|
|||
post_message(generate_xml(entity, sender, alice), alice)
|
||||
|
||||
expect(alice.contacts.count).to eq(2)
|
||||
new_contact = alice.contacts.order(created_at: :asc).last
|
||||
new_contact = alice.contacts.find {|c| c.person.diaspora_handle == sender_id }
|
||||
expect(new_contact).not_to be_nil
|
||||
expect(new_contact.sharing).to eq(true)
|
||||
expect(new_contact.person.diaspora_handle).to eq(sender_id)
|
||||
|
||||
expect(
|
||||
Notifications::StartedSharing.exists?(
|
||||
|
|
@ -130,14 +131,14 @@ describe "Receive federation messages feature" do
|
|||
end
|
||||
|
||||
context "with message" do
|
||||
let(:local_target) {
|
||||
let(:local_parent) {
|
||||
FactoryGirl.build(:conversation, author: alice.person).tap do |target|
|
||||
target.participants << remote_user_on_pod_b.person
|
||||
target.participants << remote_user_on_pod_c.person
|
||||
target.save
|
||||
end
|
||||
}
|
||||
let(:remote_target) {
|
||||
let(:remote_parent) {
|
||||
FactoryGirl.build(:conversation, author: remote_user_on_pod_b.person).tap do |target|
|
||||
target.participants << alice.person
|
||||
target.participants << remote_user_on_pod_c.person
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
shared_examples_for "it deals correctly with a relayable" do
|
||||
context "local" do
|
||||
let(:entity) { create_relayable_entity(entity_name, local_target, sender_id, nil) }
|
||||
let(:entity) { create_relayable_entity(entity_name, local_parent, sender_id) }
|
||||
|
||||
it "treats upstream receive correctly" do
|
||||
expect(Postzord::Dispatcher).to receive(:build).with(alice, kind_of(klass)).and_call_original
|
||||
|
|
@ -23,7 +23,7 @@ shared_examples_for "it deals correctly with a relayable" do
|
|||
|
||||
context "remote" do
|
||||
let(:author_id) { remote_user_on_pod_c.diaspora_handle }
|
||||
let(:entity) { create_relayable_entity(entity_name, remote_target, author_id, sender.encryption_key) }
|
||||
let(:entity) { create_relayable_entity(entity_name, remote_parent, author_id) }
|
||||
|
||||
it "treats downstream receive correctly" do
|
||||
expect(Postzord::Dispatcher).to receive(:build)
|
||||
|
|
|
|||
|
|
@ -1,17 +1,10 @@
|
|||
def retraction_entity(entity_name, target_object, sender)
|
||||
allow(DiasporaFederation.callbacks).to receive(:trigger)
|
||||
.with(
|
||||
:fetch_entity_author_id_by_guid,
|
||||
target_object.class.to_s,
|
||||
target_object.guid
|
||||
)
|
||||
.and_return(sender.encryption_key)
|
||||
|
||||
FactoryGirl.build(
|
||||
entity_name,
|
||||
author: sender.diaspora_handle,
|
||||
target_guid: target_object.guid,
|
||||
target_type: target_object.class.to_s
|
||||
target_type: target_object.class.to_s,
|
||||
target: Diaspora::Federation::Entities.related_entity(target_object)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -21,32 +21,32 @@ shared_examples_for "messages which are indifferent about sharing fact" do
|
|||
end
|
||||
|
||||
describe "with messages which require a status to operate on" do
|
||||
let(:local_target) { FactoryGirl.create(:status_message, author: alice.person, public: public) }
|
||||
let(:remote_target) { FactoryGirl.create(:status_message, author: remote_user_on_pod_b.person, public: public) }
|
||||
let(:local_parent) { FactoryGirl.create(:status_message, author: alice.person, public: public) }
|
||||
let(:remote_parent) { FactoryGirl.create(:status_message, author: remote_user_on_pod_b.person, public: public) }
|
||||
|
||||
describe "notifications are sent where required" do
|
||||
it "for comment on local post" do
|
||||
entity = create_relayable_entity(:comment_entity, local_target, remote_user_on_pod_b.diaspora_handle, nil)
|
||||
entity = create_relayable_entity(:comment_entity, local_parent, remote_user_on_pod_b.diaspora_handle)
|
||||
post_message(generate_xml(entity, sender, recipient), recipient)
|
||||
|
||||
expect(
|
||||
Notifications::CommentOnPost.exists?(
|
||||
recipient_id: alice.id,
|
||||
target_type: "Post",
|
||||
target_id: local_target.id
|
||||
target_id: local_parent.id
|
||||
)
|
||||
).to be_truthy
|
||||
end
|
||||
|
||||
it "for like on local post" do
|
||||
entity = create_relayable_entity(:like_entity, local_target, remote_user_on_pod_b.diaspora_handle, nil)
|
||||
entity = create_relayable_entity(:like_entity, local_parent, remote_user_on_pod_b.diaspora_handle)
|
||||
post_message(generate_xml(entity, sender, recipient), recipient)
|
||||
|
||||
expect(
|
||||
Notifications::Liked.exists?(
|
||||
recipient_id: alice.id,
|
||||
target_type: "Post",
|
||||
target_id: local_target.id
|
||||
target_id: local_parent.id
|
||||
)
|
||||
).to be_truthy
|
||||
end
|
||||
|
|
@ -62,13 +62,13 @@ shared_examples_for "messages which are indifferent about sharing fact" do
|
|||
end
|
||||
|
||||
context "with poll_participation" do
|
||||
let(:local_target) {
|
||||
let(:local_parent) {
|
||||
FactoryGirl.create(
|
||||
:poll,
|
||||
status_message: FactoryGirl.create(:status_message, author: alice.person, public: public)
|
||||
)
|
||||
}
|
||||
let(:remote_target) {
|
||||
let(:remote_parent) {
|
||||
FactoryGirl.create(
|
||||
:poll,
|
||||
status_message: FactoryGirl.create(:status_message, author: remote_user_on_pod_b.person, public: public)
|
||||
|
|
@ -102,22 +102,22 @@ shared_examples_for "messages which can't be send without sharing" do
|
|||
|
||||
describe "with messages which require a status to operate on" do
|
||||
let(:public) { recipient.nil? }
|
||||
let(:local_target) { FactoryGirl.create(:status_message, author: alice.person, public: public) }
|
||||
let(:remote_target) { FactoryGirl.create(:status_message, author: remote_user_on_pod_b.person, public: public) }
|
||||
let(:local_parent) { FactoryGirl.create(:status_message, author: alice.person, public: public) }
|
||||
let(:remote_parent) { FactoryGirl.create(:status_message, author: remote_user_on_pod_b.person, public: public) }
|
||||
|
||||
# this one shouldn't depend on the sharing fact. this must be fixed
|
||||
describe "notifications are sent where required" do
|
||||
it "for comment on remote post where we participate" do
|
||||
alice.participate!(remote_target)
|
||||
alice.participate!(remote_parent)
|
||||
author_id = remote_user_on_pod_c.diaspora_handle
|
||||
entity = create_relayable_entity(:comment_entity, remote_target, author_id, sender.encryption_key)
|
||||
entity = create_relayable_entity(:comment_entity, remote_parent, author_id)
|
||||
post_message(generate_xml(entity, sender, recipient), recipient)
|
||||
|
||||
expect(
|
||||
Notifications::AlsoCommented.exists?(
|
||||
recipient_id: alice.id,
|
||||
target_type: "Post",
|
||||
target_id: remote_target.id
|
||||
target_id: remote_parent.id
|
||||
)
|
||||
).to be_truthy
|
||||
end
|
||||
|
|
@ -132,14 +132,14 @@ shared_examples_for "messages which can't be send without sharing" do
|
|||
it_behaves_like "it retracts relayable object" do
|
||||
# case for to-upstream federation
|
||||
let(:target_object) {
|
||||
FactoryGirl.create(:comment, author: remote_user_on_pod_b.person, post: local_target)
|
||||
FactoryGirl.create(:comment, author: remote_user_on_pod_b.person, post: local_parent)
|
||||
}
|
||||
end
|
||||
|
||||
it_behaves_like "it retracts relayable object" do
|
||||
# case for to-downsteam federation
|
||||
let(:target_object) {
|
||||
FactoryGirl.create(:comment, author: remote_user_on_pod_c.person, post: remote_target)
|
||||
FactoryGirl.create(:comment, author: remote_user_on_pod_c.person, post: remote_parent)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -148,14 +148,14 @@ shared_examples_for "messages which can't be send without sharing" do
|
|||
it_behaves_like "it retracts relayable object" do
|
||||
# case for to-upstream federation
|
||||
let(:target_object) {
|
||||
FactoryGirl.create(:like, author: remote_user_on_pod_b.person, target: local_target)
|
||||
FactoryGirl.create(:like, author: remote_user_on_pod_b.person, target: local_parent)
|
||||
}
|
||||
end
|
||||
|
||||
it_behaves_like "it retracts relayable object" do
|
||||
# case for to-downsteam federation
|
||||
let(:target_object) {
|
||||
FactoryGirl.create(:like, author: remote_user_on_pod_c.person, target: remote_target)
|
||||
FactoryGirl.create(:like, author: remote_user_on_pod_c.person, target: remote_parent)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue