-
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.
[Bugfix] Fusion usager qui plante quand on choisit un usager sans ann…
…otation (#5143) Bugfix: fusion usager qui plante quand on choisit un usager sans annotation
- Loading branch information
1 parent
2e55aab
commit 5d228f6
Showing
2 changed files
with
46 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
# defaults | ||
let!(:organisation) { create(:organisation) } | ||
let(:attributes_to_merge) { [] } | ||
let(:user_target) { create(:user, organisations: [organisation]) } | ||
let(:user_to_merge) { create(:user, organisations: [organisation]) } | ||
let!(:user_target) { create(:user, organisations: [organisation]) } | ||
let!(:user_to_merge) { create(:user, organisations: [organisation]) } | ||
|
||
context "simply merge first_name" do | ||
let(:user_target) { create(:user, first_name: "Jean", last_name: "PAUL", email: "[email protected]", organisations: [organisation]) } | ||
|
@@ -179,8 +179,8 @@ | |
let!(:organisation2) { create(:organisation) } | ||
let!(:agent1) { create(:agent, basic_role_in_organisations: [organisation]) } | ||
let!(:agent2) { create(:agent, basic_role_in_organisations: [organisation2]) } | ||
let(:user_target) { create(:user, referent_agents: [agent1], organisations: [organisation]) } | ||
let(:user_to_merge) { create(:user, referent_agents: [agent2], organisations: [organisation, organisation2]) } | ||
let!(:user_target) { create(:user, referent_agents: [agent1], organisations: [organisation]) } | ||
let!(:user_to_merge) { create(:user, referent_agents: [agent2], organisations: [organisation, organisation2]) } | ||
|
||
it "does not move the agent from the other orga anything" do | ||
perform | ||
|
@@ -249,6 +249,46 @@ | |
end | ||
end | ||
|
||
context "only user to merge has an annotation" do | ||
before do | ||
user_to_merge.annotations.create!(territory: organisation.territory, content: "user to merge") | ||
end | ||
|
||
it "deletes the annotation along with the merged user by default" do | ||
expect { perform }.to change(Annotation, :count).by(-1).and(change(User, :count).by(-1)) | ||
expect(user_target.annotations.find_by(territory: organisation.territory)).to be_nil | ||
end | ||
|
||
context "when merging annotations" do | ||
let(:attributes_to_merge) { [:annotation_content] } | ||
|
||
it "moves the annotation to the target user" do | ||
perform | ||
expect(user_target.annotation_for(organisation.territory)).to eq("user to merge") | ||
end | ||
end | ||
end | ||
|
||
context "only target user has an annotation" do | ||
before do | ||
user_target.annotations.create!(territory: organisation.territory, content: "target user") | ||
end | ||
|
||
it "keeps the annotation by default" do | ||
expect { perform }.not_to change(Annotation, :count) | ||
expect(user_target.annotation_for(organisation.territory)).to eq("target user") | ||
end | ||
|
||
context "when merging annotations" do | ||
let(:attributes_to_merge) { [:annotation_content] } | ||
|
||
it "deletes the annotation of the target user, to replace it with with the absence of annotation of the user to merge" do | ||
expect { perform }.to change(Annotation, :count).by(-1) | ||
expect(user_target.annotations.find_by(territory: organisation.territory)).to be_nil | ||
end | ||
end | ||
end | ||
|
||
context "when one user is connected by FranceConnect" do | ||
it "keep FranceConnect attributes when merged user logged once with franceconnect" do | ||
user_to_merge = create(:user, logged_once_with_franceconnect: true, franceconnect_openid_sub: "unechainedecharacteres", organisations: [organisation]) | ||
|