From a739d706212b5edfffc64b07f0424d907b90b655 Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Mon, 21 Oct 2024 09:45:28 +0200 Subject: [PATCH 1/9] =?UTF-8?q?Ajout=20de=20l'ann=C3=A9e=20scolaire=20sur?= =?UTF-8?q?=20le=20Job=20'ClassesJob'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/apis/students_api/sygne/api.rb | 6 +++--- app/controllers/users/omniauth_callbacks_controller.rb | 2 +- app/jobs/sync/classes_job.rb | 4 ++-- config/locales/fr.yml | 2 +- spec/apis/students_api/sygne/api_spec.rb | 4 ++-- spec/jobs/sync/classes_job_spec.rb | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/apis/students_api/sygne/api.rb b/app/apis/students_api/sygne/api.rb index e65d4a064..43d8b2e64 100644 --- a/app/apis/students_api/sygne/api.rb +++ b/app/apis/students_api/sygne/api.rb @@ -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) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 908ea22f3..5044165f2 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -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! diff --git a/app/jobs/sync/classes_job.rb b/app/jobs/sync/classes_job.rb index f946541f8..026f7d9ed 100644 --- a/app/jobs/sync/classes_job.rb +++ b/app/jobs/sync/classes_job.rb @@ -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) @@ -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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index a19e3a7c7..c9e5a5d7a 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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 diff --git a/spec/apis/students_api/sygne/api_spec.rb b/spec/apis/students_api/sygne/api_spec.rb index 3b4a43351..94fde20dd 100644 --- a/spec/apis/students_api/sygne/api_spec.rb +++ b/spec/apis/students_api/sygne/api_spec.rb @@ -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 diff --git a/spec/jobs/sync/classes_job_spec.rb b/spec/jobs/sync/classes_job_spec.rb index fe424a69c..0d4302835 100644 --- a/spec/jobs/sync/classes_job_spec.rb +++ b/spec/jobs/sync/classes_job_spec.rb @@ -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)) @@ -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 @@ -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 From 312e8ec706466c1788b5747de744f9ebca6f1c06 Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Mon, 21 Oct 2024 10:20:04 +0200 Subject: [PATCH 2/9] =?UTF-8?q?R=C3=A9cup=C3=A9ration=20de=20l'objet=20'Sc?= =?UTF-8?q?hoolYear'=20plut=C3=B4t=20que=20l'ann=C3=A9e=20scolaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../users/omniauth_callbacks_controller.rb | 2 +- app/jobs/sync/classes_job.rb | 2 +- spec/jobs/sync/classes_job_spec.rb | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 5044165f2..63c871e14 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -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! diff --git a/app/jobs/sync/classes_job.rb b/app/jobs/sync/classes_job.rb index 026f7d9ed..355fb72dd 100644 --- a/app/jobs/sync/classes_job.rb +++ b/app/jobs/sync/classes_job.rb @@ -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 diff --git a/spec/jobs/sync/classes_job_spec.rb b/spec/jobs/sync/classes_job_spec.rb index 0d4302835..e86e8a54a 100644 --- a/spec/jobs/sync/classes_job_spec.rb +++ b/spec/jobs/sync/classes_job_spec.rb @@ -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)) @@ -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 @@ -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 From 17083e4913ce315603a5b4dd2ea6feb3964d87ca Mon Sep 17 00:00:00 2001 From: pskl Date: Mon, 21 Oct 2024 15:18:28 +0200 Subject: [PATCH 3/9] Fix year related params for classe --- app/apis/students_api/sygne/mappers/classe_mapper.rb | 4 ++-- .../{1_scolarite.feature => gestion_scolarites.feature} | 0 features/step_definitions/job_steps.rb | 2 +- spec/support/webmock_helpers.rb | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) rename features/{1_scolarite.feature => gestion_scolarites.feature} (100%) diff --git a/app/apis/students_api/sygne/mappers/classe_mapper.rb b/app/apis/students_api/sygne/mappers/classe_mapper.rb index b67f8c150..b2d050ccf 100644 --- a/app/apis/students_api/sygne/mappers/classe_mapper.rb +++ b/app/apis/students_api/sygne/mappers/classe_mapper.rb @@ -9,13 +9,13 @@ class ClasseMapper < Dry::Transformer::Pipe define! do deep_symbolize_keys - rename_keys(codeMefRatt: :mef_code, classe: :label) + rename_keys(codeMefRatt: :mef_code, classe: :label, anneeScolaire: :year) map_value(:mef_code, Dry::Transformer::Coercions[:to_string]) map_value :mef_code, ->(value) { value.chop } - accept_keys %i[label mef_code] + accept_keys %i[label mef_code year] end end end diff --git a/features/1_scolarite.feature b/features/gestion_scolarites.feature similarity index 100% rename from features/1_scolarite.feature rename to features/gestion_scolarites.feature diff --git a/features/step_definitions/job_steps.rb b/features/step_definitions/job_steps.rb index 9c04a3da2..9f0b4a308 100644 --- a/features/step_definitions/job_steps.rb +++ b/features/step_definitions/job_steps.rb @@ -18,7 +18,7 @@ end Quand("la liste des élèves de l'établissement {string} est rafraîchie") do |uai| - Sync::ClassesJob.perform_later(Establishment.find_by(uai: uai)) + Sync::ClassesJob.perform_later(Establishment.find_by(uai: uai), SchoolYear.current) end # NOTE: pas très élégant mais comme le job parent diff --git a/spec/support/webmock_helpers.rb b/spec/support/webmock_helpers.rb index 9de0e978e..89c52cd08 100644 --- a/spec/support/webmock_helpers.rb +++ b/spec/support/webmock_helpers.rb @@ -45,12 +45,12 @@ def mock_sygne_student_schoolings_endpoint(ine, payload) .to_return(status: 200, body: payload, headers: { "Content-Type" => "application/json" }) end - def mock_sygne_students_endpoint(uai, payload) - url = StudentsApi::Sygne::Api.establishment_students_endpoint(uai: uai) + def mock_sygne_students_endpoint(uai, payload, school_year = SchoolYear.current) + url = StudentsApi::Sygne::Api.establishment_students_endpoint(uai: uai, school_year: school_year) WebMock.stub_request(:get, url) .with( - query: { "etat-scolarisation" => true }, + query: { "etat-scolarisation" => true, "annee-scolaire" => school_year.start_year }, headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", From 8cbb12cbb76342de86d030cd758ae35bc1ac0925 Mon Sep 17 00:00:00 2001 From: pskl Date: Mon, 21 Oct 2024 15:20:31 +0200 Subject: [PATCH 4/9] Update mock rev --- mock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock b/mock index f9247b78b..c93268805 160000 --- a/mock +++ b/mock @@ -1 +1 @@ -Subproject commit f9247b78b584c98d275994f1e4676ee93c2723f0 +Subproject commit c93268805e70765ccccaaa3993e1abff6c3372ac From 5c120bc83b6f4828ab5f145030700c3d9efb38ce Mon Sep 17 00:00:00 2001 From: pskl Date: Mon, 21 Oct 2024 15:40:07 +0200 Subject: [PATCH 5/9] Fix random stuff --- app/controllers/schoolings_controller.rb | 5 ++--- app/models/student/mappers/base.rb | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/schoolings_controller.rb b/app/controllers/schoolings_controller.rb index faee68d8c..341848422 100644 --- a/app/controllers/schoolings_controller.rb +++ b/app/controllers/schoolings_controller.rb @@ -3,7 +3,6 @@ class SchoolingsController < ApplicationController include RoleCheck - before_action :set_schooling, only: [:update] before_action :authenticate_user!, :set_classe, :set_schooling before_action :check_director, :update_confirmed_director!, :check_confirmed_director, only: %i[abrogate_decision update] @@ -27,7 +26,7 @@ def confirm_removal; end def confirm_removal_cancellation; end def remove - @schooling.update(removed_at: params[:value]) + @schooling.update!(removed_at: params[:value]) redirect_to school_year_class_path(selected_school_year, @classe), notice: t("flash.schooling.removed", name: @schooling.student, classe: @schooling.classe.label) @@ -53,7 +52,7 @@ def update # rubocop:disable Metrics/AbcSize def set_schooling @schooling = Schooling.find(params[:id]) rescue ActiveRecord::RecordNotFound - redirect_to @classe, alert: t("errors.schoolings.not_found") + redirect_to school_year_classes_path(selected_school_year), alert: t("errors.schoolings.not_found") end def schooling_params diff --git a/app/models/student/mappers/base.rb b/app/models/student/mappers/base.rb index c0c340ea9..51682ee4c 100644 --- a/app/models/student/mappers/base.rb +++ b/app/models/student/mappers/base.rb @@ -36,6 +36,8 @@ def parse! begin map_schooling!(classe, student, entry) rescue StandardError => e + raise e unless Rails.env.production? + Sentry.capture_exception( SchoolingParsingError.new( "Schooling parsing failed for #{uai}: #{e.message}" From 1be5285a72972cd385122556af815c103e9fd15d Mon Sep 17 00:00:00 2001 From: pskl Date: Mon, 21 Oct 2024 15:47:09 +0200 Subject: [PATCH 6/9] Fix api_spec --- spec/apis/students_api/sygne/api_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/apis/students_api/sygne/api_spec.rb b/spec/apis/students_api/sygne/api_spec.rb index 94fde20dd..77564feb6 100644 --- a/spec/apis/students_api/sygne/api_spec.rb +++ b/spec/apis/students_api/sygne/api_spec.rb @@ -8,7 +8,7 @@ before do mock_sygne_token - mock_sygne_students_endpoint("007", {}.to_json) + mock_sygne_students_endpoint("007", {}.to_json, SchoolYear.create!(start_year: 2022)) mock_sygne_student_endpoint_with("007", {}.to_json) mock_sygne_student_schoolings_endpoint("123", {}.to_json) end @@ -32,7 +32,7 @@ end [ - [:establishment_students, { uai: "007" }], + [:establishment_students, { uai: "007", school_year: 2022 }], [:student, { ine: "007" }], [:student_schoolings, { ine: "007" }] ].each do |resource, params| From cbb857a1377830e0c2100d18c7d94fef0f540060 Mon Sep 17 00:00:00 2001 From: pskl Date: Mon, 21 Oct 2024 16:00:33 +0200 Subject: [PATCH 7/9] Fix even more random stuff (reloaded) --- features/step_definitions/api_steps.rb | 2 +- spec/apis/students_api/sygne/api_spec.rb | 2 +- spec/support/webmock_helpers.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/step_definitions/api_steps.rb b/features/step_definitions/api_steps.rb index 91d8af06e..72f116863 100644 --- a/features/step_definitions/api_steps.rb +++ b/features/step_definitions/api_steps.rb @@ -93,7 +93,7 @@ end Sachantque("les élèves de l'établissement {string} sont rafraîchis") do |uai| - Sync::ClassesJob.new(Establishment.find_by(uai: uai)).perform_now + Sync::ClassesJob.new(Establishment.find_by(uai: uai), SchoolYear.current).perform_now end Sachantque("l'API SYGNE renvoie un élève avec l'INE {string} qui a quitté l'établissement {string}") do |ine, uai| diff --git a/spec/apis/students_api/sygne/api_spec.rb b/spec/apis/students_api/sygne/api_spec.rb index 77564feb6..3d23ce016 100644 --- a/spec/apis/students_api/sygne/api_spec.rb +++ b/spec/apis/students_api/sygne/api_spec.rb @@ -8,7 +8,7 @@ before do mock_sygne_token - mock_sygne_students_endpoint("007", {}.to_json, SchoolYear.create!(start_year: 2022)) + mock_sygne_students_endpoint("007", {}.to_json, 2022) mock_sygne_student_endpoint_with("007", {}.to_json) mock_sygne_student_schoolings_endpoint("123", {}.to_json) end diff --git a/spec/support/webmock_helpers.rb b/spec/support/webmock_helpers.rb index 89c52cd08..f41ce2965 100644 --- a/spec/support/webmock_helpers.rb +++ b/spec/support/webmock_helpers.rb @@ -45,12 +45,12 @@ def mock_sygne_student_schoolings_endpoint(ine, payload) .to_return(status: 200, body: payload, headers: { "Content-Type" => "application/json" }) end - def mock_sygne_students_endpoint(uai, payload, school_year = SchoolYear.current) + def mock_sygne_students_endpoint(uai, payload, school_year = SchoolYear.current.start_year) url = StudentsApi::Sygne::Api.establishment_students_endpoint(uai: uai, school_year: school_year) WebMock.stub_request(:get, url) .with( - query: { "etat-scolarisation" => true, "annee-scolaire" => school_year.start_year }, + query: { "etat-scolarisation" => true, "annee-scolaire" => school_year }, headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", From 11b3f974e15c08923907e36dc138a1b341733162 Mon Sep 17 00:00:00 2001 From: pskl Date: Mon, 21 Oct 2024 16:16:51 +0200 Subject: [PATCH 8/9] Fix and restructure payment_request_spec --- spec/models/asp/payment_request_spec.rb | 29 ++++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/spec/models/asp/payment_request_spec.rb b/spec/models/asp/payment_request_spec.rb index 7929d5883..c8437686d 100644 --- a/spec/models/asp/payment_request_spec.rb +++ b/spec/models/asp/payment_request_spec.rb @@ -166,36 +166,39 @@ end describe "eligible_for_rejected_or_unpaid_auto_retry?" do - let(:p_r_rejected) { create(:asp_payment_request, :rejected) } - let(:p_r_rejected_rib) do - create(:asp_payment_request, :rejected, reason: "Test d'une raison de blocage d'un paiement bancaire") - end - let(:p_r_unpaid) { create(:asp_payment_request, :unpaid) } - let(:p_r_unpaid_rib) do - create(:asp_payment_request, :unpaid, reason: "Test d'une raison de blocage d'un paiement bancaire") - end - context "when the payment request is in 'rejected' state without a RIB reason" do + let(:p_r) { create(:asp_payment_request, :rejected) } + it "returns false" do - expect(p_r_rejected.eligible_for_rejected_or_unpaid_auto_retry?).to be false + expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be false end end context "when the payment request is in 'rejected' state with a RIB reason" do + let(:p_r) do + create(:asp_payment_request, :rejected, reason: "Test d'une raison de blocage d'un paiement bancaire") + end + it "returns true" do - expect(p_r_rejected_rib.eligible_for_rejected_or_unpaid_auto_retry?).to be true + expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be true end end context "when the payment request is in 'unpaid' state without a RIB reason" do + let(:p_r) { create(:asp_payment_request, :unpaid) } + it "returns false" do - expect(p_r_unpaid.eligible_for_rejected_or_unpaid_auto_retry?).to be false + expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be false end end context "when the payment request is in 'unpaid' state with a RIB reason" do + let(:p_r) do + create(:asp_payment_request, :unpaid, reason: "Test d'une raison de blocage d'un paiement bancaire") + end + it "returns true" do - expect(p_r_unpaid_rib.eligible_for_rejected_or_unpaid_auto_retry?).to be true + expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be true end end end From 8c099206e04db39edc27046c370ebef27a1b372e Mon Sep 17 00:00:00 2001 From: tnicolas1 Date: Mon, 21 Oct 2024 16:34:40 +0200 Subject: [PATCH 9/9] Renommer '1_scolarite.feature' --- features/{gestion_scolarites.feature => 1_scolarite.feature} | 0 mock | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename features/{gestion_scolarites.feature => 1_scolarite.feature} (100%) diff --git a/features/gestion_scolarites.feature b/features/1_scolarite.feature similarity index 100% rename from features/gestion_scolarites.feature rename to features/1_scolarite.feature diff --git a/mock b/mock index c93268805..f9247b78b 160000 --- a/mock +++ b/mock @@ -1 +1 @@ -Subproject commit c93268805e70765ccccaaa3993e1abff6c3372ac +Subproject commit f9247b78b584c98d275994f1e4676ee93c2723f0