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

feat: Allow to configure notifications_sending_frequency #183

Merged
merged 3 commits into from
Mar 1, 2024
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem "decidim-cache_cleaner"
gem "decidim-decidim_awesome"
gem "decidim-extended_socio_demographic_authorization_handler", git: "https://github.com/OpenSourcePolitics/decidim-module-extended_socio_demographic_authorization_handler.git",
branch: DECIDIM_BRANCH
gem "decidim-extra_user_fields", git: "https://github.com/PopulateTools/decidim-module-extra_user_fields.git", branch: "release/0.27-stable"
gem "decidim-extra_user_fields", git: "https://github.com/OpenSourcePolitics/decidim-module-extra_user_fields.git", branch: "feat/notifications_sending_frequency"
gem "decidim-friendly_signup", git: "https://github.com/OpenSourcePolitics/decidim-module-friendly_signup.git"
gem "decidim-gallery", git: "https://github.com/OpenSourcePolitics/decidim-module-gallery.git", branch: "fix/nokogiri_deps"
gem "decidim-homepage_interactive_map", git: "https://github.com/OpenSourcePolitics/decidim-module-homepage_interactive_map.git", branch: DECIDIM_BRANCH
Expand Down
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ GIT
decidim-extended_socio_demographic_authorization_handler (0.27.0)
decidim-core (~> 0.27)

GIT
remote: https://github.com/OpenSourcePolitics/decidim-module-extra_user_fields.git
revision: 9517905551332c4145796bc21ef5e035f99176b4
branch: feat/notifications_sending_frequency
specs:
decidim-extra_user_fields (0.27.2)
country_select (~> 4.0)
decidim-core (>= 0.27.0, < 0.28)
deface (~> 1.5)

GIT
remote: https://github.com/OpenSourcePolitics/decidim-module-friendly_signup.git
revision: 1a054faf964cc6ed07f1bec47cb92f0083a5bcb4
Expand Down Expand Up @@ -74,16 +84,6 @@ GIT
omniauth (~> 2.0)
omniauth-oauth2 (>= 1.7.2, < 2.0)

GIT
remote: https://github.com/PopulateTools/decidim-module-extra_user_fields.git
revision: ef262d6619ef254de1379278f56c4c6af789e54c
branch: release/0.27-stable
specs:
decidim-extra_user_fields (0.27.2)
country_select (~> 4.0)
decidim-core (>= 0.27.0, < 0.28)
deface (~> 1.5)

GIT
remote: https://github.com/alecslupu-pfa/decidim-module-survey_multiple_answers
revision: 65ea83227f99d0f3d6237f98334ecc914a2a5597
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/friendly_signup.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

return unless defined?(Decidim::FriendlySignup)

Decidim::FriendlySignup.configure do |config|
# Override password views or leave the originals (default is true):
config.override_passwords = ENV.fetch("FRIENDLY_SIGNUP_OVERRIDE_PASSWORDS", "1") == "1"
Expand Down
200 changes: 102 additions & 98 deletions spec/commands/decidim/create_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,120 +3,124 @@
require "spec_helper"

module Decidim
module Comments
describe CreateRegistration do
describe "call" do
let(:organization) { create(:organization) }

let(:name) { "Username" }
let(:nickname) { "nickname" }
let(:email) { "[email protected]" }
let(:password) { "Y1fERVzL2F" }
let(:password_confirmation) { password }
let(:tos_agreement) { "1" }
let(:newsletter) { "1" }
let(:current_locale) { "fr" }

