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

Davantage de fuzzing dans les factories #4809

Draft
wants to merge 16 commits into
base: production
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions app/models/concerns/rdv/address_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions app/models/rdv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
2 changes: 1 addition & 1 deletion spec/blueprint/rdv_blueprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/absence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions spec/factories/agent.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/generators.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 2 additions & 5 deletions spec/factories/lieu.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
8 changes: 4 additions & 4 deletions spec/factories/motif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
7 changes: 2 additions & 5 deletions spec/factories/organisation.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/prescripteur.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions spec/factories/rdv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/receipt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -16,7 +16,7 @@
channel { :mail }
sms_count { nil }
sms_phone_number { nil }
email_address { "[email protected]" }
email_address { user.email || Faker::Internet.email }
end
end
end
4 changes: 1 addition & 3 deletions spec/factories/super_admin.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/team.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :team do
territory { association(:territory) }
territory
name { "#{Faker::Team.name} #{SecureRandom.hex(4)}" }
end
end
8 changes: 3 additions & 5 deletions spec/factories/territory.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
18 changes: 7 additions & 11 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
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
num = ""
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" }
Expand Down
12 changes: 6 additions & 6 deletions spec/features/agents/agent_can_crud_intervenants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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("[email protected]")
expect(page).to have_content("FICTIF Bob")

Expand All @@ -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(
Expand Down Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions spec/features/agents/agent_can_crud_motifs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@
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

click_on "Modifier"
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
Expand Down
4 changes: 2 additions & 2 deletions spec/features/agents/agent_can_prescribe_rdvs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/features/agents/agents/crud_on_agents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,28 @@
create(:agent, first_name: "Tony", last_name: "Patrick", email: "[email protected]", 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
fill_in "Email", with: "[email protected]"
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("[email protected]")

click_on "Se déconnecter"
Expand Down
Loading
Loading