diff --git a/Gemfile.lock b/Gemfile.lock index 3d8d3d540..b54bf1331 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -792,9 +792,9 @@ GEM xray-rails (0.3.2) rails (>= 3.1.0) zeitwerk (2.4.2) - zip_tricks (5.3.1) - zipline (1.2.1) - rails (>= 3.2.1, < 6.1) + zip_tricks (5.5.0) + zipline (1.3.0) + actionpack (>= 3.2.1, < 7.0) zip_tricks (>= 4.2.1, < 6.0) zxcvbn-ruby (1.1.0) diff --git a/app/assets/stylesheets/stats.scss b/app/assets/stylesheets/stats.scss index 4b9b8b58e..28da6239c 100644 --- a/app/assets/stylesheets/stats.scss +++ b/app/assets/stylesheets/stats.scss @@ -125,7 +125,7 @@ $segmented-control-item-border-radius: 2 * $default-space; $big-number-card-padding: 2 * $segmented-control-item-border-radius; .big-number-card { - padding: $big-number-card-padding; + padding: $big-number-card-padding $segmented-control-item-horizontal-padding; } .big-number-card-title { diff --git a/app/controllers/api/v2/graphql_controller.rb b/app/controllers/api/v2/graphql_controller.rb index dafa1099c..cc4b25ad8 100644 --- a/app/controllers/api/v2/graphql_controller.rb +++ b/app/controllers/api/v2/graphql_controller.rb @@ -2,7 +2,7 @@ class API::V2::GraphqlController < API::V2::BaseController def execute variables = ensure_hash(params[:variables]) - result = Api::V2::Schema.execute(params[:query], + result = API::V2::Schema.execute(params[:query], variables: variables, context: context, operation_name: params[:operationName]) diff --git a/app/controllers/champs/carte_controller.rb b/app/controllers/champs/carte_controller.rb index c15ce9774..f0e51754a 100644 --- a/app/controllers/champs/carte_controller.rb +++ b/app/controllers/champs/carte_controller.rb @@ -11,7 +11,7 @@ class Champs::CarteController < ApplicationController @champ.geo_areas += GeoArea.from_feature_collection(cadastres_features_collection(@champ.to_feature_collection)) @champ.save! end - rescue ApiCarto::API::ResourceNotFound + rescue APICarto::API::ResourceNotFound flash.alert = 'Les données cartographiques sont temporairement indisponibles. Réessayez dans un instant.' response.status = 503 end @@ -77,7 +77,7 @@ class Champs::CarteController < ApplicationController end if coordinates.present? - cadastres = ApiCartoService.generate_cadastre(coordinates) + cadastres = APICartoService.generate_cadastre(coordinates) { type: 'FeatureCollection', diff --git a/app/controllers/champs/siret_controller.rb b/app/controllers/champs/siret_controller.rb index 60f5f1e48..bc279baf0 100644 --- a/app/controllers/champs/siret_controller.rb +++ b/app/controllers/champs/siret_controller.rb @@ -17,7 +17,7 @@ class Champs::SiretController < ApplicationController begin etablissement = find_etablissement_with_siret - rescue ApiEntreprise::API::Error::RequestFailed, ApiEntreprise::API::Error::ServiceUnavailable + rescue APIEntreprise::API::Error::RequestFailed, APIEntreprise::API::Error::ServiceUnavailable # i18n-tasks-use t('errors.siret_network_error') return siret_error(:network_error) end @@ -53,7 +53,7 @@ class Champs::SiretController < ApplicationController end def find_etablissement_with_siret - ApiEntrepriseService.create_etablissement(@champ, @siret, current_user.id) + APIEntrepriseService.create_etablissement(@champ, @siret, current_user.id) end def clear_siret_and_etablissement diff --git a/app/controllers/new_administrateur/procedures_controller.rb b/app/controllers/new_administrateur/procedures_controller.rb index 1e74e2312..bebb3a255 100644 --- a/app/controllers/new_administrateur/procedures_controller.rb +++ b/app/controllers/new_administrateur/procedures_controller.rb @@ -129,7 +129,7 @@ module NewAdministrateur @procedure.api_entreprise_token = token if @procedure.valid? && - ApiEntreprise::PrivilegesAdapter.new(token).valid? && + APIEntreprise::PrivilegesAdapter.new(token).valid? && @procedure.save redirect_to jeton_admin_procedure_path(procedure_id: params[:procedure_id]), diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 7d17e2b1d..21d93ef9f 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -97,8 +97,8 @@ module Users sanitized_siret = siret_model.siret begin - etablissement = ApiEntrepriseService.create_etablissement(@dossier, sanitized_siret, current_user.id) - rescue ApiEntreprise::API::Error::RequestFailed, ApiEntreprise::API::Error::BadGateway, ApiEntreprise::API::Error::TimedOut + etablissement = APIEntrepriseService.create_etablissement(@dossier, sanitized_siret, current_user.id) + rescue APIEntreprise::API::Error::RequestFailed, APIEntreprise::API::Error::BadGateway, APIEntreprise::API::Error::TimedOut return render_siret_error(t('errors.messages.siret_network_error')) end if etablissement.nil? diff --git a/app/graphql/api/v2/context.rb b/app/graphql/api/v2/context.rb index 227dee008..4b395d730 100644 --- a/app/graphql/api/v2/context.rb +++ b/app/graphql/api/v2/context.rb @@ -1,4 +1,4 @@ -class Api::V2::Context < GraphQL::Query::Context +class API::V2::Context < GraphQL::Query::Context def has_fragment?(name) if self["has_fragment_#{name}"] true diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index a6fcb596a..25ab2a8ae 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -1,4 +1,4 @@ -class Api::V2::Schema < GraphQL::Schema +class API::V2::Schema < GraphQL::Schema default_max_page_size 100 max_complexity 300 max_depth 15 @@ -6,7 +6,7 @@ class Api::V2::Schema < GraphQL::Schema query Types::QueryType mutation Types::MutationType - context_class Api::V2::Context + context_class API::V2::Context def self.id_from_object(object, type_definition, ctx) object.to_typed_id diff --git a/app/helpers/notice_url_helper.rb b/app/helpers/notice_url_helper.rb index 337cb228a..c1e7df802 100644 --- a/app/helpers/notice_url_helper.rb +++ b/app/helpers/notice_url_helper.rb @@ -1,4 +1,4 @@ -module NoticeUrlHelper +module NoticeURLHelper def notice_url(procedure) if procedure.notice.attached? url_for(procedure.notice) diff --git a/app/jobs/annuaire_education_update_job.rb b/app/jobs/annuaire_education_update_job.rb index 334b268e9..ffd06a27e 100644 --- a/app/jobs/annuaire_education_update_job.rb +++ b/app/jobs/annuaire_education_update_job.rb @@ -3,7 +3,7 @@ class AnnuaireEducationUpdateJob < ApplicationJob external_id = champ.external_id if external_id.present? - data = ApiEducation::AnnuaireEducationAdapter.new(external_id).to_params + data = APIEducation::AnnuaireEducationAdapter.new(external_id).to_params if data.present? champ.data = data diff --git a/app/jobs/api_entreprise/association_job.rb b/app/jobs/api_entreprise/association_job.rb index 26307854c..71d1a9f5a 100644 --- a/app/jobs/api_entreprise/association_job.rb +++ b/app/jobs/api_entreprise/association_job.rb @@ -1,7 +1,7 @@ -class ApiEntreprise::AssociationJob < ApiEntreprise::Job +class APIEntreprise::AssociationJob < APIEntreprise::Job def perform(etablissement_id, procedure_id) find_etablissement(etablissement_id) - etablissement_params = ApiEntreprise::RNAAdapter.new(etablissement.siret, procedure_id).to_params + etablissement_params = APIEntreprise::RNAAdapter.new(etablissement.siret, procedure_id).to_params etablissement.update!(etablissement_params) end end diff --git a/app/jobs/api_entreprise/attestation_fiscale_job.rb b/app/jobs/api_entreprise/attestation_fiscale_job.rb index ab6168f00..6b01a89f1 100644 --- a/app/jobs/api_entreprise/attestation_fiscale_job.rb +++ b/app/jobs/api_entreprise/attestation_fiscale_job.rb @@ -1,7 +1,7 @@ -class ApiEntreprise::AttestationFiscaleJob < ApiEntreprise::Job +class APIEntreprise::AttestationFiscaleJob < APIEntreprise::Job def perform(etablissement_id, procedure_id, user_id) find_etablissement(etablissement_id) - etablissement_params = ApiEntreprise::AttestationFiscaleAdapter.new(etablissement.siret, procedure_id, user_id).to_params + etablissement_params = APIEntreprise::AttestationFiscaleAdapter.new(etablissement.siret, procedure_id, user_id).to_params attestation_fiscale_url = etablissement_params.delete(:entreprise_attestation_fiscale_url) etablissement.upload_attestation_fiscale(attestation_fiscale_url) if attestation_fiscale_url.present? end diff --git a/app/jobs/api_entreprise/attestation_sociale_job.rb b/app/jobs/api_entreprise/attestation_sociale_job.rb index 789afa650..f385a14d3 100644 --- a/app/jobs/api_entreprise/attestation_sociale_job.rb +++ b/app/jobs/api_entreprise/attestation_sociale_job.rb @@ -1,7 +1,7 @@ -class ApiEntreprise::AttestationSocialeJob < ApiEntreprise::Job +class APIEntreprise::AttestationSocialeJob < APIEntreprise::Job def perform(etablissement_id, procedure_id) find_etablissement(etablissement_id) - etablissement_params = ApiEntreprise::AttestationSocialeAdapter.new(etablissement.siret, procedure_id).to_params + etablissement_params = APIEntreprise::AttestationSocialeAdapter.new(etablissement.siret, procedure_id).to_params attestation_sociale_url = etablissement_params.delete(:entreprise_attestation_sociale_url) etablissement.upload_attestation_sociale(attestation_sociale_url) if attestation_sociale_url.present? end diff --git a/app/jobs/api_entreprise/bilans_bdf_job.rb b/app/jobs/api_entreprise/bilans_bdf_job.rb index 7501d3f37..9dca78f85 100644 --- a/app/jobs/api_entreprise/bilans_bdf_job.rb +++ b/app/jobs/api_entreprise/bilans_bdf_job.rb @@ -1,7 +1,7 @@ -class ApiEntreprise::BilansBdfJob < ApiEntreprise::Job +class APIEntreprise::BilansBdfJob < APIEntreprise::Job def perform(etablissement_id, procedure_id) find_etablissement(etablissement_id) - etablissement_params = ApiEntreprise::BilansBdfAdapter.new(etablissement.siret, procedure_id).to_params + etablissement_params = APIEntreprise::BilansBdfAdapter.new(etablissement.siret, procedure_id).to_params etablissement.update!(etablissement_params) end end diff --git a/app/jobs/api_entreprise/effectifs_annuels_job.rb b/app/jobs/api_entreprise/effectifs_annuels_job.rb index 9bc5e9c62..ebdf7a3a9 100644 --- a/app/jobs/api_entreprise/effectifs_annuels_job.rb +++ b/app/jobs/api_entreprise/effectifs_annuels_job.rb @@ -1,7 +1,7 @@ -class ApiEntreprise::EffectifsAnnuelsJob < ApiEntreprise::Job +class APIEntreprise::EffectifsAnnuelsJob < APIEntreprise::Job def perform(etablissement_id, procedure_id) find_etablissement(etablissement_id) - etablissement_params = ApiEntreprise::EffectifsAnnuelsAdapter.new(etablissement.siret, procedure_id).to_params + etablissement_params = APIEntreprise::EffectifsAnnuelsAdapter.new(etablissement.siret, procedure_id).to_params etablissement.update!(etablissement_params) end end diff --git a/app/jobs/api_entreprise/effectifs_job.rb b/app/jobs/api_entreprise/effectifs_job.rb index 5acf8c55f..feb21e10a 100644 --- a/app/jobs/api_entreprise/effectifs_job.rb +++ b/app/jobs/api_entreprise/effectifs_job.rb @@ -1,8 +1,8 @@ -class ApiEntreprise::EffectifsJob < ApiEntreprise::Job +class APIEntreprise::EffectifsJob < APIEntreprise::Job def perform(etablissement_id, procedure_id) find_etablissement(etablissement_id) # may 2020 is at the moment the most actual info for effectifs endpoint - etablissement_params = ApiEntreprise::EffectifsAdapter.new(etablissement.siret, procedure_id, "2020", "05").to_params + etablissement_params = APIEntreprise::EffectifsAdapter.new(etablissement.siret, procedure_id, "2020", "05").to_params etablissement.update!(etablissement_params) end diff --git a/app/jobs/api_entreprise/entreprise_job.rb b/app/jobs/api_entreprise/entreprise_job.rb index b6317fd32..35c0af070 100644 --- a/app/jobs/api_entreprise/entreprise_job.rb +++ b/app/jobs/api_entreprise/entreprise_job.rb @@ -1,7 +1,7 @@ -class ApiEntreprise::EntrepriseJob < ApiEntreprise::Job +class APIEntreprise::EntrepriseJob < APIEntreprise::Job def perform(etablissement_id, procedure_id) find_etablissement(etablissement_id) - etablissement_params = ApiEntreprise::EntrepriseAdapter.new(etablissement.siret, procedure_id).to_params + etablissement_params = APIEntreprise::EntrepriseAdapter.new(etablissement.siret, procedure_id).to_params etablissement.update!(etablissement_params) end end diff --git a/app/jobs/api_entreprise/exercices_job.rb b/app/jobs/api_entreprise/exercices_job.rb index ba5b27e29..de0759a09 100644 --- a/app/jobs/api_entreprise/exercices_job.rb +++ b/app/jobs/api_entreprise/exercices_job.rb @@ -1,10 +1,10 @@ -class ApiEntreprise::ExercicesJob < ApiEntreprise::Job - rescue_from(ApiEntreprise::API::Error::BadFormatRequest) do |exception| +class APIEntreprise::ExercicesJob < APIEntreprise::Job + rescue_from(APIEntreprise::API::Error::BadFormatRequest) do |exception| end def perform(etablissement_id, procedure_id) find_etablissement(etablissement_id) - etablissement_params = ApiEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params + etablissement_params = APIEntreprise::ExercicesAdapter.new(etablissement.siret, procedure_id).to_params etablissement.update!(etablissement_params) end end diff --git a/app/jobs/api_entreprise/job.rb b/app/jobs/api_entreprise/job.rb index e7db45d29..f62a31d69 100644 --- a/app/jobs/api_entreprise/job.rb +++ b/app/jobs/api_entreprise/job.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::Job < ApplicationJob +class APIEntreprise::Job < ApplicationJob DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5 queue_as :api_entreprise @@ -8,27 +8,27 @@ class ApiEntreprise::Job < ApplicationJob # - bdf: erreur interne # so we retry every day for 5 days # same logic for ServiceUnavailable - rescue_from(ApiEntreprise::API::Error::ServiceUnavailable) do |exception| + rescue_from(APIEntreprise::API::Error::ServiceUnavailable) do |exception| retry_or_discard(exception) end - rescue_from(ApiEntreprise::API::Error::BadGateway) do |exception| + rescue_from(APIEntreprise::API::Error::BadGateway) do |exception| retry_or_discard(exception) end # We guess the backend is slow but not broken # and the information we are looking for is available # so we retry few seconds later (exponentially to avoid overload) - retry_on ApiEntreprise::API::Error::TimedOut, wait: :exponentially_longer + retry_on APIEntreprise::API::Error::TimedOut, wait: :exponentially_longer # If by the time the job runs the Etablissement has been deleted # (it can happen through EtablissementUpdateJob for instance), ignore the job discard_on ActiveRecord::RecordNotFound - rescue_from(ApiEntreprise::API::Error::ResourceNotFound) do |exception| + rescue_from(APIEntreprise::API::Error::ResourceNotFound) do |exception| error(self, exception) end - rescue_from(ApiEntreprise::API::Error::BadFormatRequest) do |exception| + rescue_from(APIEntreprise::API::Error::BadFormatRequest) do |exception| error(self, exception) end diff --git a/app/jobs/cron/fix_missing_antivirus_analysis_job.rb b/app/jobs/cron/fix_missing_antivirus_analysis_job.rb index a9d097cfd..b12a0445c 100644 --- a/app/jobs/cron/fix_missing_antivirus_analysis_job.rb +++ b/app/jobs/cron/fix_missing_antivirus_analysis_job.rb @@ -1,4 +1,4 @@ -class Cron::FixMissingAntivirusAnalysis < Cron::CronJob +class Cron::FixMissingAntivirusAnalysisJob < Cron::CronJob self.schedule_expression = "every day at 2 am" def perform diff --git a/app/jobs/etablissement_update_job.rb b/app/jobs/etablissement_update_job.rb index 578bf3cb4..e8eb2b12b 100644 --- a/app/jobs/etablissement_update_job.rb +++ b/app/jobs/etablissement_update_job.rb @@ -1,7 +1,7 @@ class EtablissementUpdateJob < ApplicationJob def perform(dossier, siret) begin - etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, dossier.procedure.id) + etablissement_attributes = APIEntrepriseService.get_etablissement_params_for_siret(siret, dossier.procedure.id) rescue return end diff --git a/app/lib/api_carto/api.rb b/app/lib/api_carto/api.rb index 92730c654..7cf076dd6 100644 --- a/app/lib/api_carto/api.rb +++ b/app/lib/api_carto/api.rb @@ -1,4 +1,4 @@ -class ApiCarto::API +class APICarto::API class ResourceNotFound < StandardError end @@ -16,7 +16,7 @@ class ApiCarto::API response.body else message = response.code == 0 ? response.return_message : response.code.to_s - Rails.logger.error "[ApiCarto] Error on #{url}: #{message}" + Rails.logger.error "[APICarto] Error on #{url}: #{message}" raise ResourceNotFound end end diff --git a/app/lib/api_carto/cadastre_adapter.rb b/app/lib/api_carto/cadastre_adapter.rb index a1d396502..65c939def 100644 --- a/app/lib/api_carto/cadastre_adapter.rb +++ b/app/lib/api_carto/cadastre_adapter.rb @@ -1,10 +1,10 @@ -class ApiCarto::CadastreAdapter +class APICarto::CadastreAdapter def initialize(coordinates) @coordinates = GeojsonService.to_json_polygon_for_cadastre(coordinates) end def data_source - @data_source ||= JSON.parse(ApiCarto::API.search_cadastre(@coordinates), symbolize_names: true) + @data_source ||= JSON.parse(APICarto::API.search_cadastre(@coordinates), symbolize_names: true) end def results diff --git a/app/lib/api_education/annuaire_education_adapter.rb b/app/lib/api_education/annuaire_education_adapter.rb index 151120ec1..161317d69 100644 --- a/app/lib/api_education/annuaire_education_adapter.rb +++ b/app/lib/api_education/annuaire_education_adapter.rb @@ -1,6 +1,6 @@ require 'json_schemer' -class ApiEducation::AnnuaireEducationAdapter +class APIEducation::AnnuaireEducationAdapter class InvalidSchemaError < ::StandardError def initialize(errors) super(errors.map(&:to_json).join("\n")) @@ -27,7 +27,7 @@ class ApiEducation::AnnuaireEducationAdapter private def data_source - @data_source ||= JSON.parse(ApiEducation::API.get_annuaire_education(@id), symbolize_names: true) + @data_source ||= JSON.parse(APIEducation::API.get_annuaire_education(@id), symbolize_names: true) end def schemer diff --git a/app/lib/api_education/api.rb b/app/lib/api_education/api.rb index 368096712..d0ee6bcae 100644 --- a/app/lib/api_education/api.rb +++ b/app/lib/api_education/api.rb @@ -1,4 +1,4 @@ -class ApiEducation::API +class APIEducation::API class ResourceNotFound < StandardError end @@ -15,7 +15,7 @@ class ApiEducation::API response.body else message = response.code == 0 ? response.return_message : response.code.to_s - Rails.logger.error "[ApiEducation] Error on #{url}: #{message}" + Rails.logger.error "[APIEducation] Error on #{url}: #{message}" raise ResourceNotFound end end diff --git a/app/lib/api_entreprise/adapter.rb b/app/lib/api_entreprise/adapter.rb index efa731096..84655a9b2 100644 --- a/app/lib/api_entreprise/adapter.rb +++ b/app/lib/api_entreprise/adapter.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::Adapter +class APIEntreprise::Adapter UNAVAILABLE = 'Donnée indisponible' def initialize(siret, procedure_id) @@ -9,7 +9,7 @@ class ApiEntreprise::Adapter def data_source begin @data_source ||= get_resource - rescue ApiEntreprise::API::Error::ResourceNotFound + rescue APIEntreprise::API::Error::ResourceNotFound @data_source = nil end end diff --git a/app/lib/api_entreprise/api.rb b/app/lib/api_entreprise/api.rb index f1db82607..f5a57fa20 100644 --- a/app/lib/api_entreprise/api.rb +++ b/app/lib/api_entreprise/api.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::API +class APIEntreprise::API ENTREPRISE_RESOURCE_NAME = "entreprises" ETABLISSEMENT_RESOURCE_NAME = "etablissements" EXERCICES_RESOURCE_NAME = "exercices" @@ -11,6 +11,7 @@ class ApiEntreprise::API PRIVILEGES_RESOURCE_NAME = "privileges" TIMEOUT = 20 + DEFAULT_API_ENTREPRISE_DELAY = 0.0 def self.entreprise(siren, procedure_id) call_with_siret(ENTREPRISE_RESOURCE_NAME, siren, procedure_id) @@ -60,6 +61,15 @@ class ApiEntreprise::API def self.call_with_token(resource_name, token) url = "#{API_ENTREPRISE_URL}/#{resource_name}" + + # this is a poor man throttling + # the idea is to queue api entreprise job on 1 worker + # and add a delay between each call + # example: API_ENTREPRISE_DELAY=1 => 60 rpm max + if api_entreprise_delay != 0.0 + sleep api_entreprise_delay + end + response = Typhoeus.get(url, headers: { Authorization: "Bearer #{token}" }, timeout: TIMEOUT) @@ -72,10 +82,14 @@ class ApiEntreprise::API end def self.call_with_siret(resource_name, siret_or_siren, procedure_id, user_id = nil) - return if ApiEntrepriseToken.new(token_for_procedure(procedure_id)).expired? + return if APIEntrepriseToken.new(token_for_procedure(procedure_id)).expired? url = url(resource_name, siret_or_siren) params = params(siret_or_siren, procedure_id, user_id) + if api_entreprise_delay != 0.0 + sleep api_entreprise_delay + end + response = Typhoeus.get(url, headers: { Authorization: "Bearer #{token_for_procedure(procedure_id)}" }, params: params, @@ -125,4 +139,8 @@ class ApiEntreprise::API procedure = Procedure.find(procedure_id) procedure.api_entreprise_token end + + def self.api_entreprise_delay + ENV.fetch("API_ENTREPRISE_DELAY", DEFAULT_API_ENTREPRISE_DELAY).to_f + end end diff --git a/app/lib/api_entreprise/api/error.rb b/app/lib/api_entreprise/api/error.rb index 6719ba7f1..f0aa3de7d 100644 --- a/app/lib/api_entreprise/api/error.rb +++ b/app/lib/api_entreprise/api/error.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::API::Error < ::StandardError +class APIEntreprise::API::Error < ::StandardError def initialize(response) # use uri to avoid sending token uri = URI.parse(response.effective_url) diff --git a/app/lib/api_entreprise/api/error/bad_format_request.rb b/app/lib/api_entreprise/api/error/bad_format_request.rb index c5a1210eb..52cf8e517 100644 --- a/app/lib/api_entreprise/api/error/bad_format_request.rb +++ b/app/lib/api_entreprise/api/error/bad_format_request.rb @@ -1,4 +1,2 @@ -class ApiEntreprise::API::Error - class BadFormatRequest < ApiEntreprise::API::Error - end +class APIEntreprise::API::Error::BadFormatRequest < APIEntreprise::API::Error end diff --git a/app/lib/api_entreprise/api/error/bad_gateway.rb b/app/lib/api_entreprise/api/error/bad_gateway.rb index dd2a7065b..0943c2635 100644 --- a/app/lib/api_entreprise/api/error/bad_gateway.rb +++ b/app/lib/api_entreprise/api/error/bad_gateway.rb @@ -1,4 +1,2 @@ -class ApiEntreprise::API::Error - class BadGateway < ApiEntreprise::API::Error - end +class APIEntreprise::API::Error::BadGateway < APIEntreprise::API::Error end diff --git a/app/lib/api_entreprise/api/error/request_failed.rb b/app/lib/api_entreprise/api/error/request_failed.rb index e4680c631..e99ca8b44 100644 --- a/app/lib/api_entreprise/api/error/request_failed.rb +++ b/app/lib/api_entreprise/api/error/request_failed.rb @@ -1,4 +1,2 @@ -class ApiEntreprise::API::Error - class RequestFailed < ApiEntreprise::API::Error - end +class APIEntreprise::API::Error::RequestFailed < APIEntreprise::API::Error end diff --git a/app/lib/api_entreprise/api/error/resource_not_found.rb b/app/lib/api_entreprise/api/error/resource_not_found.rb index 27b9fd053..4fc38f86e 100644 --- a/app/lib/api_entreprise/api/error/resource_not_found.rb +++ b/app/lib/api_entreprise/api/error/resource_not_found.rb @@ -1,4 +1,2 @@ -class ApiEntreprise::API::Error - class ResourceNotFound < ApiEntreprise::API::Error - end +class APIEntreprise::API::Error::ResourceNotFound < APIEntreprise::API::Error end diff --git a/app/lib/api_entreprise/api/error/service_unavailable.rb b/app/lib/api_entreprise/api/error/service_unavailable.rb index 684574ed4..51cdf5254 100644 --- a/app/lib/api_entreprise/api/error/service_unavailable.rb +++ b/app/lib/api_entreprise/api/error/service_unavailable.rb @@ -1,4 +1,2 @@ -class ApiEntreprise::API::Error - class ServiceUnavailable < ApiEntreprise::API::Error - end +class APIEntreprise::API::Error::ServiceUnavailable < APIEntreprise::API::Error end diff --git a/app/lib/api_entreprise/api/error/timed_out.rb b/app/lib/api_entreprise/api/error/timed_out.rb index 7921afcf2..7e4b27590 100644 --- a/app/lib/api_entreprise/api/error/timed_out.rb +++ b/app/lib/api_entreprise/api/error/timed_out.rb @@ -1,4 +1,2 @@ -class ApiEntreprise::API::Error - class TimedOut < ApiEntreprise::API::Error - end +class APIEntreprise::API::Error::TimedOut < APIEntreprise::API::Error end diff --git a/app/lib/api_entreprise/attestation_fiscale_adapter.rb b/app/lib/api_entreprise/attestation_fiscale_adapter.rb index f1e0adf39..e776dc48d 100644 --- a/app/lib/api_entreprise/attestation_fiscale_adapter.rb +++ b/app/lib/api_entreprise/attestation_fiscale_adapter.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::AttestationFiscaleAdapter < ApiEntreprise::Adapter +class APIEntreprise::AttestationFiscaleAdapter < APIEntreprise::Adapter def initialize(siret, procedure_id, user_id) @siret = siret @procedure_id = procedure_id @@ -8,7 +8,7 @@ class ApiEntreprise::AttestationFiscaleAdapter < ApiEntreprise::Adapter private def get_resource - ApiEntreprise::API.attestation_fiscale(siren, @procedure_id, @user_id) + APIEntreprise::API.attestation_fiscale(siren, @procedure_id, @user_id) end def process_params diff --git a/app/lib/api_entreprise/attestation_sociale_adapter.rb b/app/lib/api_entreprise/attestation_sociale_adapter.rb index d43b19452..551b042b2 100644 --- a/app/lib/api_entreprise/attestation_sociale_adapter.rb +++ b/app/lib/api_entreprise/attestation_sociale_adapter.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::AttestationSocialeAdapter < ApiEntreprise::Adapter +class APIEntreprise::AttestationSocialeAdapter < APIEntreprise::Adapter def initialize(siret, procedure_id) @siret = siret @procedure_id = procedure_id @@ -7,7 +7,7 @@ class ApiEntreprise::AttestationSocialeAdapter < ApiEntreprise::Adapter private def get_resource - ApiEntreprise::API.attestation_sociale(siren, @procedure_id) + APIEntreprise::API.attestation_sociale(siren, @procedure_id) end def process_params diff --git a/app/lib/api_entreprise/bilans_bdf_adapter.rb b/app/lib/api_entreprise/bilans_bdf_adapter.rb index 02066545b..7e8de8932 100644 --- a/app/lib/api_entreprise/bilans_bdf_adapter.rb +++ b/app/lib/api_entreprise/bilans_bdf_adapter.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::BilansBdfAdapter < ApiEntreprise::Adapter +class APIEntreprise::BilansBdfAdapter < APIEntreprise::Adapter def initialize(siret, procedure_id) @siret = siret @procedure_id = procedure_id @@ -7,7 +7,7 @@ class ApiEntreprise::BilansBdfAdapter < ApiEntreprise::Adapter private def get_resource - ApiEntreprise::API.bilans_bdf(siren, @procedure_id) + APIEntreprise::API.bilans_bdf(siren, @procedure_id) end def process_params diff --git a/app/lib/api_entreprise/effectifs_adapter.rb b/app/lib/api_entreprise/effectifs_adapter.rb index d53cf63c7..55c31e853 100644 --- a/app/lib/api_entreprise/effectifs_adapter.rb +++ b/app/lib/api_entreprise/effectifs_adapter.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter +class APIEntreprise::EffectifsAdapter < APIEntreprise::Adapter def initialize(siret, procedure_id, annee, mois) @siret = siret @procedure_id = procedure_id @@ -9,7 +9,7 @@ class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter private def get_resource - ApiEntreprise::API.effectifs(siren, @procedure_id, @annee, @mois) + APIEntreprise::API.effectifs(siren, @procedure_id, @annee, @mois) end def process_params diff --git a/app/lib/api_entreprise/effectifs_annuels_adapter.rb b/app/lib/api_entreprise/effectifs_annuels_adapter.rb index cfc679cd6..0dba6ae4b 100644 --- a/app/lib/api_entreprise/effectifs_annuels_adapter.rb +++ b/app/lib/api_entreprise/effectifs_annuels_adapter.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::EffectifsAnnuelsAdapter < ApiEntreprise::Adapter +class APIEntreprise::EffectifsAnnuelsAdapter < APIEntreprise::Adapter def initialize(siret, procedure_id) @siret = siret @procedure_id = procedure_id @@ -7,7 +7,7 @@ class ApiEntreprise::EffectifsAnnuelsAdapter < ApiEntreprise::Adapter private def get_resource - ApiEntreprise::API.effectifs_annuels(siren, @procedure_id) + APIEntreprise::API.effectifs_annuels(siren, @procedure_id) end def process_params diff --git a/app/lib/api_entreprise/entreprise_adapter.rb b/app/lib/api_entreprise/entreprise_adapter.rb index d15f4d29e..8586caa50 100644 --- a/app/lib/api_entreprise/entreprise_adapter.rb +++ b/app/lib/api_entreprise/entreprise_adapter.rb @@ -1,8 +1,8 @@ -class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter +class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter private def get_resource - ApiEntreprise::API.entreprise(siren, @procedure_id) + APIEntreprise::API.entreprise(siren, @procedure_id) end def process_params diff --git a/app/lib/api_entreprise/etablissement_adapter.rb b/app/lib/api_entreprise/etablissement_adapter.rb index 05436c1c0..eb8312d59 100644 --- a/app/lib/api_entreprise/etablissement_adapter.rb +++ b/app/lib/api_entreprise/etablissement_adapter.rb @@ -1,8 +1,8 @@ -class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter +class APIEntreprise::EtablissementAdapter < APIEntreprise::Adapter private def get_resource - ApiEntreprise::API.etablissement(@siret, @procedure_id) + APIEntreprise::API.etablissement(@siret, @procedure_id) end def process_params diff --git a/app/lib/api_entreprise/exercices_adapter.rb b/app/lib/api_entreprise/exercices_adapter.rb index 0563f629a..dc2cbd45f 100644 --- a/app/lib/api_entreprise/exercices_adapter.rb +++ b/app/lib/api_entreprise/exercices_adapter.rb @@ -1,8 +1,8 @@ -class ApiEntreprise::ExercicesAdapter < ApiEntreprise::Adapter +class APIEntreprise::ExercicesAdapter < APIEntreprise::Adapter private def get_resource - ApiEntreprise::API.exercices(@siret, @procedure_id) + APIEntreprise::API.exercices(@siret, @procedure_id) end def process_params diff --git a/app/lib/api_entreprise/privileges_adapter.rb b/app/lib/api_entreprise/privileges_adapter.rb index 8064d5962..745102b9d 100644 --- a/app/lib/api_entreprise/privileges_adapter.rb +++ b/app/lib/api_entreprise/privileges_adapter.rb @@ -1,4 +1,4 @@ -class ApiEntreprise::PrivilegesAdapter < ApiEntreprise::Adapter +class APIEntreprise::PrivilegesAdapter < APIEntreprise::Adapter def initialize(token) @token = token end @@ -15,6 +15,6 @@ class ApiEntreprise::PrivilegesAdapter < ApiEntreprise::Adapter private def get_resource - ApiEntreprise::API.privileges(@token) + APIEntreprise::API.privileges(@token) end end diff --git a/app/lib/api_entreprise/rna_adapter.rb b/app/lib/api_entreprise/rna_adapter.rb index 042b952ca..a616cb19a 100644 --- a/app/lib/api_entreprise/rna_adapter.rb +++ b/app/lib/api_entreprise/rna_adapter.rb @@ -1,8 +1,8 @@ -class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter +class APIEntreprise::RNAAdapter < APIEntreprise::Adapter private def get_resource - ApiEntreprise::API.rna(@siret, @procedure_id) + APIEntreprise::API.rna(@siret, @procedure_id) end def process_params diff --git a/app/lib/sendinblue/api.rb b/app/lib/sendinblue/api.rb index 89d9a821f..7cfe78ae9 100644 --- a/app/lib/sendinblue/api.rb +++ b/app/lib/sendinblue/api.rb @@ -1,4 +1,4 @@ -class Sendinblue::Api +class Sendinblue::API def self.new_properly_configured! api = self.new if !api.properly_configured? diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb index 1d340c32b..285802797 100644 --- a/app/mailers/dossier_mailer.rb +++ b/app/mailers/dossier_mailer.rb @@ -150,7 +150,7 @@ class DossierMailer < ApplicationMailer if interpolations[:state] mailer_scope = self.class.mailer_name.tr('/', '.') state = interpolations[:state].in?(Dossier::TERMINE) ? 'termine' : interpolations[:state] - I18n.t("subject_#{state}", interpolations.merge(scope: [mailer_scope, action_name])) + I18n.t("subject_#{state}", **interpolations.merge(scope: [mailer_scope, action_name])) else super end diff --git a/app/models/api_entreprise_token.rb b/app/models/api_entreprise_token.rb index 4398c1d0b..ff0dbf49e 100644 --- a/app/models/api_entreprise_token.rb +++ b/app/models/api_entreprise_token.rb @@ -1,4 +1,4 @@ -class ApiEntrepriseToken +class APIEntrepriseToken attr_reader :token def initialize(token) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index a763570c1..59ea1f07a 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -227,8 +227,8 @@ class Dossier < ApplicationRecord user: []) } - scope :with_notifiable_procedure, -> (notify_on_closed: false) do - states = notify_on_closed ? [:publiee, :close, :depubliee] : [:publiee, :depubliee] + scope :with_notifiable_procedure, -> (opts = { notify_on_closed: false }) do + states = opts[:notify_on_closed] ? [:publiee, :close, :depubliee] : [:publiee, :depubliee] joins(:procedure) .where(procedures: { aasm_state: states }) end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index d48f06111..a2912b7b6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -625,7 +625,7 @@ class Procedure < ApplicationRecord end def api_entreprise_role?(role) - ApiEntrepriseToken.new(api_entreprise_token).role?(role) + APIEntrepriseToken.new(api_entreprise_token).role?(role) end def api_entreprise_token @@ -633,7 +633,7 @@ class Procedure < ApplicationRecord end def api_entreprise_token_expired? - ApiEntrepriseToken.new(api_entreprise_token).expired? + APIEntrepriseToken.new(api_entreprise_token).expired? end def create_new_revision diff --git a/app/serializers/module_api_carto_serializer.rb b/app/serializers/module_api_carto_serializer.rb index b79abfba8..bbc19de16 100644 --- a/app/serializers/module_api_carto_serializer.rb +++ b/app/serializers/module_api_carto_serializer.rb @@ -1,3 +1,3 @@ -class ModuleApiCartoSerializer < ActiveModel::Serializer +class ModuleAPICartoSerializer < ActiveModel::Serializer attributes :use_api_carto, :cadastre end diff --git a/app/serializers/procedure_serializer.rb b/app/serializers/procedure_serializer.rb index ef0eb2b35..915dd0d23 100644 --- a/app/serializers/procedure_serializer.rb +++ b/app/serializers/procedure_serializer.rb @@ -13,7 +13,7 @@ class ProcedureSerializer < ActiveModel::Serializer :link, :state - has_one :geographic_information, serializer: ModuleApiCartoSerializer + has_one :geographic_information, serializer: ModuleAPICartoSerializer has_many :types_de_champ, serializer: TypeDeChampSerializer has_many :types_de_champ_private, serializer: TypeDeChampSerializer has_many :types_de_piece_justificative diff --git a/app/services/administrateur_usage_statistics_service.rb b/app/services/administrateur_usage_statistics_service.rb index 1623b34c5..d00de6cb0 100644 --- a/app/services/administrateur_usage_statistics_service.rb +++ b/app/services/administrateur_usage_statistics_service.rb @@ -18,7 +18,7 @@ class AdministrateurUsageStatisticsService private def api - @api ||= Sendinblue::Api.new_properly_configured! + @api ||= Sendinblue::API.new_properly_configured! end def administrateur_stats(administrateur) diff --git a/app/services/api_carto_service.rb b/app/services/api_carto_service.rb index ec0f64dfe..9c9379beb 100644 --- a/app/services/api_carto_service.rb +++ b/app/services/api_carto_service.rb @@ -1,7 +1,7 @@ -class ApiCartoService +class APICartoService def self.generate_qp(coordinates) coordinates.flat_map do |coordinate| - ApiCarto::QuartiersPrioritairesAdapter.new( + APICarto::QuartiersPrioritairesAdapter.new( coordinate.map { |element| [element['lng'], element['lat']] } ).results end @@ -9,7 +9,7 @@ class ApiCartoService def self.generate_cadastre(coordinates) coordinates.flat_map do |coordinate| - ApiCarto::CadastreAdapter.new( + APICarto::CadastreAdapter.new( coordinate.map { |element| [element['lng'], element['lat']] } ).results end diff --git a/app/services/api_entreprise_service.rb b/app/services/api_entreprise_service.rb index 5fdc7f205..bc27431d1 100644 --- a/app/services/api_entreprise_service.rb +++ b/app/services/api_entreprise_service.rb @@ -1,27 +1,27 @@ -class ApiEntrepriseService +class APIEntrepriseService # create etablissement with EtablissementAdapter # enqueue api_entreprise jobs to retrieve # all informations we can get about a SIRET. # # Returns nil if the SIRET is unknown # - # Raises a ApiEntreprise::API::Error::RequestFailed exception on transient errors + # Raises a APIEntreprise::API::Error::RequestFailed exception on transient errors # (timeout, 5XX HTTP error code, etc.) def self.create_etablissement(dossier_or_champ, siret, user_id = nil) - etablissement_params = ApiEntreprise::EtablissementAdapter.new(siret, dossier_or_champ.procedure.id).to_params + etablissement_params = APIEntreprise::EtablissementAdapter.new(siret, dossier_or_champ.procedure.id).to_params return nil if etablissement_params.empty? etablissement = dossier_or_champ.build_etablissement(etablissement_params) etablissement.save! [ - ApiEntreprise::EntrepriseJob, ApiEntreprise::AssociationJob, ApiEntreprise::ExercicesJob, - ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob, - ApiEntreprise::BilansBdfJob + APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob, + APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob, + APIEntreprise::BilansBdfJob ].each do |job| job.perform_later(etablissement.id, dossier_or_champ.procedure.id) end - ApiEntreprise::AttestationFiscaleJob.perform_later(etablissement.id, dossier_or_champ.procedure.id, user_id) + APIEntreprise::AttestationFiscaleJob.perform_later(etablissement.id, dossier_or_champ.procedure.id, user_id) etablissement end diff --git a/app/views/layouts/mailers/layout.html.erb b/app/views/layouts/mailers/layout.html.erb index 564a96ee3..6175243c6 100644 --- a/app/views/layouts/mailers/layout.html.erb +++ b/app/views/layouts/mailers/layout.html.erb @@ -167,7 +167,7 @@
- Logo Beta Gouv Fr + Logo <%= " src="<%= image_url("#{MAILER_FOOTER_LOGO_SRC}") %>" style="max-width=125px; padding=30px 0; display=inline !important; vertical-align=bottom; border=0; height=auto; outline=none; text-decoration=none; -ms-interpolation-mode=bicubic;" />
diff --git a/config/env.example.optional b/config/env.example.optional index e41c6a190..2a4a6c636 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -50,6 +50,9 @@ APPLICATION_BASE_URL="https://www.demarches-simplifiees.fr" # Personnalisation d'instance - Logo dans l'entête des emails ---> à placer dans "app/assets/images" # MAILER_LOGO_SRC="mailer/instructeur_mailer/logo.png" +# Personnalisation d'instance - Logo dans le pied de page des emails ---> à placer dans "app/assets/images" +# MAILER_FOOTER_LOGO_SRC="mailer/instructeur_mailer/logo-beta-gouv-fr.png" + # Personnalisation d'instance - Logo par défaut d'une procédure ---> à placer dans "app/assets/images" # PROCEDURE_DEFAULT_LOGO_SRC="republique-francaise-logo.svg" diff --git a/config/initializers/active_job_compatibility.rb b/config/initializers/active_job_compatibility.rb new file mode 100644 index 000000000..054ae18c9 --- /dev/null +++ b/config/initializers/active_job_compatibility.rb @@ -0,0 +1,30 @@ +# The following jobs were renamed, but instances using the old name +# were still scheduled to run on the job queue. +# +# To ensure the job queue can instantiate these jobs using the previous +# names, this file defines retro-compatibility aliases. +# +# Once all jobs running using the previous name will have run, this +# file can be safely deleted. +# +# (That probably means a few hours after deploying the rename in production +# - but let's keep these for a while to make external integrators's life easier. +# To keep some margin, let's say this file can be safely deleted in May 2021.) + +require 'excon' + +module ApiEntreprise + Job = APIEntreprise::Job + AssociationJob = APIEntreprise::AssociationJob + AttestationFiscaleJob = APIEntreprise::AttestationFiscaleJob + AttestationSocialeJob = APIEntreprise::AttestationSocialeJob + BilansBdfJob = APIEntreprise::BilansBdfJob + EffectifsAnnuelsJob = APIEntreprise::EffectifsAnnuelsJob + EffectifsJob = APIEntreprise::EffectifsJob + EntrepriseJob = APIEntreprise::EntrepriseJob + ExercicesJob = APIEntreprise::ExercicesJob +end + +module Cron + FixMissingAntivirusAnalysis = FixMissingAntivirusAnalysisJob +end diff --git a/config/initializers/images.rb b/config/initializers/images.rb index 462dedd33..c488aa279 100644 --- a/config/initializers/images.rb +++ b/config/initializers/images.rb @@ -9,8 +9,9 @@ HEADER_LOGO_ALT = ENV.fetch("HEADER_LOGO_ALT", "Liberté, égalité, fraternité HEADER_LOGO_WIDTH = ENV.fetch("HEADER_LOGO_WIDTH", "65") HEADER_LOGO_HEIGHT = ENV.fetch("HEADER_LOGO_HEIGHT", "56") -# Mailer logo +# Mailer logos MAILER_LOGO_SRC = ENV.fetch("MAILER_LOGO_SRC", "mailer/instructeur_mailer/logo.png") +MAILER_FOOTER_LOGO_SRC = ENV.fetch("MAILER_FOOTER_LOGO_SRC", "mailer/instructeur_mailer/logo-beta-gouv-fr.png") # Default logo of a procedure PROCEDURE_DEFAULT_LOGO_SRC = ENV.fetch("PROCEDURE_DEFAULT_LOGO_SRC", "republique-francaise-logo.svg") diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 69ce9269b..ab95accd8 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -9,7 +9,11 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) inflect.acronym 'API' + inflect.acronym 'ASN1' + inflect.acronym 'IP' + inflect.acronym 'JSON' inflect.acronym 'RNA' + inflect.acronym 'URL' inflect.irregular 'type_de_champ', 'types_de_champ' inflect.irregular 'type_de_champ_private', 'types_de_champ_private' inflect.irregular 'procedure_revision_type_de_champ', 'procedure_revision_types_de_champ' diff --git a/lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake b/lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake index e7093ca81..e8e011970 100644 --- a/lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake +++ b/lib/tasks/deployment/20200527124112_fix_champ_etablissement.rake @@ -24,12 +24,12 @@ namespace :after_party do def fetch_api_entreprise_infos(etablissement_id, procedure_id, user_id) [ - ApiEntreprise::EntrepriseJob, ApiEntreprise::AssociationJob, ApiEntreprise::ExercicesJob, - ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob, - ApiEntreprise::BilansBdfJob + APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob, + APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob, + APIEntreprise::BilansBdfJob ].each do |job| job.perform_later(etablissement_id, procedure_id) end - ApiEntreprise::AttestationFiscaleJob.perform_later(etablissement_id, procedure_id, user_id) + APIEntreprise::AttestationFiscaleJob.perform_later(etablissement_id, procedure_id, user_id) end end diff --git a/lib/tasks/graphql.rake b/lib/tasks/graphql.rake index a029b14b8..9eb82da77 100644 --- a/lib/tasks/graphql.rake +++ b/lib/tasks/graphql.rake @@ -1,2 +1,2 @@ require "graphql/rake_task" -GraphQL::RakeTask.new(schema_name: "Api::V2::Schema", directory: 'app/graphql') +GraphQL::RakeTask.new(schema_name: "API::V2::Schema", directory: 'app/graphql') diff --git a/spec/controllers/champs/siret_controller_spec.rb b/spec/controllers/champs/siret_controller_spec.rb index 4e565dc8b..be79a10dd 100644 --- a/spec/controllers/champs/siret_controller_spec.rb +++ b/spec/controllers/champs/siret_controller_spec.rb @@ -32,9 +32,9 @@ describe Champs::SiretController, type: :controller do sign_in user stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/) .to_return(status: api_etablissement_status, body: api_etablissement_body) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles) .and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(token_expired) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(token_expired) end context 'when the SIRET is empty' do diff --git a/spec/controllers/new_administrateur/procedures_controller_spec.rb b/spec/controllers/new_administrateur/procedures_controller_spec.rb index de1efc074..e508faba7 100644 --- a/spec/controllers/new_administrateur/procedures_controller_spec.rb +++ b/spec/controllers/new_administrateur/procedures_controller_spec.rb @@ -338,7 +338,7 @@ describe NewAdministrateur::ProceduresController, type: :controller do subject { patch :update_jeton, params: { id: procedure.id, procedure: { api_entreprise_token: token } } } before do - allow_any_instance_of(ApiEntreprise::PrivilegesAdapter).to receive(:valid?).and_return(token_is_valid) + allow_any_instance_of(APIEntreprise::PrivilegesAdapter).to receive(:valid?).and_return(token_is_valid) subject end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index b7208be2d..5c81263f7 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -208,9 +208,9 @@ describe Users::DossiersController, type: :controller do sign_in(user) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/) .to_return(status: api_etablissement_status, body: api_etablissement_body) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles) .and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(token_expired) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(token_expired) end subject! { post :update_siret, params: { id: dossier.id, user: { siret: params_siret } } } diff --git a/spec/features/instructeurs/instruction_spec.rb b/spec/features/instructeurs/instruction_spec.rb index 573a562b8..fb0b5acd6 100644 --- a/spec/features/instructeurs/instruction_spec.rb +++ b/spec/features/instructeurs/instruction_spec.rb @@ -187,6 +187,7 @@ feature 'Instructing a dossier:' do expect(files[2].filename.include?('horodatage/operation')).to be_truthy end + before { DownloadHelpers.clear_downloads } after { DownloadHelpers.clear_downloads } end diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index 121619e24..99e075a0a 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -78,8 +78,8 @@ feature 'Creating a new dossier:' do .to_return(status: 404, body: '') stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/) .to_return(status: 404, body: '') - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return([]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return([]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end before { Timecop.freeze(Time.zone.local(2020, 3, 14)) } after { Timecop.return } diff --git a/spec/jobs/api_entreprise/association_job_spec.rb b/spec/jobs/api_entreprise/association_job_spec.rb index 51c19e67e..e3ec76d7a 100644 --- a/spec/jobs/api_entreprise/association_job_spec.rb +++ b/spec/jobs/api_entreprise/association_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ApiEntreprise::AssociationJob, type: :job do +RSpec.describe APIEntreprise::AssociationJob, type: :job do let(:siret) { '50480511000013' } let(:etablissement) { create(:etablissement, siret: siret) } let(:procedure) { create(:procedure) } @@ -9,10 +9,10 @@ RSpec.describe ApiEntreprise::AssociationJob, type: :job do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end - subject { ApiEntreprise::AssociationJob.new.perform(etablissement.id, procedure_id) } + subject { APIEntreprise::AssociationJob.new.perform(etablissement.id, procedure_id) } it 'updates etablissement' do subject diff --git a/spec/jobs/api_entreprise/attestation_fiscale_job_spec.rb b/spec/jobs/api_entreprise/attestation_fiscale_job_spec.rb index 7030c04bf..2923b55c0 100644 --- a/spec/jobs/api_entreprise/attestation_fiscale_job_spec.rb +++ b/spec/jobs/api_entreprise/attestation_fiscale_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ApiEntreprise::AttestationFiscaleJob, type: :job do +RSpec.describe APIEntreprise::AttestationFiscaleJob, type: :job do let(:etablissement) { create(:etablissement, siret: siret) } let(:siret) { '41816609600069' } let(:siren) { '418166096' } @@ -12,11 +12,11 @@ RSpec.describe ApiEntreprise::AttestationFiscaleJob, type: :job do .to_return(body: body, status: status) stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf") .to_return(body: "body attestation", status: 200) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["attestations_fiscales"]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["attestations_fiscales"]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end - subject { ApiEntreprise::AttestationFiscaleJob.new.perform(etablissement.id, procedure.id, user_id) } + subject { APIEntreprise::AttestationFiscaleJob.new.perform(etablissement.id, procedure.id, user_id) } it 'updates etablissement' do subject diff --git a/spec/jobs/api_entreprise/attestation_sociale_job_spec.rb b/spec/jobs/api_entreprise/attestation_sociale_job_spec.rb index aa81231c3..c9927ba85 100644 --- a/spec/jobs/api_entreprise/attestation_sociale_job_spec.rb +++ b/spec/jobs/api_entreprise/attestation_sociale_job_spec.rb @@ -1,6 +1,6 @@ include ActiveJob::TestHelper -RSpec.describe ApiEntreprise::AttestationSocialeJob, type: :job do +RSpec.describe APIEntreprise::AttestationSocialeJob, type: :job do let(:etablissement) { create(:etablissement, siret: siret) } let(:siret) { '41816609600069' } let(:siren) { '418166096' } @@ -13,11 +13,11 @@ RSpec.describe ApiEntreprise::AttestationSocialeJob, type: :job do .to_return(body: body, status: status) stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156881-f749d75e2bfd443316e2e02d59015f-attestation_vigilance_acoss.pdf") .to_return(body: "body attestation", status: 200) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["attestations_sociales"]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["attestations_sociales"]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end - subject { ApiEntreprise::AttestationSocialeJob.new.perform(etablissement.id, procedure.id) } + subject { APIEntreprise::AttestationSocialeJob.new.perform(etablissement.id, procedure.id) } it 'updates etablissement' do subject diff --git a/spec/jobs/api_entreprise/bilans_bdf_job_spec.rb b/spec/jobs/api_entreprise/bilans_bdf_job_spec.rb index 08beafc54..a3b0f60a0 100644 --- a/spec/jobs/api_entreprise/bilans_bdf_job_spec.rb +++ b/spec/jobs/api_entreprise/bilans_bdf_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ApiEntreprise::BilansBdfJob, type: :job do +RSpec.describe APIEntreprise::BilansBdfJob, type: :job do let(:etablissement) { create(:etablissement, siret: siret) } let(:siret) { '41816609600069' } let(:siren) { '418166096' } @@ -11,11 +11,11 @@ RSpec.describe ApiEntreprise::BilansBdfJob, type: :job do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end - subject { ApiEntreprise::BilansBdfJob.new.perform(etablissement.id, procedure_id) } + subject { APIEntreprise::BilansBdfJob.new.perform(etablissement.id, procedure_id) } it 'updates etablissement' do subject diff --git a/spec/jobs/api_entreprise/effectifs_annuels_job_spec.rb b/spec/jobs/api_entreprise/effectifs_annuels_job_spec.rb index ea6f16d19..e4be65cb4 100644 --- a/spec/jobs/api_entreprise/effectifs_annuels_job_spec.rb +++ b/spec/jobs/api_entreprise/effectifs_annuels_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ApiEntreprise::EffectifsAnnuelsJob, type: :job do +RSpec.describe APIEntreprise::EffectifsAnnuelsJob, type: :job do let(:etablissement) { create(:etablissement, siret: siret) } let(:siret) { '41816609600069' } let(:siren) { '418166096' } @@ -10,10 +10,10 @@ RSpec.describe ApiEntreprise::EffectifsAnnuelsJob, type: :job do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end - subject { ApiEntreprise::EffectifsAnnuelsJob.new.perform(etablissement.id, procedure_id) } + subject { APIEntreprise::EffectifsAnnuelsJob.new.perform(etablissement.id, procedure_id) } it 'updates etablissement' do subject diff --git a/spec/jobs/api_entreprise/effectifs_job_spec.rb b/spec/jobs/api_entreprise/effectifs_job_spec.rb index 94fc7d051..f0f7e7d23 100644 --- a/spec/jobs/api_entreprise/effectifs_job_spec.rb +++ b/spec/jobs/api_entreprise/effectifs_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ApiEntreprise::EffectifsJob, type: :job do +RSpec.describe APIEntreprise::EffectifsJob, type: :job do let(:siret) { '41816609600069' } let(:siren) { '418166096' } let(:etablissement) { create(:etablissement, siret: siret) } @@ -13,13 +13,13 @@ RSpec.describe ApiEntreprise::EffectifsJob, type: :job do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end before { Timecop.freeze(now) } after { Timecop.return } - subject { ApiEntreprise::EffectifsJob.new.perform(etablissement.id, procedure_id) } + subject { APIEntreprise::EffectifsJob.new.perform(etablissement.id, procedure_id) } it 'updates etablissement' do subject diff --git a/spec/jobs/api_entreprise/entreprise_job_spec.rb b/spec/jobs/api_entreprise/entreprise_job_spec.rb index bd8298308..8ba5221d6 100644 --- a/spec/jobs/api_entreprise/entreprise_job_spec.rb +++ b/spec/jobs/api_entreprise/entreprise_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ApiEntreprise::EntrepriseJob, type: :job do +RSpec.describe APIEntreprise::EntrepriseJob, type: :job do let(:siret) { '41816609600051' } let(:siren) { '418166096' } let(:etablissement) { create(:etablissement, siret: siret) } @@ -10,10 +10,10 @@ RSpec.describe ApiEntreprise::EntrepriseJob, type: :job do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end - subject { ApiEntreprise::EntrepriseJob.new.perform(etablissement.id, procedure_id) } + subject { APIEntreprise::EntrepriseJob.new.perform(etablissement.id, procedure_id) } it 'updates etablissement' do subject diff --git a/spec/jobs/api_entreprise/exercices_job_spec.rb b/spec/jobs/api_entreprise/exercices_job_spec.rb index d94ce682f..1addbce62 100644 --- a/spec/jobs/api_entreprise/exercices_job_spec.rb +++ b/spec/jobs/api_entreprise/exercices_job_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe ApiEntreprise::ExercicesJob, type: :job do +RSpec.describe APIEntreprise::ExercicesJob, type: :job do let(:siret) { '41816609600051' } let(:procedure) { create(:procedure) } let(:etablissement) { create(:etablissement, siret: siret) } @@ -8,10 +8,10 @@ RSpec.describe ApiEntreprise::ExercicesJob, type: :job do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end - subject { ApiEntreprise::ExercicesJob.new.perform(etablissement.id, procedure.id) } + subject { APIEntreprise::ExercicesJob.new.perform(etablissement.id, procedure.id) } it 'updates etablissement' do subject diff --git a/spec/jobs/api_entreprise/job_spec.rb b/spec/jobs/api_entreprise/job_spec.rb index d71d7f126..db03ae134 100644 --- a/spec/jobs/api_entreprise/job_spec.rb +++ b/spec/jobs/api_entreprise/job_spec.rb @@ -1,6 +1,6 @@ include ActiveJob::TestHelper -RSpec.describe ApiEntreprise::Job, type: :job do +RSpec.describe APIEntreprise::Job, type: :job do # https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html # #method-i-retry_on describe '#perform' do @@ -19,7 +19,7 @@ RSpec.describe ApiEntreprise::Job, type: :job do it 'retries 5 times' do ensure_errors_force_n_retry(errors, 5) - expect(dossier.reload.api_entreprise_job_exceptions.first).to match('ApiEntreprise::API::Error::ServiceUnavailable') + expect(dossier.reload.api_entreprise_job_exceptions.first).to match('APIEntreprise::API::Error::ServiceUnavailable') end end @@ -34,7 +34,7 @@ RSpec.describe ApiEntreprise::Job, type: :job do end end - class ErrorJob < ApiEntreprise::Job + class ErrorJob < APIEntreprise::Job def perform(error, etablissement) @etablissement = etablissement @@ -50,11 +50,11 @@ RSpec.describe ApiEntreprise::Job, type: :job do case error when :service_unavaible - raise ApiEntreprise::API::Error::ServiceUnavailable.new(response) + raise APIEntreprise::API::Error::ServiceUnavailable.new(response) when :bad_gateway - raise ApiEntreprise::API::Error::BadGateway.new(response) + raise APIEntreprise::API::Error::BadGateway.new(response) when :timed_out - raise ApiEntreprise::API::Error::TimedOut.new(response) + raise APIEntreprise::API::Error::TimedOut.new(response) else raise StandardError end diff --git a/spec/lib/api_carto/api_spec.rb b/spec/lib/api_carto/api_spec.rb index 432a11b46..246cd5ce4 100644 --- a/spec/lib/api_carto/api_spec.rb +++ b/spec/lib/api_carto/api_spec.rb @@ -1,4 +1,4 @@ -describe ApiCarto::API do +describe APICarto::API do describe '.search_cadastre' do subject { described_class.search_cadastre(geojson) } @@ -13,8 +13,8 @@ describe ApiCarto::API do let(:status) { 404 } let(:body) { '' } - it 'raises ApiCarto::API::ResourceNotFound' do - expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound) + it 'raises APICarto::API::ResourceNotFound' do + expect { subject }.to raise_error(APICarto::API::ResourceNotFound) end end diff --git a/spec/lib/api_carto/cadastre_adapter_spec.rb b/spec/lib/api_carto/cadastre_adapter_spec.rb index 7d2d5860d..fcbb64fa4 100644 --- a/spec/lib/api_carto/cadastre_adapter_spec.rb +++ b/spec/lib/api_carto/cadastre_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiCarto::CadastreAdapter do +describe APICarto::CadastreAdapter do subject { described_class.new(coordinates).results } before do @@ -58,6 +58,6 @@ describe ApiCarto::CadastreAdapter do let(:status) { 404 } let(:body) { '' } - it { expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound) } + it { expect { subject }.to raise_error(APICarto::API::ResourceNotFound) } end end diff --git a/spec/lib/api_education/annuaire_education_adapter_spec.rb b/spec/lib/api_education/annuaire_education_adapter_spec.rb index a428c3d22..fe5fa5024 100644 --- a/spec/lib/api_education/annuaire_education_adapter_spec.rb +++ b/spec/lib/api_education/annuaire_education_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEducation::AnnuaireEducationAdapter do +describe APIEducation::AnnuaireEducationAdapter do let(:search_term) { '0050009H' } let(:adapter) { described_class.new(search_term) } subject { adapter.to_params } @@ -23,7 +23,7 @@ describe ApiEducation::AnnuaireEducationAdapter do let(:status) { 200 } it '#to_params raise exception' do - expect { subject }.to raise_exception(ApiEducation::AnnuaireEducationAdapter::InvalidSchemaError) + expect { subject }.to raise_exception(APIEducation::AnnuaireEducationAdapter::InvalidSchemaError) end end end diff --git a/spec/lib/api_entreprise/api_spec.rb b/spec/lib/api_entreprise/api_spec.rb index 745bdd452..bb6d6aff1 100644 --- a/spec/lib/api_entreprise/api_spec.rb +++ b/spec/lib/api_entreprise/api_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::API do +describe APIEntreprise::API do let(:procedure) { create(:procedure) } let(:procedure_id) { procedure.id } let(:token) { Rails.application.secrets.api_entreprise[:key] } @@ -9,7 +9,7 @@ describe ApiEntreprise::API do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/) .to_return(status: status, body: body) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context 'when the service throws a bad gateaway exception' do @@ -17,8 +17,8 @@ describe ApiEntreprise::API do let(:status) { 502 } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_unavailable.json') } - it 'raises ApiEntreprise::API::Error::RequestFailed' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::BadGateway) + it 'raises APIEntreprise::API::Error::RequestFailed' do + expect { subject }.to raise_error(APIEntreprise::API::Error::BadGateway) end end @@ -27,8 +27,8 @@ describe ApiEntreprise::API do let(:status) { 404 } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') } - it 'raises ApiEntreprise::API::Error::ResourceNotFound' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) + it 'raises APIEntreprise::API::Error::ResourceNotFound' do + expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound) end end @@ -37,8 +37,8 @@ describe ApiEntreprise::API do let(:status) { 400 } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') } - it 'raises ApiEntreprise::API::Error::BadFormatRequest' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::BadFormatRequest) + it 'raises APIEntreprise::API::Error::BadFormatRequest' do + expect { subject }.to raise_error(APIEntreprise::API::Error::BadFormatRequest) end end @@ -47,8 +47,8 @@ describe ApiEntreprise::API do let(:status) { 403 } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_private.json') } - it 'raises ApiEntreprise::API::Error::ResourceNotFound' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) + it 'raises APIEntreprise::API::Error::ResourceNotFound' do + expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound) end end @@ -89,7 +89,7 @@ describe ApiEntreprise::API do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*non_diffusables=true/) .to_return(status: status, body: body) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context 'when siret does not exist' do @@ -97,8 +97,8 @@ describe ApiEntreprise::API do let(:status) { 404 } let(:body) { '' } - it 'raises ApiEntreprise::API::Error::ResourceNotFound' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) + it 'raises APIEntreprise::API::Error::ResourceNotFound' do + expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound) end end @@ -117,7 +117,7 @@ describe ApiEntreprise::API do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//) .to_return(status: status, body: body) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context 'when siret does not exist' do @@ -127,8 +127,8 @@ describe ApiEntreprise::API do let(:status) { 404 } let(:body) { '' } - it 'raises ApiEntreprise::API::Error::ResourceNotFound' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) + it 'raises APIEntreprise::API::Error::ResourceNotFound' do + expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound) end end @@ -149,7 +149,7 @@ describe ApiEntreprise::API do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//) .to_return(status: status, body: body) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end subject { described_class.rna(siren, procedure_id) } @@ -159,8 +159,8 @@ describe ApiEntreprise::API do let(:status) { 404 } let(:body) { '' } - it 'raises ApiEntreprise::API::Error::ResourceNotFound' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) + it 'raises APIEntreprise::API::Error::ResourceNotFound' do + expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound) end end @@ -180,8 +180,8 @@ describe ApiEntreprise::API do let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_sociale.json') } before do - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(roles) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}/) .to_return(body: body, status: status) end @@ -209,8 +209,8 @@ describe ApiEntreprise::API do let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') } before do - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(roles) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}/) .to_return(body: body, status: status) end @@ -237,8 +237,8 @@ describe ApiEntreprise::API do let(:body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') } before do - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(roles) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) .to_return(body: body, status: status) end @@ -263,7 +263,7 @@ describe ApiEntreprise::API do subject { described_class.entreprise(siren, procedure_id) } before do - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(true) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(true) end it 'makes no call to api-entreprise' do diff --git a/spec/lib/api_entreprise/attestation_fiscale_adapter_spec.rb b/spec/lib/api_entreprise/attestation_fiscale_adapter_spec.rb index ff5e64774..c5354b159 100644 --- a/spec/lib/api_entreprise/attestation_fiscale_adapter_spec.rb +++ b/spec/lib/api_entreprise/attestation_fiscale_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::AttestationFiscaleAdapter do +describe APIEntreprise::AttestationFiscaleAdapter do let(:siret) { '41816609600069' } let(:siren) { '418166096' } let(:procedure) { create(:procedure) } @@ -9,8 +9,8 @@ describe ApiEntreprise::AttestationFiscaleAdapter do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["attestations_fiscales"]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["attestations_fiscales"]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context "when the SIREN is valid" do diff --git a/spec/lib/api_entreprise/attestation_sociale_adapter_spec.rb b/spec/lib/api_entreprise/attestation_sociale_adapter_spec.rb index 067521afb..8bef840c2 100644 --- a/spec/lib/api_entreprise/attestation_sociale_adapter_spec.rb +++ b/spec/lib/api_entreprise/attestation_sociale_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::AttestationSocialeAdapter do +describe APIEntreprise::AttestationSocialeAdapter do let(:siret) { '41816609600069' } let(:siren) { '418166096' } let(:procedure) { create(:procedure) } @@ -8,8 +8,8 @@ describe ApiEntreprise::AttestationSocialeAdapter do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["attestations_sociales"]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["attestations_sociales"]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context "when the SIREN is valid" do diff --git a/spec/lib/api_entreprise/bilans_bdf_adapter_spec.rb b/spec/lib/api_entreprise/bilans_bdf_adapter_spec.rb index fd3689a9c..7945d0cf0 100644 --- a/spec/lib/api_entreprise/bilans_bdf_adapter_spec.rb +++ b/spec/lib/api_entreprise/bilans_bdf_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::BilansBdfAdapter do +describe APIEntreprise::BilansBdfAdapter do let(:siret) { '41816609600069' } let(:siren) { '418166096' } let(:procedure) { create(:procedure) } @@ -9,8 +9,8 @@ describe ApiEntreprise::BilansBdfAdapter do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context "when the SIREN is valid" do diff --git a/spec/lib/api_entreprise/effectifs_adapter_spec.rb b/spec/lib/api_entreprise/effectifs_adapter_spec.rb index ed037135b..d9acbd325 100644 --- a/spec/lib/api_entreprise/effectifs_adapter_spec.rb +++ b/spec/lib/api_entreprise/effectifs_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::EffectifsAdapter do +describe APIEntreprise::EffectifsAdapter do let(:siret) { '41816609600069' } let(:siren) { '418166096' } let(:procedure) { create(:procedure) } @@ -11,7 +11,7 @@ describe ApiEntreprise::EffectifsAdapter do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context "when the SIREN is valid" do diff --git a/spec/lib/api_entreprise/effectifs_annuels_adapter_spec.rb b/spec/lib/api_entreprise/effectifs_annuels_adapter_spec.rb index b343bb79f..48bb22e50 100644 --- a/spec/lib/api_entreprise/effectifs_annuels_adapter_spec.rb +++ b/spec/lib/api_entreprise/effectifs_annuels_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::EffectifsAnnuelsAdapter do +describe APIEntreprise::EffectifsAnnuelsAdapter do let(:siret) { '41816609600069' } let(:siren) { '418166096' } let(:procedure) { create(:procedure) } @@ -9,7 +9,7 @@ describe ApiEntreprise::EffectifsAnnuelsAdapter do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context "when the SIREN is valid" do diff --git a/spec/lib/api_entreprise/entreprise_adapter_spec.rb b/spec/lib/api_entreprise/entreprise_adapter_spec.rb index b72d054a7..cb26c6db9 100644 --- a/spec/lib/api_entreprise/entreprise_adapter_spec.rb +++ b/spec/lib/api_entreprise/entreprise_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::EntrepriseAdapter do +describe APIEntreprise::EntrepriseAdapter do let(:siren) { '418166096' } let(:procedure) { create(:procedure) } let(:procedure_id) { procedure.id } @@ -8,7 +8,7 @@ describe ApiEntreprise::EntrepriseAdapter do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context "when the SIRET is valid" do @@ -84,7 +84,7 @@ describe ApiEntreprise::EntrepriseAdapter do let(:status) { 500 } it 'raises an exception' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::RequestFailed) + expect { subject }.to raise_error(APIEntreprise::API::Error::RequestFailed) end end end diff --git a/spec/lib/api_entreprise/etablissement_adapter_spec.rb b/spec/lib/api_entreprise/etablissement_adapter_spec.rb index 953fc6473..e9cff88a3 100644 --- a/spec/lib/api_entreprise/etablissement_adapter_spec.rb +++ b/spec/lib/api_entreprise/etablissement_adapter_spec.rb @@ -1,9 +1,9 @@ -describe ApiEntreprise::EtablissementAdapter do +describe APIEntreprise::EtablissementAdapter do let(:procedure) { create(:procedure) } let(:procedure_id) { procedure.id } before do - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context 'SIRET valide avec infos diffusables' do diff --git a/spec/lib/api_entreprise/exercices_adapter_spec.rb b/spec/lib/api_entreprise/exercices_adapter_spec.rb index 5f9ab865a..72ecf95eb 100644 --- a/spec/lib/api_entreprise/exercices_adapter_spec.rb +++ b/spec/lib/api_entreprise/exercices_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::ExercicesAdapter do +describe APIEntreprise::ExercicesAdapter do let(:siret) { '41816609600051' } let(:procedure) { create(:procedure) } subject { described_class.new(siret, procedure.id).to_params } @@ -6,7 +6,7 @@ describe ApiEntreprise::ExercicesAdapter do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//) .to_return(body: File.read('spec/fixtures/files/api_entreprise/exercices.json', status: 200)) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end it { is_expected.to be_an_instance_of(Hash) } diff --git a/spec/lib/api_entreprise/rna_adapter_spec.rb b/spec/lib/api_entreprise/rna_adapter_spec.rb index edf632eee..8fb5bc95e 100644 --- a/spec/lib/api_entreprise/rna_adapter_spec.rb +++ b/spec/lib/api_entreprise/rna_adapter_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntreprise::RNAAdapter do +describe APIEntreprise::RNAAdapter do let(:siret) { '50480511000013' } let(:procedure) { create(:procedure) } let(:procedure_id) { procedure.id } @@ -11,7 +11,7 @@ describe ApiEntreprise::RNAAdapter do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//) .to_return(body: body, status: status) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context 'when siret is not valid' do diff --git a/spec/lib/tasks/graphql_spec.rb b/spec/lib/tasks/graphql_spec.rb index 04bf2ebe8..24b772c9a 100644 --- a/spec/lib/tasks/graphql_spec.rb +++ b/spec/lib/tasks/graphql_spec.rb @@ -1,5 +1,5 @@ describe 'graphql' do - let(:current_defn) { Api::V2::Schema.to_definition } + let(:current_defn) { API::V2::Schema.to_definition } let(:printout_defn) { File.read(Rails.root.join('app', 'graphql', 'schema.graphql')) } it "update the printed schema with `bin/rake graphql:schema:idl`" do diff --git a/spec/services/api_entreprise_service_spec.rb b/spec/services/api_entreprise_service_spec.rb index d72da48c4..ba3d117af 100644 --- a/spec/services/api_entreprise_service_spec.rb +++ b/spec/services/api_entreprise_service_spec.rb @@ -1,4 +1,4 @@ -describe ApiEntrepriseService do +describe APIEntrepriseService do describe '#create_etablissement' do before do stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/) @@ -11,11 +11,11 @@ describe ApiEntrepriseService do let(:valid_token) { "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" } let(:procedure) { create(:procedure, api_entreprise_token: valid_token) } let(:dossier) { create(:dossier, procedure: procedure) } - let(:subject) { ApiEntrepriseService.create_etablissement(dossier, siret, procedure.id) } + let(:subject) { APIEntrepriseService.create_etablissement(dossier, siret, procedure.id) } before do - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return([]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return([]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end context 'when service is up' do @@ -24,9 +24,9 @@ describe ApiEntrepriseService do end [ - ApiEntreprise::EntrepriseJob, ApiEntreprise::AssociationJob, ApiEntreprise::ExercicesJob, - ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob, - ApiEntreprise::BilansBdfJob + APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob, + APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob, + APIEntreprise::BilansBdfJob ].each do |job| it "should enqueue #{job.class.name}" do expect { subject }.to have_enqueued_job(job) @@ -38,8 +38,8 @@ describe ApiEntrepriseService do let(:etablissements_status) { 504 } let(:etablissements_body) { '' } - it 'should raise ApiEntreprise::API::Error::RequestFailed' do - expect { subject }.to raise_error(ApiEntreprise::API::Error::RequestFailed) + it 'should raise APIEntreprise::API::Error::RequestFailed' do + expect { subject }.to raise_error(APIEntreprise::API::Error::RequestFailed) end end diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index 3190b90ae..ac66c0a4b 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -370,7 +370,7 @@ describe ProcedureExportService do end it 'should have valid sheet name' do - expect { subject }.not_to raise_error(ArgumentError) + expect { subject }.not_to raise_error end end diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index e4f26d2f1..56347bbfa 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -71,7 +71,7 @@ module FeatureHelpers # Add a new type de champ in the procedure editor def add_champ(options = {}) - add_champs(options) + add_champs(**options) end # Add several new type de champ in the procedure editor diff --git a/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb b/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb index 675353a80..98aa12ef4 100644 --- a/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb +++ b/spec/views/new_administrateur/procedures/invited_expert_list.html.haml_spec.rb @@ -38,7 +38,7 @@ describe 'new_administrateur/procedures/invited_expert_list.html.haml', type: :v it 'has 2 experts and match array' do expect(@invited_expert_emails.count).to eq(2) - expect(@invited_expert_emails).to eq([expert.email, expert2.email]) + expect(@invited_expert_emails).to eq([expert.email, expert2.email].sort) end end end diff --git a/spec/views/users/dossiers/etablissement.html.haml_spec.rb b/spec/views/users/dossiers/etablissement.html.haml_spec.rb index df6399e82..8457012d7 100644 --- a/spec/views/users/dossiers/etablissement.html.haml_spec.rb +++ b/spec/views/users/dossiers/etablissement.html.haml_spec.rb @@ -6,8 +6,8 @@ describe 'users/dossiers/etablissement.html.haml', type: :view do before do sign_in dossier.user assign(:dossier, dossier) - allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return([]) - allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) + allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return([]) + allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) end subject! { render }