let(:form_params) do
{
"user" => {
"name" => name,
"nickname" => nickname,
"email" => email,
"password" => password,
"password_confirmation" => password_confirmation,
"tos_agreement" => tos_agreement,
"newsletter_at" => newsletter
}
describe CreateRegistration do
describe "call" do
let(:organization) { create(:organization) }

let(:name) { "Username" }
let(:nickname) { "nickname" }
let(:email) { "[email protected]" }
let(:password) { "Y1fERVzL2F" }
let(:password_confirmation) { password }
let(:tos_agreement) { "1" }
let(:newsletter) { "1" }
let(:current_locale) { "fr" }
let(:notifications_sending_frequency) { "none" }

let(:form_params) do
{
"user" => {
"name" => name,
"nickname" => nickname,
"email" => email,
"password" => password,
"password_confirmation" => password_confirmation,
"tos_agreement" => tos_agreement,
"newsletter_at" => newsletter
}
}
end
let(:form) do
RegistrationForm.from_params(
form_params,
current_locale: current_locale
).with_context(
current_organization: organization
)
end
let(:command) { described_class.new(form) }

describe "when the form is not valid" do
before do
allow(form).to receive(:invalid?).and_return(true)
end
let(:form) do
RegistrationForm.from_params(
form_params,
current_locale: current_locale
).with_context(
current_organization: organization
)

it "broadcasts invalid" do
expect { command.call }.to broadcast(:invalid)
end
let(:command) { described_class.new(form) }

describe "when the form is not valid" do
before do
allow(form).to receive(:invalid?).and_return(true)
end
it "doesn't create a user" do
expect do
command.call
end.not_to change(User, :count)
end

context "when the user was already invited" do
let(:user) { build(:user, email: email, organization: organization) }

it "broadcasts invalid" do
expect { command.call }.to broadcast(:invalid)
before do
user.invite!
clear_enqueued_jobs
end

it "doesn't create a user" do
# rubocop:disable RSpec/ChangeByZero
it "receives the invitation email again" do
expect do
command.call
end.not_to change(User, :count)
user.reload
end.to change(User, :count).by(0)
.and broadcast(:invalid)
.and change(user.reload, :invitation_token)
expect(ActionMailer::MailDeliveryJob).to have_been_enqueued.on_queue("mailers")
end
# rubocop:enable RSpec/ChangeByZero
end
end

context "when the user was already invited" do
let(:user) { build(:user, email: email, organization: organization) }

before do
user.invite!
clear_enqueued_jobs
end

# rubocop:disable RSpec/ChangeByZero
it "receives the invitation email again" do
expect do
command.call
user.reload
end.to change(User, :count).by(0)
.and broadcast(:invalid)
.and change(user.reload, :invitation_token)
expect(ActionMailer::MailDeliveryJob).to have_been_enqueued.on_queue("mailers")
end
# rubocop:enable RSpec/ChangeByZero
end
describe "when the form is valid" do
before do
Decidim::ExtraUserFields.notifications_sending_frequency = "none"
end

describe "when the form is valid" do
it "broadcasts ok" do
expect { command.call }.to broadcast(:ok)
end
it "broadcasts ok" do
expect { command.call }.to broadcast(:ok)
end

it "creates a new user" do
expect(User).to receive(:create!).with(
name: form.name,
nickname: form.nickname,
email: form.email,
password: form.password,
password_confirmation: form.password_confirmation,
tos_agreement: form.tos_agreement,
newsletter_notifications_at: form.newsletter_at,
organization: organization,
accepted_tos_version: organization.tos_version,
locale: form.current_locale,
password_updated_at: an_instance_of(ActiveSupport::TimeWithZone),
extended_data: {
country: nil,
date_of_birth: nil,
gender: nil,
location: nil,
phone_number: nil,
postal_code: nil
}
).and_call_original

expect { command.call }.to change(User, :count).by(1)
end
it "creates a new user" do
expect(User).to receive(:create!).with(
name: form.name,
nickname: form.nickname,
email: form.email,
password: form.password,
password_confirmation: form.password_confirmation,
tos_agreement: form.tos_agreement,
newsletter_notifications_at: form.newsletter_at,
organization: organization,
accepted_tos_version: organization.tos_version,
locale: form.current_locale,
password_updated_at: an_instance_of(ActiveSupport::TimeWithZone),
notifications_sending_frequency: "none",
extended_data: {
country: nil,
date_of_birth: nil,
gender: nil,
location: nil,
phone_number: nil,
postal_code: nil
}
).and_call_original

expect { command.call }.to change(User, :count).by(1)
end

describe "when user keeps the newsletter unchecked" do
let(:newsletter) { "0" }
describe "when user keeps the newsletter unchecked" do
let(:newsletter) { "0" }

it "creates a user with no newsletter notifications" do
expect do
command.call
expect(User.last.newsletter_notifications_at).to be_nil
end.to change(User, :count).by(1)
end
it "creates a user with no newsletter notifications" do
expect do
command.call
expect(User.last.newsletter_notifications_at).to be_nil
end.to change(User, :count).by(1)
end
end
end
Expand Down