Skip to content

Commit

Permalink
Ajout de l'année scolaire sur le Job 'ClassesJob'
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 committed Oct 21, 2024
1 parent bdb8211 commit a739d70
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/apis/students_api/sygne/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module Sygne
class Api < StudentsApi::Base
class << self
def establishment_students_endpoint(params)
base_url +
format("etablissements/%s/eleves?statut=ST&annee-scolaire=#{SchoolYear.current.start_year}&etat-scolarisation=true", # rubocop:disable Layout/LineLength
params[:uai])
query = { statut: "ST", "annee-scolaire": params[:school_year], "etat-scolarisation": true }.to_query

base_url + format("etablissements/%s/eleves?#{query}", params[:uai])
end

def student_endpoint(params)
Expand Down
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) })
ActiveJob.perform_all_later(establishments.map { |e| Sync::ClassesJob.new(e, selected_school_year.start_year) })
end

def fetch_establishments!
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/sync/classes_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ClassesJob < ApplicationJob
establishment.update!(fetching_students: false)
end

def perform(establishment)
def perform(establishment, school_year)
# NOTE: there is a bug in Sygne where students are removed from classes
# earlier than they should be so we disable student list fetching for now
# (only in production because we want to keep our tests intact)
Expand All @@ -28,7 +28,7 @@ def perform(establishment)
api = establishment.students_api

api
.fetch_resource(:establishment_students, uai: establishment.uai)
.fetch_resource(:establishment_students, uai: establishment.uai, school_year:)
.then { |data| api.mapper.new(data, establishment.uai).parse! }
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ fr:
1CAP1: CAP en 1 an
1CAP2: 1ère année de CAP
1CAP2A: 1ère année de CAP agricole
2CAP2: 2ène année de CAP
2CAP2: 2ème année de CAP
2CAP2A: 2ème année de CAP agricole
2CAP3: 2ème année CAP en 3 ans
3CAP3: 3ème année de CAP en 3 ans
Expand Down
4 changes: 2 additions & 2 deletions spec/apis/students_api/sygne/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

describe "endpoints" do
specify "establishment students endpoint" do
expect(api.establishment_students_endpoint(uai: "007")).to(
expect(api.establishment_students_endpoint(uai: "007", school_year: 2022)).to(
end_with(
"etablissements/007/eleves?statut=ST&annee-scolaire=#{SchoolYear.current.start_year}&etat-scolarisation=true"
"etablissements/007/eleves?annee-scolaire=2022&etat-scolarisation=true&statut=ST"
)
)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/jobs/sync/classes_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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)
allow(api_double).to receive(:fetch_resource).with(:establishment_students, uai: establishment.uai, school_year: 2022)
allow(api_double)
.to receive(:mapper)
.and_return(class_double(Student::Mappers::Sygne, new: mapper_double))
Expand All @@ -21,13 +21,13 @@
end

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

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

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

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

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

Expand Down

0 comments on commit a739d70

Please sign in to comment.