Skip to content

Commit

Permalink
Récupération de l'objet 'SchoolYear' plutôt que l'année scolaire
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 committed Oct 21, 2024
1 parent a739d70 commit 312e8ec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def choose_redirect_page!
end

def fetch_students_for!(establishments)
ActiveJob.perform_all_later(establishments.map { |e| Sync::ClassesJob.new(e, selected_school_year.start_year) })
ActiveJob.perform_all_later(establishments.map { |e| Sync::ClassesJob.new(e, selected_school_year) })
end

def fetch_establishments!
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/sync/classes_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def perform(establishment, school_year)
api = establishment.students_api

api
.fetch_resource(:establishment_students, uai: establishment.uai, school_year:)
.fetch_resource(:establishment_students, uai: establishment.uai, school_year: school_year.start_year)
.then { |data| api.mapper.new(data, establishment.uai).parse! }
end
end
Expand Down
11 changes: 7 additions & 4 deletions spec/jobs/sync/classes_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
include ActiveJob::TestHelper

let(:establishment) { create(:establishment, :sygne_provider) }
let(:school_year) { SchoolYear.current }
let(:api_double) { class_double(StudentsApi::Sygne::Api) }
let(:mapper_double) { instance_double(Student::Mappers::Sygne) }

before do
allow(StudentsApi).to receive(:api_for).with("sygne").and_return(api_double)

allow(api_double).to receive(:fetch_resource).with(:establishment_students, uai: establishment.uai, school_year: 2022)
allow(api_double).to receive(:fetch_resource).with(:establishment_students,
uai: establishment.uai,
school_year: school_year.start_year)
allow(api_double)
.to receive(:mapper)
.and_return(class_double(Student::Mappers::Sygne, new: mapper_double))
Expand All @@ -21,13 +24,13 @@
end

it "calls the matchingStudentsApi proxy" do
described_class.perform_now(establishment, 2022)
described_class.perform_now(establishment, school_year)

expect(StudentsApi).to have_received(:api_for).with("sygne")
end

it "maps and parse the results" do
described_class.perform_now(establishment, 2022)
described_class.perform_now(establishment, school_year)

expect(mapper_double).to have_received(:parse!)
end
Expand All @@ -39,7 +42,7 @@

it "rescues and retry" do
perform_enqueued_jobs do
described_class.perform_now(establishment, 2022)
described_class.perform_now(establishment, school_year)
rescue Faraday::UnauthorizedError # rubocop:disable Lint/SuppressedException
end

Expand Down

0 comments on commit 312e8ec

Please sign in to comment.