diff --git a/app/models/concerns/rdv/address_concern.rb b/app/models/concerns/rdv/address_concern.rb index 2a39d9faa7..d1965e820c 100644 --- a/app/models/concerns/rdv/address_concern.rb +++ b/app/models/concerns/rdv/address_concern.rb @@ -53,4 +53,9 @@ def address_without_personal_information Motif.human_attribute_value(:location_type, :phone) end end + + def user_for_home_rdv + proches, responsables = users.partition(&:responsible_id) + (responsables + proches).select(&:address).first || users.first + end end diff --git a/app/models/rdv.rb b/app/models/rdv.rb index f22203dea5..1e52d59338 100644 --- a/app/models/rdv.rb +++ b/app/models/rdv.rb @@ -211,11 +211,6 @@ def creneaux_available(date_range) CreneauxSearch::Calculator.available_slots(motif, lieu, date_range) end - def user_for_home_rdv - responsibles = users.loaded? ? users.select(&:responsible_id) : users.where.not(responsible_id: [nil]) - [responsibles, users].flatten.select(&:address).first || users.first - end - # Ces plages d'ouvertures sont utilisé pour afficher des infos # s'il y a un chevauchement avec le RDV. # diff --git a/spec/blueprint/rdv_blueprint_spec.rb b/spec/blueprint/rdv_blueprint_spec.rb index 6ed6121cee..7543486868 100644 --- a/spec/blueprint/rdv_blueprint_spec.rb +++ b/spec/blueprint/rdv_blueprint_spec.rb @@ -19,7 +19,7 @@ "collectif" => false, "context" => nil, "created_by" => "agent", - "duration_in_min" => 45, + "duration_in_min" => rdv.duration_in_min.to_i, "max_participants_count" => nil, "name" => nil, }) diff --git a/spec/controllers/admin/agenda/plage_ouvertures_controller_spec.rb b/spec/controllers/admin/agenda/plage_ouvertures_controller_spec.rb index cc5ebf50db..9872313634 100644 --- a/spec/controllers/admin/agenda/plage_ouvertures_controller_spec.rb +++ b/spec/controllers/admin/agenda/plage_ouvertures_controller_spec.rb @@ -57,7 +57,7 @@ "url" => "/admin/organisations/#{organisation.id}/plage_ouvertures/#{plage_ouverture.id}", "extendedProps" => { "organisationName" => organisation.name, - "location" => "1 rue de l'adresse, Ville, 12345", + "location" => plage_ouverture.lieu.address, "lieu" => plage_ouverture.lieu.name, }, }, diff --git a/spec/factories/absence.rb b/spec/factories/absence.rb index 67b7429569..f4ddecbaed 100644 --- a/spec/factories/absence.rb +++ b/spec/factories/absence.rb @@ -5,7 +5,7 @@ agent { association(:agent) } title { generate(:absence_title) } - first_day { Time.zone.tomorrow } + first_day { Faker::Date.forward(days: 7) } start_time { Tod::TimeOfDay.new(10) } end_time { Tod::TimeOfDay.new(15, 30) } no_recurrence diff --git a/spec/factories/agent.rb b/spec/factories/agent.rb index c9917a1967..eeb6583974 100644 --- a/spec/factories/agent.rb +++ b/spec/factories/agent.rb @@ -1,14 +1,12 @@ FactoryBot.define do - sequence(:agent_email) { |n| "agent_#{n}@lapin.fr" } - factory :agent do - email { generate(:agent_email) } + sequence(:email) { |n| Faker::Internet.email(name: "last_name #{n}", domain: "agent.gouv.fr") } uid { email } first_name { Faker::Name.first_name } last_name { Faker::Name.last_name } - password { "Correcth0rse!" } - confirmed_at { Time.zone.parse("2020-07-30 10:30").in_time_zone } - invitation_accepted_at { Time.zone.parse("2020-07-30 10:30").in_time_zone } + password { generate(:valid_password) } + confirmed_at { 2.days.ago } + invitation_accepted_at { 2.days.ago } transient do service { build(:service) } diff --git a/spec/factories/generators.rb b/spec/factories/generators.rb new file mode 100644 index 0000000000..b049cdd051 --- /dev/null +++ b/spec/factories/generators.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + sequence(:valid_password) do + "Aa1_#{Faker::Internet.password(min_length: 12, mix_case: true, special_characters: true)}" + end +end diff --git a/spec/factories/lieu.rb b/spec/factories/lieu.rb index b20dbdc0aa..6dbec0f7dd 100644 --- a/spec/factories/lieu.rb +++ b/spec/factories/lieu.rb @@ -1,12 +1,9 @@ FactoryBot.define do - sequence(:lieu_name) { |n| "Lieu n°#{n}" } - sequence(:address) { |n| "#{n} rue de l'adresse, Ville, 12345" } - factory :lieu do organisation - name { generate(:lieu_name) } - address { generate(:address) } + name { Faker::Address.community } + address { Faker::Address.full_address } latitude { 38.8951 } longitude { -77.0364 } availability { :enabled } diff --git a/spec/factories/motif.rb b/spec/factories/motif.rb index 267a30d329..f0598b40b9 100644 --- a/spec/factories/motif.rb +++ b/spec/factories/motif.rb @@ -7,10 +7,10 @@ motif_category { association(:motif_category) } name { generate(:motif_name) } - default_duration_in_min { 45 } - min_public_booking_delay { 30.minutes.seconds } - max_public_booking_delay { 6.months.seconds } - sequence(:color) { |n| ["#bff3c8", "#336650", "#0066ee", "#3300ee"][n % 4] } + default_duration_in_min { random_value_in([15, 30, 45, 60, 90]) } + min_public_booking_delay { random_value_in([30.minutes, 4.hours, 2.days]) } + max_public_booking_delay { random_value_in([3.days, 3.weeks, 6.months]) } + color { random_value_in(["#bff3c8", "#336650", "#0066ee", "#3300ee"]) } bookable_by { :everyone } location_type { :public_office } visibility_type { Motif::VISIBLE_AND_NOTIFIED } diff --git a/spec/factories/organisation.rb b/spec/factories/organisation.rb index ae7e6282eb..fe0a96c72e 100644 --- a/spec/factories/organisation.rb +++ b/spec/factories/organisation.rb @@ -1,13 +1,10 @@ FactoryBot.define do - sequence(:orga_name) { |n| "Organisation n°#{n}" } - sequence(:orga_email) { |n| "contact#{n}@organisation.fr" } - factory :organisation do - name { generate(:orga_name) } + name { Faker::Company.industry } territory trait :with_contact do - email { generate(:orga_email) } + email { Faker::Internet.email(name: name, domain: "orga.fr") } phone_number { Faker::PhoneNumber.phone_number } website { Faker::Internet.url } end diff --git a/spec/factories/prescripteur.rb b/spec/factories/prescripteur.rb index dd8f562734..d69b43f9ed 100644 --- a/spec/factories/prescripteur.rb +++ b/spec/factories/prescripteur.rb @@ -2,7 +2,7 @@ factory :prescripteur do first_name { Faker::Name.first_name } last_name { Faker::Name.last_name.upcase } - email { Faker::Internet.email } - sequence(:phone_number) { |n| "060000#{n.to_s.rjust(4, '0')}" } + email { Faker::Internet.email(name: last_name, domain: "prescripteur.fr") } + phone_number { Faker::PhoneNumber.cell_phone } end end diff --git a/spec/factories/rdv.rb b/spec/factories/rdv.rb index c933793f43..e2d670c542 100644 --- a/spec/factories/rdv.rb +++ b/spec/factories/rdv.rb @@ -5,8 +5,8 @@ motif { build(:motif, organisation: organisation) } agents { [build(:agent, organisations: [organisation])] } - duration_in_min { 45 } - starts_at { 3.days.from_now } + duration_in_min { motif&.default_duration_in_min || random_value_in([15, 30, 45, 60, 90]) } + starts_at { Faker::Time.forward(days: 7) } status { "unknown" } @@ -21,23 +21,23 @@ lieu { nil } end trait :past do - starts_at { 1.day.ago.at_noon } + starts_at { Faker::Time.backward(days: 30) } end trait :future do - starts_at { 2.days.from_now.at_noon } + starts_at { Faker::Time.forward(days: 7) } end trait :at_home do motif { build(:motif, :at_home, organisation: organisation) } lieu { nil } end trait :excused do - cancelled_at { Time.zone.parse("2020-01-15 10:30").in_time_zone } + cancelled_at { 2.days.ago } status { "excused" } end trait(:with_fake_timestamps) do - created_at { Time.zone.parse("2020-06-05 13:51") } - updated_at { Time.zone.parse("2020-06-05 13:51") } + created_at { 2.days.ago } + updated_at { created_at } end # by default, attach a new user when building a RDV diff --git a/spec/factories/receipt.rb b/spec/factories/receipt.rb index 6c8c7a8c4f..d9572e82d4 100644 --- a/spec/factories/receipt.rb +++ b/spec/factories/receipt.rb @@ -6,7 +6,7 @@ channel { :sms } result { :processed } sms_count { 2 } - sms_phone_number { "0600001111" } + sms_phone_number { Faker::PhoneNumber.cell_phone } content { "Atelier collectif, mardi 20/02 à 16h00. Mairie de Romainville (7 Rue de Paris, Romainville, 93230). Infos et annulation: https://demo.rdv-solidarites.fr/r/asdfasd/ / 0100001111" } created_at { Time.zone.now } updated_at { Time.zone.now } @@ -16,7 +16,7 @@ channel { :mail } sms_count { nil } sms_phone_number { nil } - email_address { "francis@factice.org" } + email_address { user.email || Faker::Internet.email } end end end diff --git a/spec/factories/super_admin.rb b/spec/factories/super_admin.rb index 369f6343d0..4d108ac7bb 100644 --- a/spec/factories/super_admin.rb +++ b/spec/factories/super_admin.rb @@ -1,8 +1,6 @@ FactoryBot.define do - sequence(:super_admin_email) { |n| "super_admin_#{n}@lapin.fr" } - factory :super_admin do - email { generate(:super_admin_email) } + email { Faker::Internet.email(domain: "super-admin.fr") } role { :legacy_admin } first_name { Faker::Name.first_name } last_name { Faker::Name.last_name } diff --git a/spec/factories/team.rb b/spec/factories/team.rb index bb58d7e794..58625b7d0a 100644 --- a/spec/factories/team.rb +++ b/spec/factories/team.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :team do - territory { association(:territory) } + territory name { "#{Faker::Team.name} #{SecureRandom.hex(4)}" } end end diff --git a/spec/factories/territory.rb b/spec/factories/territory.rb index 9e876f0936..cb513b6185 100644 --- a/spec/factories/territory.rb +++ b/spec/factories/territory.rb @@ -1,10 +1,7 @@ FactoryBot.define do - sequence(:territory_name) { |n| "Territoire n°#{n}" } - sequence(:departement_number) - factory :territory do - name { generate(:territory_name) } - departement_number { generate(:departement_number).to_s.rjust(2, "0") } + name { Territory::DEPARTEMENTS_NAMES.fetch(departement_number) } + departement_number { random_value_in(Territory::DEPARTEMENTS_NAMES.keys) } sms_provider { "netsize" } sms_configuration { "a_key" } end @@ -17,6 +14,7 @@ end trait :conseillers_numeriques do + name { SecureRandom.uuid } departement_number { Territory::CN_DEPARTEMENT_NUMBER } after(:create) do |territory, _| # Les contraintes de validations sur les noms spéciaux obligent à faire un update_columns ici diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 484089eab2..64e3ba91a3 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -1,10 +1,6 @@ FactoryBot.define do - require "faker" - - sequence(:user_email) { |n| "usager_#{n}@lapin.fr" } - factory :user do - email { generate(:user_email) } + email { Faker::Internet.email } first_name { Faker::Name.first_name } last_name { Faker::Name.last_name.upcase } phone_number do @@ -12,16 +8,16 @@ num = Faker::PhoneNumber.cell_phone until Phonelib.parse(num, "FR").valid? num end - birth_date { Date.parse("1985-07-20") } - address { "20 avenue de Ségur, Paris, 75012" } - password { "coRrect!h0rse" } - password_confirmation { "coRrect!h0rse" } + birth_date { Faker::Date.birthday(min_age: 1, max_age: 120) } + address { Faker::Address.full_address } + password { generate(:valid_password) } + password_confirmation { password } confirmed_at { Time.zone.now } caisse_affiliation { "caf" } affiliation_number { "39012093812038" } family_situation { "divorced" } - number_of_children { 12 } - notes { "Super note" } + number_of_children { random_value_in([nil, 0, 1, 2, 3, 8, 800]) } + notes { Faker::Movies::PrincessBride.quote } logement { :locataire } responsible { nil } created_through { "user_sign_up" } diff --git a/spec/features/agents/agent_can_crud_intervenants_spec.rb b/spec/features/agents/agent_can_crud_intervenants_spec.rb index 606b3617d4..129f20806e 100644 --- a/spec/features/agents/agent_can_crud_intervenants_spec.rb +++ b/spec/features/agents/agent_can_crud_intervenants_spec.rb @@ -9,7 +9,7 @@ specify "full intervenant lifecycle", js: true do visit admin_organisation_agents_path(organisation) - expect_page_title("Agents de Organisation n°1") + expect_page_title("Agents de #{organisation.name}") # Create an intervenant click_link "Ajouter un agent", match: :first @@ -18,7 +18,7 @@ find("label", text: "Intervenant").click fill_in "Nom", with: "Avocat 1" click_button("Enregistrer") - expect_page_title("Agents de Organisation n°1") + expect_page_title("Agents de #{organisation.name}") expect(page).to have_content("AVOCAT 1") expect(Agent.last).to have_attributes( plage_ouverture_notification_level: "none", @@ -31,7 +31,7 @@ expect_page_title("Modifier le niveau de permission de l'agent INTERVENANT1") fill_in "Nom", with: "Nouveau nom" click_button("Modifier le nom") - expect_page_title("Agents de Organisation n°1") + expect_page_title("Agents de #{organisation.name}") expect(page).to have_content("AVOCAT 1") # Change the intervenant into an admin agent @@ -60,7 +60,7 @@ absence_notification_level: "all" ) - expect_page_title("Invitations en cours pour Organisation n°1") + expect_page_title("Invitations en cours pour #{organisation.name}") expect(page).to have_content("ancien_intervenant1@invitation.com") expect(page).to have_content("FICTIF Bob") @@ -80,7 +80,7 @@ click_button("Enregistrer") end - expect_page_title("Agents de Organisation n°1") + expect_page_title("Agents de #{organisation.name}") expect(Agent.last.roles.pluck(:access_level)).to eq ["intervenant"] expect(Agent.last).to have_attributes( @@ -111,7 +111,7 @@ accept_alert do click_link("Supprimer le compte") end - expect_page_title("Agents de Organisation n°1") + expect_page_title("Agents de #{organisation.name}") expect(page).to have_no_content("FICTIF") end diff --git a/spec/features/agents/agent_can_crud_motifs_spec.rb b/spec/features/agents/agent_can_crud_motifs_spec.rb index d24dfa122d..0c4d19a451 100644 --- a/spec/features/agents/agent_can_crud_motifs_spec.rb +++ b/spec/features/agents/agent_can_crud_motifs_spec.rb @@ -65,7 +65,9 @@ visit edit_admin_organisation_motif_path(organisation_id: organisation.id, id: motif.id) find("#tab_resa_en_ligne").click check "Autoriser les agents du service Secrétariat à assurer ces RDV" - click_on "Enregistrer" and motif.reload + click_on "Enregistrer" + expect(page).to have_current_path(admin_organisation_motif_path(motif.organisation, motif)) # wait for show page + motif.reload expect(motif.for_secretariat).to be_truthy expect(motif.follow_up).to be_falsey @@ -73,7 +75,9 @@ find("#tab_resa_en_ligne").click check "Autoriser ces rendez-vous seulement aux usagers bénéficiant d'un suivi par un référent" expect(find("#motif_for_secretariat", visible: false)).not_to be_checked - click_on "Enregistrer" and motif.reload + click_on "Enregistrer" + expect(page).to have_current_path(admin_organisation_motif_path(motif.organisation, motif)) # wait for show page + motif.reload expect(motif.for_secretariat).to be_falsey expect(motif.follow_up).to be_truthy end diff --git a/spec/features/agents/agent_can_prescribe_rdvs_spec.rb b/spec/features/agents/agent_can_prescribe_rdvs_spec.rb index 180e205833..17c1264a67 100644 --- a/spec/features/agents/agent_can_prescribe_rdvs_spec.rb +++ b/spec/features/agents/agent_can_prescribe_rdvs_spec.rb @@ -25,8 +25,8 @@ let!(:motif_autre_service) { create(:motif, organisation: org_insertion, service: service_autre) } let!(:mds_paris_nord) { create(:lieu, organisation: org_mds) } - let!(:mission_locale_paris_nord) { create(:lieu, organisation: org_insertion) } - let!(:mission_locale_paris_sud) { create(:lieu, organisation: org_insertion) } + let!(:mission_locale_paris_nord) { create(:lieu, name: "ML Paris Nord", organisation: org_insertion) } + let!(:mission_locale_paris_sud) { create(:lieu, name: "ML Paris Sud", organisation: org_insertion) } before do next_month = (now + 1.month).to_date diff --git a/spec/features/agents/agents/crud_on_agents_spec.rb b/spec/features/agents/agents/crud_on_agents_spec.rb index 96e7c35fc5..062bbcb8cd 100644 --- a/spec/features/agents/agents/crud_on_agents_spec.rb +++ b/spec/features/agents/agents/crud_on_agents_spec.rb @@ -74,20 +74,20 @@ create(:agent, first_name: "Tony", last_name: "Patrick", email: "tony@patrick.fr", service: pmi, basic_role_in_organisations: [organisation1], invitation_accepted_at: nil) click_link "Agents" - expect_page_title("Agents de Organisation n°1") + expect_page_title("Agents de #{organisation1.name}") click_link "PATRICK Tony" expect_page_title("Modifier le niveau de permission de l'agent Tony PATRICK") choose "Administrateur" click_button("Enregistrer") - expect_page_title("Agents de Organisation n°1") + expect_page_title("Agents de #{organisation1.name}") expect(page).to have_content("Administrateur", count: 2) click_link "PATRICK Tony" click_link("Supprimer le compte") - expect_page_title("Agents de Organisation n°1") + expect_page_title("Agents de #{organisation1.name}") expect(page).to have_no_content("Tony PATRICK") click_link "Ajouter un agent", match: :first @@ -95,7 +95,7 @@ check(pmi.name) click_button "Enregistrer" - expect_page_title("Invitations en cours pour Organisation n°1") + expect_page_title("Invitations en cours pour #{organisation1.name}") expect(page).to have_content("jean@paul.com") click_on "Se déconnecter" diff --git a/spec/features/agents/calendar_export_spec.rb b/spec/features/agents/calendar_export_spec.rb index 966ae9c708..7cfd6fd0b9 100644 --- a/spec/features/agents/calendar_export_spec.rb +++ b/spec/features/agents/calendar_export_spec.rb @@ -35,15 +35,22 @@ end it "displays rdvs in the proper format for calendars, without including personal information" do - travel_to(Time.zone.local(2022, 7, 8)) + travel_to(Time.zone.parse("2022-07-08 16:00")) org = create(:organisation, id: 123_000) agent = create(:agent, calendar_uid: SecureRandom.uuid, first_name: "Marceau", last_name: "COLIN") motif = create(:motif, name: "Accompagnement individuel") - create(:rdv, motif: motif, agents: [agent], status: "unknown", starts_at: 1.day.from_now, uuid: "e0a8dbac-d06c-4d18-98c6-a48f47fddd4c", organisation: org, id: 456_000) - create(:rdv, motif: motif, agents: [agent], status: "revoked", starts_at: 2.days.from_now, uuid: "749336ce-eaca-40a3-8c28-246ed8d18849", organisation: org, id: 789_000) + lieu = create(:lieu, name: "CMS Le Vernay", address: "22 avenue Germain Perréard, 74960 Cran Gevrier") + + create(:rdv, motif: motif, agents: [agent], status: "unknown", starts_at: Time.zone.parse("2022-07-09 16:00"), ends_at: Time.zone.parse("2022-07-09 16:45"), + uuid: "e0a8dbac-d06c-4d18-98c6-a48f47fddd4c", organisation: org, id: 456_000, lieu: lieu) + + create(:rdv, motif: motif, agents: [agent], status: "revoked", starts_at: Time.zone.parse("2022-07-10 16:00"), ends_at: Time.zone.parse("2022-07-10 16:45"), + uuid: "749336ce-eaca-40a3-8c28-246ed8d18849", organisation: org, id: 789_000, lieu: lieu) + motif_collectif = create(:motif, :collectif, name: "Atelier collectif", organisation: org) - create(:rdv, motif: motif_collectif, agents: [agent], status: "unknown", starts_at: 3.days.from_now, uuid: "abb701a5-381a-4fae-9157-129b5843834c", organisation: org, id: 123_123, - max_participants_count: 5) + create(:rdv, motif: motif_collectif, agents: [agent], status: "unknown", + starts_at: Time.zone.parse("2022-07-11 16:00"), ends_at: Time.zone.parse("2022-07-11 16:45"), + uuid: "abb701a5-381a-4fae-9157-129b5843834c", max_participants_count: 5, organisation: org, id: 123_123, lieu: lieu) visit ics_calendar_path(agent.calendar_uid, format: :ics) diff --git a/spec/features/agents/track_broken_links_spec.rb b/spec/features/agents/track_broken_links_spec.rb index f3ff145d44..a8d1106ad3 100644 --- a/spec/features/agents/track_broken_links_spec.rb +++ b/spec/features/agents/track_broken_links_spec.rb @@ -23,7 +23,7 @@ expect_any_instance_of(Sentry::Client).to receive(:log_debug).with("Discarded event because before_send returned nil") # rubocop:disable RSpec/AnyInstance visit broken_agenda_path fill_in "Email", with: agent.email - fill_in :password, with: "Correcth0rse!" + fill_in :password, with: agent.password expect { click_on "Se connecter" }.to raise_error(ActiveRecord::RecordNotFound) end end diff --git a/spec/features/agents/users/agent_can_merge_users_spec.rb b/spec/features/agents/users/agent_can_merge_users_spec.rb index d1db8373dd..08cef7b841 100644 --- a/spec/features/agents/users/agent_can_merge_users_spec.rb +++ b/spec/features/agents/users/agent_can_merge_users_spec.rb @@ -10,6 +10,7 @@ last_name: "SWAN", birth_date: nil, phone_number: "01 02 03 04 05", + address: "rue de chez Swan, 87000 Limoges", logement: "locataire" ) end @@ -24,6 +25,7 @@ last_name: "SWAN", birth_date: nil, phone_number: "01 09 09 09 09", + address: "rue de chez Swan, 87000 Limoges", organisations: [organisation], logement: "proprietaire" ) diff --git a/spec/features/users/online_booking/link_to_take_rdv_in_organisation_spec.rb b/spec/features/users/online_booking/link_to_take_rdv_in_organisation_spec.rb index b5cf1f6df1..e0370122fe 100644 --- a/spec/features/users/online_booking/link_to_take_rdv_in_organisation_spec.rb +++ b/spec/features/users/online_booking/link_to_take_rdv_in_organisation_spec.rb @@ -3,7 +3,7 @@ around { |example| perform_enqueued_jobs { example.run } } - let!(:territory) { create(:territory, departement_number: Territory::CN_DEPARTEMENT_NUMBER) } + let!(:territory) { create(:territory, :conseillers_numeriques) } let!(:organisation_a) { create(:organisation, territory: territory, external_id: "123") } let!(:organisation_b) { create(:organisation, territory: territory, external_id: "456") } diff --git a/spec/features/users/online_booking/resin_link_spec.rb b/spec/features/users/online_booking/resin_link_spec.rb index b6b1edd9bf..1c8f05688b 100644 --- a/spec/features/users/online_booking/resin_link_spec.rb +++ b/spec/features/users/online_booking/resin_link_spec.rb @@ -5,7 +5,7 @@ travel_to(Time.zone.parse("2023-01-30 17:00")) end - let!(:cnfs_territory) { create(:territory, departement_number: Territory::CN_DEPARTEMENT_NUMBER) } + let!(:cnfs_territory) { create(:territory, :conseillers_numeriques) } let!(:cnfs_service) { create(:service, :conseiller_numerique) } let!(:orga_cnfs_lyon_a) { create(:organisation, territory: cnfs_territory, external_id: "123") } let!(:orga_cnfs_lyon_b) { create(:organisation, territory: cnfs_territory, external_id: "456") } diff --git a/spec/jobs/cron_job/anonymize_old_receipts_spec.rb b/spec/jobs/cron_job/anonymize_old_receipts_spec.rb index 8d4190c6fb..d0e12784fc 100644 --- a/spec/jobs/cron_job/anonymize_old_receipts_spec.rb +++ b/spec/jobs/cron_job/anonymize_old_receipts_spec.rb @@ -15,7 +15,7 @@ expect(recent_sms_receipt.reload).to have_attributes( content: "Atelier collectif, mardi 20/02 à 16h00. Mairie de Romainville (7 Rue de Paris, Romainville, 93230). Infos et annulation: https://demo.rdv-solidarites.fr/r/asdfasd/ / 0100001111", - sms_phone_number: "0600001111" + sms_phone_number: recent_sms_receipt.sms_phone_number ) old_sms_receipt.reload diff --git a/spec/models/rdv_spec.rb b/spec/models/rdv_spec.rb index 68839b60b2..d9b7e050c9 100644 --- a/spec/models/rdv_spec.rb +++ b/spec/models/rdv_spec.rb @@ -186,17 +186,17 @@ end context "when rdv is at home" do - let(:responsible) { create(:user) } - let(:child) { create(:user, responsible: responsible) } - let(:rdv) { create(:rdv, :at_home, users: [child]) } + let(:responsable) { create(:user, address: "1 rue du Responsable, 74000 Annecy") } + let(:proche) { create(:user, responsible: responsable, address: "33 impasse du Proche, 42300 Roanne") } + let(:rdv) { create(:rdv, :at_home, users: [responsable, proche]) } - it { is_expected.to eq responsible.address } + it { is_expected.to eq responsable.address } end context "when rdv is by phone" do - let(:responsible) { create(:user) } - let(:child) { create(:user, responsible: responsible) } - let(:rdv) { create(:rdv, :by_phone, users: [child]) } + let(:responsable) { create(:user) } + let(:proche) { create(:user, responsible: responsable) } + let(:rdv) { create(:rdv, :by_phone, users: [responsable, proche]) } it { is_expected.to be_blank } end diff --git a/spec/models/stat_spec.rb b/spec/models/stat_spec.rb index 532243b037..70a47cb8c7 100644 --- a/spec/models/stat_spec.rb +++ b/spec/models/stat_spec.rb @@ -70,7 +70,7 @@ home_motif = create(:motif, location_type: :home) create(:rdv, motif: home_motif, created_at: now) stats = described_class.new(rdvs: Rdv.all) - expect(stats.rdvs_group_by_territory_name).to eq({ ["Territoire n°2", "23/01/2022"] => 1 }) + expect(stats.rdvs_group_by_territory_name).to eq({ [home_motif.organisation.territory.name, "23/01/2022"] => 1 }) end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 763acb3759..8a685e810e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -81,7 +81,11 @@ config.before(:suite) do DatabaseCleaner.clean_with(:truncation) + Rack::Attack.enabled = false + + Faker::Config.locale = :fr + Faker::Config.random = Random.new(config.seed) end config.around do |example| diff --git a/spec/requests/api/v1/public_links_request_spec.rb b/spec/requests/api/v1/public_links_request_spec.rb index 45cc8c57fc..28ca7129e4 100644 --- a/spec/requests/api/v1/public_links_request_spec.rb +++ b/spec/requests/api/v1/public_links_request_spec.rb @@ -13,7 +13,7 @@ parameter name: "territory", in: :query, type: :string, description: "Le numéro ou code de département du territoire concerné", example: "26" response 200, "Retourne les liens publics de recherche" do - let!(:terr) { create(:territory, departement_number: Territory::CN_DEPARTEMENT_NUMBER) } + let!(:terr) { create(:territory, :conseillers_numeriques) } let!(:organisation_a) { create(:organisation, verticale: :rdv_aide_numerique, external_id: "ext_id_A", territory: terr) } let!(:organisation_b) { create(:organisation, verticale: :rdv_aide_numerique, external_id: "ext_id_B", territory: terr) } let!(:organisation_c) { create(:organisation, verticale: :rdv_aide_numerique, external_id: "ext_id_C", territory: terr) } diff --git a/spec/services/creneaux_search/for_user_spec.rb b/spec/services/creneaux_search/for_user_spec.rb index 4ffeb48803..d3a68b9ba8 100644 --- a/spec/services/creneaux_search/for_user_spec.rb +++ b/spec/services/creneaux_search/for_user_spec.rb @@ -75,13 +75,13 @@ subject { described_class.new(user: user, motif: motif, lieu: lieu) } let!(:motif) { create(:motif, collectif: true) } - let!(:rdv) { create(:rdv, :future, motif: motif, lieu: lieu, starts_at: 3.days.from_now) } + let!(:rdv) { create(:rdv, motif: motif, lieu: lieu, starts_at: 3.days.from_now) } let!(:passed_rdv) { create(:rdv, motif: motif, lieu: lieu, starts_at: 2.days.ago) } - let!(:rdv_with_user) { create(:rdv, :future, motif: motif, lieu: lieu, users: [user], starts_at: 4.days.from_now) } - let!(:rdv_in_different_lieu) { create(:rdv, :future, motif: motif, lieu: create(:lieu)) } - let!(:rdv_with_no_remaining_seat) { create(:rdv, :future, motif: motif, lieu: lieu, max_participants_count: 1) } - let!(:rdv_after_max_public_booking_delay) { create(:rdv, :future, motif: motif, lieu: lieu, starts_at: motif.end_booking_delay + 1.hour) } - let!(:rdv_before_min_public_booking_delay) { create(:rdv, :future, motif: motif, lieu: lieu, starts_at: motif.start_booking_delay - 1.hour) } + let!(:rdv_with_user) { create(:rdv, motif: motif, lieu: lieu, users: [user], starts_at: 4.days.from_now) } + let!(:rdv_in_different_lieu) { create(:rdv, motif: motif, lieu: create(:lieu), starts_at: 2.days.from_now.at_noon) } + let!(:rdv_with_no_remaining_seat) { create(:rdv, motif: motif, lieu: lieu, max_participants_count: 1, starts_at: 2.days.from_now.at_noon) } + let!(:rdv_after_max_public_booking_delay) { create(:rdv, motif: motif, lieu: lieu, starts_at: motif.end_booking_delay + 1.hour) } + let!(:rdv_before_min_public_booking_delay) { create(:rdv, motif: motif, lieu: lieu, starts_at: motif.start_booking_delay - 1.hour) } let!(:user) { create(:user) } it "returns the subscribable collective rdvs (rdv and rdv_with_user)" do @@ -94,8 +94,8 @@ let!(:agent) { create(:agent) } let!(:motif) { create(:motif, collectif: true, organisation: organisation, sectorisation_level: "agent") } - let!(:rdv) { create(:rdv, :future, motif: motif, lieu: lieu, agents: [agent]) } - let!(:rdv2) { create(:rdv, :future, motif: motif, lieu: lieu, agents: [build(:agent)]) } + let!(:rdv) { create(:rdv, motif: motif, lieu: lieu, agents: [agent], starts_at: 2.days.from_now.at_noon) } + let!(:rdv2) { create(:rdv, motif: motif, lieu: lieu, agents: [build(:agent)], starts_at: 2.days.from_now.at_noon) } let!(:geo_search) { instance_double(Users::GeoSearch, attributed_agents_by_organisation: { organisation => [agent] }) } it "returns the rdv linked to the geo attributed agents" do @@ -110,8 +110,8 @@ let!(:agent) { create(:agent) } let!(:user) { create(:user, referent_agents: [agent]) } let!(:motif) { create(:motif, collectif: true, organisation: organisation, follow_up: true) } - let!(:rdv) { create(:rdv, :future, motif: motif, lieu: lieu, agents: [agent]) } - let!(:rdv2) { create(:rdv, :future, motif: motif, lieu: lieu, agents: [build(:agent)]) } + let!(:rdv) { create(:rdv, motif: motif, lieu: lieu, agents: [agent], starts_at: 2.days.from_now.at_noon) } + let!(:rdv2) { create(:rdv, motif: motif, lieu: lieu, agents: [build(:agent)], starts_at: 2.days.from_now.at_noon) } it "returns the rdv linked to referents" do expect(subject.next_availability).to eq(rdv) diff --git a/spec/support/calendar.ics b/spec/support/calendar.ics index 80a01ff897..820ef9d49b 100644 --- a/spec/support/calendar.ics +++ b/spec/support/calendar.ics @@ -22,35 +22,35 @@ TZNAME:CET END:STANDARD END:VTIMEZONE BEGIN:VEVENT -DTSTAMP:20220707T220000Z +DTSTAMP:20220708T140000Z UID:abb701a5-381a-4fae-9157-129b5843834c -DTSTART;TZID=Europe/Paris:20220711T000000 -DTEND;TZID=Europe/Paris:20220711T004500 +DTSTART;TZID=Europe/Paris:20220711T160000 +DTEND;TZID=Europe/Paris:20220711T164500 DESCRIPTION:plus d'infos dans RDV Solidarités: http://www.rdv-solidarites- test.localhost/admin/organisations/123000/rdvs/123123 -LOCATION:Lieu n°3 (3 rue de l'adresse\, Ville\, 12345) +LOCATION:CMS Le Vernay (22 avenue Germain Perréard\, 74960 Cran Gevrier) STATUS:CONFIRMED SUMMARY:Atelier collectif (1/5) END:VEVENT BEGIN:VEVENT -DTSTAMP:20220707T220000Z +DTSTAMP:20220708T140000Z UID:749336ce-eaca-40a3-8c28-246ed8d18849 -DTSTART;TZID=Europe/Paris:20220710T000000 -DTEND;TZID=Europe/Paris:20220710T004500 +DTSTART;TZID=Europe/Paris:20220710T160000 +DTEND;TZID=Europe/Paris:20220710T164500 DESCRIPTION:plus d'infos dans RDV Solidarités: http://www.rdv-solidarites- test.localhost/admin/organisations/123000/rdvs/789000 -LOCATION:Lieu n°2 (2 rue de l'adresse\, Ville\, 12345) +LOCATION:CMS Le Vernay (22 avenue Germain Perréard\, 74960 Cran Gevrier) STATUS:CANCELLED SUMMARY:Accompagnement individuel END:VEVENT BEGIN:VEVENT -DTSTAMP:20220707T220000Z +DTSTAMP:20220708T140000Z UID:e0a8dbac-d06c-4d18-98c6-a48f47fddd4c -DTSTART;TZID=Europe/Paris:20220709T000000 -DTEND;TZID=Europe/Paris:20220709T004500 +DTSTART;TZID=Europe/Paris:20220709T160000 +DTEND;TZID=Europe/Paris:20220709T164500 DESCRIPTION:plus d'infos dans RDV Solidarités: http://www.rdv-solidarites- test.localhost/admin/organisations/123000/rdvs/456000 -LOCATION:Lieu n°1 (1 rue de l'adresse\, Ville\, 12345) +LOCATION:CMS Le Vernay (22 avenue Germain Perréard\, 74960 Cran Gevrier) STATUS:CONFIRMED SUMMARY:Accompagnement individuel END:VEVENT