Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/production' into frf/bring-back-…
Browse files Browse the repository at this point in the history
…flaky-specs
  • Loading branch information
francois-ferrandis committed Mar 4, 2025
2 parents 02dfd82 + 195b430 commit 704b96f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ jobs:
path: node_modules
- name: Install JS dependencies
run: yarn install
- name: Cache precompiled assets
id: cache-precompiled-assets
uses: actions/cache@v4
with:
key: assets-${{ hashFiles('yarn.lock', 'app/javascript/**') }}
path: app/assets/builds
- name: Precompile assets
if: steps.cache-precompiled-assets.outputs.cache-hit != 'true' # Skip if cache was restored
run: yarn run build
- name: Prepare runtime log cache key
run: ls spec/**/*.rb > tmp/spec_files.txt
Expand Down Expand Up @@ -202,7 +209,14 @@ jobs:
path: node_modules
- name: Install JS dependencies
run: yarn install
- name: Cache precompiled assets
id: cache-precompiled-assets
uses: actions/cache@v4
with:
key: assets-${{ hashFiles('yarn.lock', 'app/javascript/**') }}
path: app/assets/builds
- name: Precompile assets
if: steps.cache-precompiled-assets.outputs.cache-hit != 'true' # Skip if cache was restored
run: yarn run build
- name: Prepare runtime log cache key
run: "ls spec/features/${{ matrix.dirname }}/**/*.rb > tmp/feature_spec_${{ matrix.dirname }}_files.txt"
Expand Down
3 changes: 3 additions & 0 deletions app/jobs/create_crisp_ticket_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def perform(nickname:, email:, phone:, subject:, message:, role:, domain:)
domain,
],
subject:,
device: {
locales: ["fr"],
},
}
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/merge_users_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def merge_annotations
current_territory = @organisation.territory

annotation_to_merge = @user_to_merge.annotations.find_by(territory: current_territory)
@user_target.annotate!(annotation_to_merge.content, territory: current_territory)
annotation_to_merge.destroy!
@user_target.annotate!(annotation_to_merge&.content, territory: current_territory)
annotation_to_merge&.destroy!
end

def merge_user_attributes
Expand Down
1 change: 0 additions & 1 deletion config/anonymizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ tables:
- city_name
- case_number
- logement
- notes
- ants_pre_demande_number
- franceconnect_openid_sub
- encrypted_password
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20250303104258_remove_users_notes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RemoveUsersNotes < ActiveRecord::Migration[7.1]
def change
safety_assured do
remove_column :users, :notes, :text
end
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2025_02_27_165927) do
ActiveRecord::Schema[7.1].define(version: 2025_03_03_104258) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "pgcrypto"
Expand Down Expand Up @@ -795,7 +795,6 @@
t.string "case_number"
t.string "address_details"
t.integer "logement"
t.text "notes"
t.string "ants_pre_demande_number"
t.string "rdv_invitation_token"
t.virtual "text_search_terms", type: :tsvector, as: "(((((setweight(to_tsvector('simple'::regconfig, translate(lower((COALESCE(last_name, ''::character varying))::text), 'àâäéèêëïîôöùûüÿç'::text, 'aaaeeeeiioouuuyc'::text)), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, translate(lower((COALESCE(first_name, ''::character varying))::text), 'àâäéèêëïîôöùûüÿç'::text, 'aaaeeeeiioouuuyc'::text)), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, translate(lower((COALESCE(birth_name, ''::character varying))::text), 'àâäéèêëïîôöùûüÿç'::text, 'aaaeeeeiioouuuyc'::text)), 'C'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(email, ''::character varying))::text), 'D'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(phone_number_formatted, ''::character varying))::text), 'D'::\"char\")) || setweight(to_tsvector('simple'::regconfig, COALESCE((id)::text, ''::text)), 'D'::\"char\"))", stored: true
Expand Down
48 changes: 44 additions & 4 deletions spec/services/merge_users_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]) }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 704b96f

Please sign in to comment.