Skip to content

Commit

Permalink
do not use specific ids in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Holist committed Oct 2, 2024
1 parent a57cb07 commit 823c680
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
44 changes: 22 additions & 22 deletions spec/jobs/inbound_webhooks/rdv_solidarites/process_rdv_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
}.deep_symbolize_keys
end

let!(:user) { create(:user, organisations: [organisation], id: 3) }
let!(:user2) { create(:user, organisations: [organisation], id: 4) }
let!(:user) { create(:user, organisations: [organisation]) }
let!(:user2) { create(:user, organisations: [organisation]) }

let!(:agent) { create(:agent) }

Expand Down Expand Up @@ -101,15 +101,6 @@
)
end

let!(:invitation3) do
create(
:invitation,
organisations: [organisation],
follow_up: follow_up,
expires_at: 3.days.ago
)
end

let!(:follow_up) do
build(:follow_up, motif_category: motif_category, user: user)
end
Expand Down Expand Up @@ -176,6 +167,15 @@
end

context "it upserts the rdv (for a create)" do
let!(:invitation3) do
create(
:invitation,
organisations: [organisation],
follow_up: follow_up,
expires_at: 3.days.ago
)
end

it "enqueues a job to upsert the rdv" do
expect(UpsertRecordJob).to receive(:perform_later)
.with(
Expand Down Expand Up @@ -355,7 +355,7 @@
id: 2,
status: "seen",
created_by: "user",
user_id: 4,
user_id: user2.id,
rdv_solidarites_participation_id: 999,
follow_up_id: follow_up2.id,
rdv_solidarites_agent_prescripteur_id: nil
Expand Down Expand Up @@ -461,7 +461,7 @@
id: nil,
status: "unknown",
created_by: "user",
user_id: 3,
user_id: user.id,
rdv_solidarites_participation_id: 998,
follow_up_id: follow_up.id,
convocable: true,
Expand All @@ -471,7 +471,7 @@
id: nil,
status: "unknown",
created_by: "user",
user_id: 4,
user_id: user2.id,
rdv_solidarites_participation_id: 999,
follow_up_id: follow_up2.id,
convocable: true,
Expand All @@ -498,7 +498,7 @@
id: nil,
status: "unknown",
created_by: "user",
user_id: 3,
user_id: user.id,
rdv_solidarites_participation_id: 998,
follow_up_id: follow_up.id,
convocable: false,
Expand All @@ -508,7 +508,7 @@
id: nil,
status: "unknown",
created_by: "user",
user_id: 4,
user_id: user2.id,
rdv_solidarites_participation_id: 999,
follow_up_id: follow_up2.id,
convocable: false,
Expand Down Expand Up @@ -582,7 +582,7 @@
id: nil,
status: "unknown",
created_by: "agent",
user_id: 3,
user_id: user.id,
rdv_solidarites_participation_id: 998,
follow_up_id: follow_up.id,
convocable: true,
Expand All @@ -592,7 +592,7 @@
id: nil,
status: "unknown",
created_by: "user",
user_id: 4,
user_id: user2.id,
rdv_solidarites_participation_id: 999,
follow_up_id: follow_up2.id,
convocable: false,
Expand Down Expand Up @@ -622,7 +622,7 @@
id: nil,
status: "unknown",
created_by: "agent",
user_id: 3,
user_id: user.id,
rdv_solidarites_participation_id: 998,
follow_up_id: follow_up.id,
convocable: false,
Expand All @@ -632,7 +632,7 @@
id: nil,
status: "unknown",
created_by: "user",
user_id: 4,
user_id: user2.id,
rdv_solidarites_participation_id: 999,
follow_up_id: follow_up2.id,
convocable: false,
Expand Down Expand Up @@ -702,7 +702,7 @@
id: nil,
status: "unknown",
created_by: "agent",
user_id: 3,
user_id: user.id,
rdv_solidarites_participation_id: 998,
follow_up_id: follow_up.id,
convocable: true,
Expand All @@ -712,7 +712,7 @@
id: nil,
status: "unknown",
created_by: "user",
user_id: 4,
user_id: user2.id,
rdv_solidarites_participation_id: 999,
follow_up_id: follow_up2.id,
convocable: false,
Expand Down
17 changes: 9 additions & 8 deletions spec/jobs/refresh_out_of_date_follow_up_statuses_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,49 @@
# status out of date
let!(:participation1) { create(:participation, status: "unknown", follow_up: follow_up1) }
let!(:rdv1) { create(:rdv, starts_at: 1.day.ago, participations: [participation1]) }
let!(:follow_up1) { create(:follow_up, status: "rdv_pending", id: 1) }
let!(:follow_up1) { create(:follow_up, status: "rdv_pending") }

# ok
let!(:follow_up2) { create(:follow_up, status: "not_invited", id: 2) }
let!(:follow_up2) { create(:follow_up, status: "not_invited") }

# status out of date
let!(:follow_up3) { create(:follow_up, status: "invitation_pending", id: 3) }
let!(:follow_up3) { create(:follow_up, status: "invitation_pending") }
let!(:invitation) { create(:invitation, created_at: 3.days.ago) }
let!(:rdv3) { create(:rdv, participations: [participation3]) }
let!(:participation3) { create(:participation, created_at: 2.days.ago, status: "unknown", follow_up: follow_up3) }

# ok
let!(:follow_up4) { create(:follow_up, status: "rdv_seen", id: 4) }
let!(:follow_up4) { create(:follow_up, status: "rdv_seen") }
let!(:rdv4) do
create(:rdv, starts_at: 1.day.ago, participations: [participation4])
end
let!(:participation4) { create(:participation, follow_up: follow_up4, status: "seen") }

# status out of date
let!(:follow_up5) { create(:follow_up, status: "rdv_pending", id: 5) }
let!(:follow_up5) { create(:follow_up, status: "rdv_pending") }
let!(:rdv5) { create(:rdv, starts_at: 1.day.ago, participations: [participation5]) }
let!(:participation5) { create(:participation, status: "seen", follow_up: follow_up5) }

describe "#perform" do
before do
# remove follow-ups created in callbacks
FollowUp.where.not(id: [1, 2, 3, 4, 5]).find_each(&:destroy!)
FollowUp.where.not(id: [follow_up1.id, follow_up2.id, follow_up3.id, follow_up4.id,
follow_up5.id]).find_each(&:destroy!)
allow(RefreshFollowUpStatusesJob).to receive(:perform_later)
allow(MattermostClient).to receive(:send_to_notif_channel)
allow(ENV).to receive(:[]).with("SENTRY_ENVIRONMENT").and_return("production")
end

it "enqueues a refresh job for out of date follow-ups" do
expect(RefreshFollowUpStatusesJob).to receive(:perform_later)
.with([1, 3, 5])
.with([follow_up1.id, follow_up3.id, follow_up5.id])
subject
end

it "sends a notification on mattermost" do
expect(MattermostClient).to receive(:send_to_notif_channel)
.with(
"✨ Rafraîchit les statuts pour: [1, 3, 5]"
"✨ Rafraîchit les statuts pour: [#{follow_up1.id}, #{follow_up3.id}, #{follow_up5.id}]"
)
subject
end
Expand Down

0 comments on commit 823c680

Please sign in to comment.