forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix validation errors on impersonations or transferring users (decidi…
- Loading branch information
1 parent
075ea75
commit 9278ee0
Showing
9 changed files
with
194 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ module Admin | |
let(:organization) { create(:organization) } | ||
let(:current_user) { create(:user, :admin, organization:) } | ||
let(:new_user) { create(:user, organization:) } | ||
let(:other_user) { create(:user, organization:) } | ||
let(:managed_user) { create(:user, managed: true, organization:) } | ||
let(:email) { new_user.email } | ||
|
||
let(:conflict) do | ||
Decidim::Verifications::Conflict.create(current_user: new_user, managed_user:) | ||
|
@@ -25,14 +27,39 @@ module Admin | |
let(:attributes) do | ||
{ | ||
current_user:, | ||
conflict: | ||
conflict:, | ||
email: | ||
} | ||
end | ||
|
||
context "when form is valid" do | ||
it { is_expected.to be_valid } | ||
end | ||
|
||
context "when the email is the used by the managed_user" do | ||
let(:email) { managed_user.email } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
|
||
context "when email is blank" do | ||
let(:email) { nil } | ||
|
||
it { is_expected.to be_invalid } | ||
end | ||
|
||
context "when email belongs to an existing user different of the emails of the conflicting users" do | ||
let(:email) { other_user.email } | ||
|
||
it { is_expected.to be_invalid } | ||
end | ||
|
||
context "when email does not belong to an existing user" do | ||
let(:email) { "[email protected]" } | ||
|
||
it { is_expected.to be_valid } | ||
end | ||
|
||
context "when no current_user is passed" do | ||
let(:current_user) { nil } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe "Admin manages conflicts" do | ||
let(:organization) { create(:organization) } | ||
|
||
let!(:user) { create(:user, :admin, :confirmed, organization:) } | ||
let!(:other_user) { create(:user, :admin, :confirmed, organization:, email: "[email protected]") } | ||
|
||
let!(:conflictive_user) { create(:user, :admin, :confirmed, organization:, email: "[email protected]") } | ||
let!(:managed_user) { create(:user, managed: true, organization:, email: "[email protected]") } | ||
|
||
let!(:conflict) { create(:conflict, current_user: conflictive_user, managed_user:) } | ||
|
||
before do | ||
switch_to_host(organization.host) | ||
login_as user, scope: :user | ||
visit decidim_admin.root_path | ||
click_on "Participants" | ||
click_on "Verification conflicts" | ||
click_on "Transfer" | ||
end | ||
|
||
context "when resolving a conflict" do | ||
context "when no mail is passed" do | ||
before do | ||
click_on "Transfer" | ||
end | ||
|
||
it "the transfer cannot be sent" do | ||
expect(page).to have_content("There is an error") | ||
end | ||
end | ||
|
||
context "when a mail is passed" do | ||
let(:email) { "[email protected]" } | ||
|
||
before do | ||
fill_in "Email", with: email | ||
click_on "Transfer" | ||
end | ||
|
||
context "when the email is not in use by any other user" do | ||
it "the transfer is successful" do | ||
expect(page).to have_content("The current transfer has been successfully completed.") | ||
end | ||
|
||
it "the email of the managed user is replaced with the email passed by the form" do | ||
expect(managed_user.reload.email).to eq("[email protected]") | ||
end | ||
end | ||
|
||
context "when the email is the email of the conflictive user" do | ||
let(:email) { "[email protected]" } | ||
|
||
it "the transfer is successful" do | ||
expect(page).to have_content("The current transfer has been successfully completed.") | ||
end | ||
|
||
it "the email of the managed user is replaced with the email of the conflictive one" do | ||
expect(managed_user.reload.email).to eq("[email protected]") | ||
end | ||
end | ||
|
||
context "when the email is the email of the managed user" do | ||
let(:email) { "[email protected]" } | ||
|
||
it "the transfer is successful" do | ||
expect(page).to have_content("The current transfer has been successfully completed.") | ||
end | ||
|
||
it "the managed user keeps its email" do | ||
expect(managed_user.reload.email).to eq("[email protected]") | ||
end | ||
end | ||
|
||
context "when the email is the email of an already existing user" do | ||
let(:email) { "[email protected]" } | ||
|
||
it "the transfer fails" do | ||
expect(page).to have_no_content("The current transfer has been successfully completed.") | ||
expect(page).to have_content("There was a problem transferring the current participant to managed participant") | ||
end | ||
end | ||
end | ||
end | ||
end |