Skip to content

Commit

Permalink
Backport 'User role is defined for digest notifications to scope tran…
Browse files Browse the repository at this point in the history
…slations correctly' to v0.27 (#10738)

* initial commit

* notificationspec

* shared-example

* meeting-debate-specs-open

* tests-unfinished

* tests-finished

* test-content-change

* content-change

* refactored-tests

* moved-test-specific-shared-context-to-test

* resolved-conflict

---------

Co-authored-by: JoonasAapro <110532525+JoonasAapro@users.noreply.github.com>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
  • Loading branch information
3 people committed Apr 21, 2023
1 parent bfd4800 commit e27da06
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 0 deletions.
Expand Up @@ -27,6 +27,7 @@ def event
@event ||= event_class.constantize.new(
resource: resource,
user: user,
user_role: user_role,
event_name: event_name,
extra: extra
)
Expand Down
1 change: 1 addition & 0 deletions decidim-core/lib/decidim/core/test.rb
Expand Up @@ -75,3 +75,4 @@
require "decidim/core/test/shared_examples/resource_endorsed_event_examples"
require "decidim/core/test/shared_examples/versions_controller_examples"
require "decidim/core/test/shared_examples/mcell_examples"
require "decidim/core/test/shared_examples/digest_mail_examples"
@@ -0,0 +1,33 @@
# frozen_string_literal: true

shared_context "when sends the notification digest" do
context "when daily notification mail" do
let(:user) { create(:user, :admin, organization: organization, notifications_sending_frequency: "daily") }

it_behaves_like "notification digest mail"
end

context "when weekly notification mail" do
let(:user) { create(:user, :admin, organization: organization, notifications_sending_frequency: "weekly") }

it_behaves_like "notification digest mail"
end
end

shared_examples_for "notification digest mail" do
context "when a notificable event takes place" do
let!(:organization) { create(:organization) }
let!(:participatory_space) { create(:participatory_process, organization: organization) }

it "sends a notification to the user's email" do
perform_enqueued_jobs do
expect(command.call).to broadcast(:ok)
Decidim::Notification.last.update(created_at: 1.day.ago)
Decidim::EmailNotificationsDigestGeneratorJob.perform_now(user.id, user.notifications_sending_frequency)
end

expect(last_email_body.length).to be_positive
expect(last_email_body).not_to include("translation missing")
end
end
end
@@ -0,0 +1,50 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Debates
describe CloseDebateEvent do
describe "notification digest mail" do
let!(:component) { create(:debates_component, organization: organization, participatory_space: participatory_space) }
let(:admin) { create(:user, :admin, organization: organization) }
let!(:follow) { create(:follow, followable: record, user: user) }
let(:params) do
{
conclusions: "Example conclusion",
id: record.id
}
end

let!(:record) do
create(
:debate,
component: component,
title: { en: "Event notifier" },
description: { en: "This debate is for testing purposes" },
instructions: { en: "Use this debate for testing" }
)
end

let(:form) { Decidim::Debates::Admin::CloseDebateForm.from_params(params).with_context(current_user: admin) }
let!(:command) { Decidim::Debates::Admin::CloseDebate.new(form) }

before do
allow(command).to receive(:debate).and_return(record)
end

context "when daily notification mail" do
let!(:user) { create(:user, organization: organization, notifications_sending_frequency: "daily") }

it_behaves_like "notification digest mail"
end

context "when weekly notification mail" do
let!(:user) { create(:user, organization: organization, notifications_sending_frequency: "weekly") }

it_behaves_like "notification digest mail"
end
end
end
end
end
Expand Up @@ -22,4 +22,54 @@
expect(subject.resource_text).to eq translated(resource.description)
end
end

describe "notification digest mail" do
let!(:component) { create(:meeting_component, organization: organization, participatory_space: participatory_space) }
let(:admin) { create(:user, :admin, organization: organization, notifications_sending_frequency: "daily") }
let!(:record) do
create(
:meeting,
:published,
component: component,
author: admin,
title: { en: "Event notifier" },
description: { en: "This meeting is for testing purposes" }
)
end

let!(:follow) { create(:follow, followable: record, user: user) }

let(:params) do
{
closing_report: { en: "This meeting is closed" },
video_url: "",
audio_url: "",
closing_visible: true,
attendees_count: 1,
contributions_count: 1,
attending_organizations: ""
}
end

let(:form) do
Decidim::Meetings::Admin::CloseMeetingForm.from_params(params).with_context(
current_component: component,
current_user: admin,
current_organization: organization
)
end
let(:command) { Decidim::Meetings::Admin::CloseMeeting.new(form, record) }

context "when daily notification mail" do
let(:user) { create(:user, organization: organization, notifications_sending_frequency: "daily") }

it_behaves_like "notification digest mail"
end

context "when weekly notification mail" do
let(:user) { create(:user, organization: organization, notifications_sending_frequency: "weekly") }

it_behaves_like "notification digest mail"
end
end
end
Expand Up @@ -118,6 +118,51 @@ module Admin
subject
end
end

context "when proposal answered" do
shared_context "with correct user scoping in notification digest mail" do
let!(:component) { create(:proposal_component, organization: organization) }
let!(:record) { create(:proposal, component: component, users: [user], title: { en: "Event notifier" }) }

let!(:form) do
Decidim::Proposals::Admin::ProposalAnswerForm.from_params(form_params).with_context(
current_user: user,
current_component: record.component,
current_organization: organization
)
end

let(:form_params) do
{
internal_state: internal_state,
answer: { en: "Example answer" },
cost: 2000,
cost_report: { en: "Example report" },
execution_period: { en: "Example execution period" }
}
end

let!(:command) { Decidim::Proposals::Admin::AnswerProposal.new(form, record) }
end

include_context "with correct user scoping in notification digest mail" do
let(:internal_state) { "accepted" }

it_behaves_like "when sends the notification digest"
end

include_context "with correct user scoping in notification digest mail" do
let(:internal_state) { "rejected" }

it_behaves_like "when sends the notification digest"
end

include_context "with correct user scoping in notification digest mail" do
let(:internal_state) { "evaluating" }

it_behaves_like "when sends the notification digest"
end
end
end
end
end
Expand Down

0 comments on commit e27da06

Please sign in to comment.