Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send notifications after transaction #46

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ def call
create_attachment if process_attachments?
create_gallery if process_gallery?
link_author_meeeting if form.created_in_meeting?
send_notification
end

send_notification

broadcast(:ok, proposal)
end

Expand Down Expand Up @@ -81,11 +82,13 @@ def link_author_meeeting
end

def send_notification
return unless proposal

Decidim::EventsManager.publish(
event: "decidim.events.proposals.proposal_published",
event_class: Decidim::Proposals::PublishProposalEvent,
resource: proposal,
followers: @proposal.participatory_space.followers,
followers: proposal.participatory_space.followers,
extra: {
participatory_space: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,40 @@ module Admin
expect(action_log.version).to be_present
end

it "notifies the space followers" do
follower = create(:user, organization: component.participatory_space.organization)
create(:follow, followable: component.participatory_space, user: follower)

expect(Decidim::EventsManager)
.to receive(:publish)
.with(
context "when followers" do
let(:follower) { create(:user, organization: component.participatory_space.organization) }
let!(:follow) { create(:follow, followable: component.participatory_space, user: follower) }
let(:data) do
{
event: "decidim.events.proposals.proposal_published",
event_class: Decidim::Proposals::PublishProposalEvent,
resource: kind_of(Decidim::Proposals::Proposal),
followers: [follower],
extra: {
participatory_space: true
}
)
}
end

it "notifies the space followers" do
expect(Decidim::EventsManager).to receive(:publish).with(data)

command.call
end

command.call
context "when active record is slow" do
let(:proposal) { build :proposal, component: component }

before do
allow(command).to receive(:proposal).and_return(nil)
end

it "does not notifies the space followers" do
expect(Decidim::EventsManager).not_to receive(:publish).with(data)

command.call
end
end
end

context "when geocoding is enabled" do
Expand Down