zeitwerk: Api -> API

This commit is contained in:
Pierre de La Morinerie 2020-08-05 16:40:47 +00:00
parent 482f990594
commit 150ddab660
82 changed files with 235 additions and 217 deletions

View file

@ -2,7 +2,7 @@ class API::V2::GraphqlController < API::V2::BaseController
def execute def execute
variables = ensure_hash(params[:variables]) variables = ensure_hash(params[:variables])
result = Api::V2::Schema.execute(params[:query], result = API::V2::Schema.execute(params[:query],
variables: variables, variables: variables,
context: context, context: context,
operation_name: params[:operationName]) operation_name: params[:operationName])

View file

@ -11,7 +11,7 @@ class Champs::CarteController < ApplicationController
@champ.geo_areas += GeoArea.from_feature_collection(cadastres_features_collection(@champ.to_feature_collection)) @champ.geo_areas += GeoArea.from_feature_collection(cadastres_features_collection(@champ.to_feature_collection))
@champ.save! @champ.save!
end end
rescue ApiCarto::API::ResourceNotFound rescue APICarto::API::ResourceNotFound
flash.alert = 'Les données cartographiques sont temporairement indisponibles. Réessayez dans un instant.' flash.alert = 'Les données cartographiques sont temporairement indisponibles. Réessayez dans un instant.'
response.status = 503 response.status = 503
end end
@ -77,7 +77,7 @@ class Champs::CarteController < ApplicationController
end end
if coordinates.present? if coordinates.present?
cadastres = ApiCartoService.generate_cadastre(coordinates) cadastres = APICartoService.generate_cadastre(coordinates)
{ {
type: 'FeatureCollection', type: 'FeatureCollection',

View file

@ -17,7 +17,7 @@ class Champs::SiretController < ApplicationController
begin begin
etablissement = find_etablissement_with_siret 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') # i18n-tasks-use t('errors.siret_network_error')
return siret_error(:network_error) return siret_error(:network_error)
end end
@ -53,7 +53,7 @@ class Champs::SiretController < ApplicationController
end end
def find_etablissement_with_siret def find_etablissement_with_siret
ApiEntrepriseService.create_etablissement(@champ, @siret, current_user.id) APIEntrepriseService.create_etablissement(@champ, @siret, current_user.id)
end end
def clear_siret_and_etablissement def clear_siret_and_etablissement

View file

@ -129,7 +129,7 @@ module NewAdministrateur
@procedure.api_entreprise_token = token @procedure.api_entreprise_token = token
if @procedure.valid? && if @procedure.valid? &&
ApiEntreprise::PrivilegesAdapter.new(token).valid? && APIEntreprise::PrivilegesAdapter.new(token).valid? &&
@procedure.save @procedure.save
redirect_to jeton_admin_procedure_path(procedure_id: params[:procedure_id]), redirect_to jeton_admin_procedure_path(procedure_id: params[:procedure_id]),

View file

@ -97,8 +97,8 @@ module Users
sanitized_siret = siret_model.siret sanitized_siret = siret_model.siret
begin begin
etablissement = ApiEntrepriseService.create_etablissement(@dossier, sanitized_siret, current_user.id) etablissement = APIEntrepriseService.create_etablissement(@dossier, sanitized_siret, current_user.id)
rescue ApiEntreprise::API::Error::RequestFailed, ApiEntreprise::API::Error::BadGateway, ApiEntreprise::API::Error::TimedOut rescue APIEntreprise::API::Error::RequestFailed, APIEntreprise::API::Error::BadGateway, APIEntreprise::API::Error::TimedOut
return render_siret_error(t('errors.messages.siret_network_error')) return render_siret_error(t('errors.messages.siret_network_error'))
end end
if etablissement.nil? if etablissement.nil?

View file

@ -1,4 +1,4 @@
class Api::V2::Context < GraphQL::Query::Context class API::V2::Context < GraphQL::Query::Context
def has_fragment?(name) def has_fragment?(name)
if self["has_fragment_#{name}"] if self["has_fragment_#{name}"]
true true

View file

@ -1,4 +1,4 @@
class Api::V2::Schema < GraphQL::Schema class API::V2::Schema < GraphQL::Schema
default_max_page_size 100 default_max_page_size 100
max_complexity 300 max_complexity 300
max_depth 15 max_depth 15
@ -6,7 +6,7 @@ class Api::V2::Schema < GraphQL::Schema
query Types::QueryType query Types::QueryType
mutation Types::MutationType mutation Types::MutationType
context_class Api::V2::Context context_class API::V2::Context
def self.id_from_object(object, type_definition, ctx) def self.id_from_object(object, type_definition, ctx)
object.to_typed_id object.to_typed_id

View file

@ -3,7 +3,7 @@ class AnnuaireEducationUpdateJob < ApplicationJob
external_id = champ.external_id external_id = champ.external_id
if external_id.present? if external_id.present?
data = ApiEducation::AnnuaireEducationAdapter.new(external_id).to_params data = APIEducation::AnnuaireEducationAdapter.new(external_id).to_params
if data.present? if data.present?
champ.data = data champ.data = data

View file

@ -1,7 +1,7 @@
class ApiEntreprise::AssociationJob < ApiEntreprise::Job class APIEntreprise::AssociationJob < APIEntreprise::Job
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
find_etablissement(etablissement_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) etablissement.update!(etablissement_params)
end end
end end

View file

@ -1,7 +1,7 @@
class ApiEntreprise::AttestationFiscaleJob < ApiEntreprise::Job class APIEntreprise::AttestationFiscaleJob < APIEntreprise::Job
def perform(etablissement_id, procedure_id, user_id) def perform(etablissement_id, procedure_id, user_id)
find_etablissement(etablissement_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) attestation_fiscale_url = etablissement_params.delete(:entreprise_attestation_fiscale_url)
etablissement.upload_attestation_fiscale(attestation_fiscale_url) if attestation_fiscale_url.present? etablissement.upload_attestation_fiscale(attestation_fiscale_url) if attestation_fiscale_url.present?
end end

View file

@ -1,7 +1,7 @@
class ApiEntreprise::AttestationSocialeJob < ApiEntreprise::Job class APIEntreprise::AttestationSocialeJob < APIEntreprise::Job
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
find_etablissement(etablissement_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) attestation_sociale_url = etablissement_params.delete(:entreprise_attestation_sociale_url)
etablissement.upload_attestation_sociale(attestation_sociale_url) if attestation_sociale_url.present? etablissement.upload_attestation_sociale(attestation_sociale_url) if attestation_sociale_url.present?
end end

View file

@ -1,7 +1,7 @@
class ApiEntreprise::BilansBdfJob < ApiEntreprise::Job class APIEntreprise::BilansBdfJob < APIEntreprise::Job
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
find_etablissement(etablissement_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) etablissement.update!(etablissement_params)
end end
end end

View file

@ -1,7 +1,7 @@
class ApiEntreprise::EffectifsAnnuelsJob < ApiEntreprise::Job class APIEntreprise::EffectifsAnnuelsJob < APIEntreprise::Job
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
find_etablissement(etablissement_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) etablissement.update!(etablissement_params)
end end
end end

View file

@ -1,8 +1,8 @@
class ApiEntreprise::EffectifsJob < ApiEntreprise::Job class APIEntreprise::EffectifsJob < APIEntreprise::Job
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
find_etablissement(etablissement_id) find_etablissement(etablissement_id)
# may 2020 is at the moment the most actual info for effectifs endpoint # 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) etablissement.update!(etablissement_params)
end end

View file

@ -1,7 +1,7 @@
class ApiEntreprise::EntrepriseJob < ApiEntreprise::Job class APIEntreprise::EntrepriseJob < APIEntreprise::Job
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
find_etablissement(etablissement_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) etablissement.update!(etablissement_params)
end end
end end

View file

@ -1,10 +1,10 @@
class ApiEntreprise::ExercicesJob < ApiEntreprise::Job class APIEntreprise::ExercicesJob < APIEntreprise::Job
rescue_from(ApiEntreprise::API::Error::BadFormatRequest) do |exception| rescue_from(APIEntreprise::API::Error::BadFormatRequest) do |exception|
end end
def perform(etablissement_id, procedure_id) def perform(etablissement_id, procedure_id)
find_etablissement(etablissement_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) etablissement.update!(etablissement_params)
end end
end end

View file

@ -1,4 +1,4 @@
class ApiEntreprise::Job < ApplicationJob class APIEntreprise::Job < ApplicationJob
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5 DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
queue_as :api_entreprise queue_as :api_entreprise
@ -8,27 +8,27 @@ class ApiEntreprise::Job < ApplicationJob
# - bdf: erreur interne # - bdf: erreur interne
# so we retry every day for 5 days # so we retry every day for 5 days
# same logic for ServiceUnavailable # same logic for ServiceUnavailable
rescue_from(ApiEntreprise::API::Error::ServiceUnavailable) do |exception| rescue_from(APIEntreprise::API::Error::ServiceUnavailable) do |exception|
retry_or_discard(exception) retry_or_discard(exception)
end end
rescue_from(ApiEntreprise::API::Error::BadGateway) do |exception| rescue_from(APIEntreprise::API::Error::BadGateway) do |exception|
retry_or_discard(exception) retry_or_discard(exception)
end end
# We guess the backend is slow but not broken # We guess the backend is slow but not broken
# and the information we are looking for is available # and the information we are looking for is available
# so we retry few seconds later (exponentially to avoid overload) # 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 # If by the time the job runs the Etablissement has been deleted
# (it can happen through EtablissementUpdateJob for instance), ignore the job # (it can happen through EtablissementUpdateJob for instance), ignore the job
discard_on ActiveRecord::RecordNotFound discard_on ActiveRecord::RecordNotFound
rescue_from(ApiEntreprise::API::Error::ResourceNotFound) do |exception| rescue_from(APIEntreprise::API::Error::ResourceNotFound) do |exception|
error(self, exception) error(self, exception)
end end
rescue_from(ApiEntreprise::API::Error::BadFormatRequest) do |exception| rescue_from(APIEntreprise::API::Error::BadFormatRequest) do |exception|
error(self, exception) error(self, exception)
end end

View file

@ -1,4 +1,4 @@
class Cron::FixMissingAntivirusAnalysis < Cron::CronJob class Cron::FixMissingAntivirusAnalysisJob < Cron::CronJob
self.schedule_expression = "every day at 2 am" self.schedule_expression = "every day at 2 am"
def perform def perform

View file

@ -1,7 +1,7 @@
class EtablissementUpdateJob < ApplicationJob class EtablissementUpdateJob < ApplicationJob
def perform(dossier, siret) def perform(dossier, siret)
begin 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 rescue
return return
end end

View file

@ -1,4 +1,4 @@
class ApiCarto::API class APICarto::API
class ResourceNotFound < StandardError class ResourceNotFound < StandardError
end end
@ -16,7 +16,7 @@ class ApiCarto::API
response.body response.body
else else
message = response.code == 0 ? response.return_message : response.code.to_s 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 raise ResourceNotFound
end end
end end

View file

@ -1,10 +1,10 @@
class ApiCarto::CadastreAdapter class APICarto::CadastreAdapter
def initialize(coordinates) def initialize(coordinates)
@coordinates = GeojsonService.to_json_polygon_for_cadastre(coordinates) @coordinates = GeojsonService.to_json_polygon_for_cadastre(coordinates)
end end
def data_source 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 end
def results def results

View file

@ -1,6 +1,6 @@
require 'json_schemer' require 'json_schemer'
class ApiEducation::AnnuaireEducationAdapter class APIEducation::AnnuaireEducationAdapter
class InvalidSchemaError < ::StandardError class InvalidSchemaError < ::StandardError
def initialize(errors) def initialize(errors)
super(errors.map(&:to_json).join("\n")) super(errors.map(&:to_json).join("\n"))
@ -27,7 +27,7 @@ class ApiEducation::AnnuaireEducationAdapter
private private
def data_source 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 end
def schemer def schemer

View file

@ -1,4 +1,4 @@
class ApiEducation::API class APIEducation::API
class ResourceNotFound < StandardError class ResourceNotFound < StandardError
end end
@ -15,7 +15,7 @@ class ApiEducation::API
response.body response.body
else else
message = response.code == 0 ? response.return_message : response.code.to_s 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 raise ResourceNotFound
end end
end end

View file

@ -1,4 +1,4 @@
class ApiEntreprise::Adapter class APIEntreprise::Adapter
UNAVAILABLE = 'Donnée indisponible' UNAVAILABLE = 'Donnée indisponible'
def initialize(siret, procedure_id) def initialize(siret, procedure_id)
@ -9,7 +9,7 @@ class ApiEntreprise::Adapter
def data_source def data_source
begin begin
@data_source ||= get_resource @data_source ||= get_resource
rescue ApiEntreprise::API::Error::ResourceNotFound rescue APIEntreprise::API::Error::ResourceNotFound
@data_source = nil @data_source = nil
end end
end end

View file

@ -1,4 +1,4 @@
class ApiEntreprise::API class APIEntreprise::API
ENTREPRISE_RESOURCE_NAME = "entreprises" ENTREPRISE_RESOURCE_NAME = "entreprises"
ETABLISSEMENT_RESOURCE_NAME = "etablissements" ETABLISSEMENT_RESOURCE_NAME = "etablissements"
EXERCICES_RESOURCE_NAME = "exercices" EXERCICES_RESOURCE_NAME = "exercices"
@ -72,7 +72,7 @@ class ApiEntreprise::API
end end
def self.call_with_siret(resource_name, siret_or_siren, procedure_id, user_id = nil) 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) url = url(resource_name, siret_or_siren)
params = params(siret_or_siren, procedure_id, user_id) params = params(siret_or_siren, procedure_id, user_id)

View file

@ -1,4 +1,4 @@
class ApiEntreprise::API::Error < ::StandardError class APIEntreprise::API::Error < ::StandardError
def initialize(response) def initialize(response)
# use uri to avoid sending token # use uri to avoid sending token
uri = URI.parse(response.effective_url) uri = URI.parse(response.effective_url)

View file

@ -1,4 +1,2 @@
class ApiEntreprise::API::Error class APIEntreprise::API::Error::BadFormatRequest < APIEntreprise::API::Error
class BadFormatRequest < ApiEntreprise::API::Error
end
end end

View file

@ -1,4 +1,2 @@
class ApiEntreprise::API::Error class APIEntreprise::API::Error::BadGateway < APIEntreprise::API::Error
class BadGateway < ApiEntreprise::API::Error
end
end end

View file

@ -1,4 +1,2 @@
class ApiEntreprise::API::Error class APIEntreprise::API::Error::RequestFailed < APIEntreprise::API::Error
class RequestFailed < ApiEntreprise::API::Error
end
end end

View file

@ -1,4 +1,2 @@
class ApiEntreprise::API::Error class APIEntreprise::API::Error::ResourceNotFound < APIEntreprise::API::Error
class ResourceNotFound < ApiEntreprise::API::Error
end
end end

View file

@ -1,4 +1,2 @@
class ApiEntreprise::API::Error class APIEntreprise::API::Error::ServiceUnavailable < APIEntreprise::API::Error
class ServiceUnavailable < ApiEntreprise::API::Error
end
end end

View file

@ -1,4 +1,2 @@
class ApiEntreprise::API::Error class APIEntreprise::API::Error::TimedOut < APIEntreprise::API::Error
class TimedOut < ApiEntreprise::API::Error
end
end end

View file

@ -1,4 +1,4 @@
class ApiEntreprise::AttestationFiscaleAdapter < ApiEntreprise::Adapter class APIEntreprise::AttestationFiscaleAdapter < APIEntreprise::Adapter
def initialize(siret, procedure_id, user_id) def initialize(siret, procedure_id, user_id)
@siret = siret @siret = siret
@procedure_id = procedure_id @procedure_id = procedure_id
@ -8,7 +8,7 @@ class ApiEntreprise::AttestationFiscaleAdapter < ApiEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.attestation_fiscale(siren, @procedure_id, @user_id) APIEntreprise::API.attestation_fiscale(siren, @procedure_id, @user_id)
end end
def process_params def process_params

View file

@ -1,4 +1,4 @@
class ApiEntreprise::AttestationSocialeAdapter < ApiEntreprise::Adapter class APIEntreprise::AttestationSocialeAdapter < APIEntreprise::Adapter
def initialize(siret, procedure_id) def initialize(siret, procedure_id)
@siret = siret @siret = siret
@procedure_id = procedure_id @procedure_id = procedure_id
@ -7,7 +7,7 @@ class ApiEntreprise::AttestationSocialeAdapter < ApiEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.attestation_sociale(siren, @procedure_id) APIEntreprise::API.attestation_sociale(siren, @procedure_id)
end end
def process_params def process_params

View file

@ -1,4 +1,4 @@
class ApiEntreprise::BilansBdfAdapter < ApiEntreprise::Adapter class APIEntreprise::BilansBdfAdapter < APIEntreprise::Adapter
def initialize(siret, procedure_id) def initialize(siret, procedure_id)
@siret = siret @siret = siret
@procedure_id = procedure_id @procedure_id = procedure_id
@ -7,7 +7,7 @@ class ApiEntreprise::BilansBdfAdapter < ApiEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.bilans_bdf(siren, @procedure_id) APIEntreprise::API.bilans_bdf(siren, @procedure_id)
end end
def process_params def process_params

View file

@ -1,4 +1,4 @@
class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter class APIEntreprise::EffectifsAdapter < APIEntreprise::Adapter
def initialize(siret, procedure_id, annee, mois) def initialize(siret, procedure_id, annee, mois)
@siret = siret @siret = siret
@procedure_id = procedure_id @procedure_id = procedure_id
@ -9,7 +9,7 @@ class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.effectifs(siren, @procedure_id, @annee, @mois) APIEntreprise::API.effectifs(siren, @procedure_id, @annee, @mois)
end end
def process_params def process_params

View file

@ -1,4 +1,4 @@
class ApiEntreprise::EffectifsAnnuelsAdapter < ApiEntreprise::Adapter class APIEntreprise::EffectifsAnnuelsAdapter < APIEntreprise::Adapter
def initialize(siret, procedure_id) def initialize(siret, procedure_id)
@siret = siret @siret = siret
@procedure_id = procedure_id @procedure_id = procedure_id
@ -7,7 +7,7 @@ class ApiEntreprise::EffectifsAnnuelsAdapter < ApiEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.effectifs_annuels(siren, @procedure_id) APIEntreprise::API.effectifs_annuels(siren, @procedure_id)
end end
def process_params def process_params

View file

@ -1,8 +1,8 @@
class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.entreprise(siren, @procedure_id) APIEntreprise::API.entreprise(siren, @procedure_id)
end end
def process_params def process_params

View file

@ -1,8 +1,8 @@
class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter class APIEntreprise::EtablissementAdapter < APIEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.etablissement(@siret, @procedure_id) APIEntreprise::API.etablissement(@siret, @procedure_id)
end end
def process_params def process_params

View file

@ -1,8 +1,8 @@
class ApiEntreprise::ExercicesAdapter < ApiEntreprise::Adapter class APIEntreprise::ExercicesAdapter < APIEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.exercices(@siret, @procedure_id) APIEntreprise::API.exercices(@siret, @procedure_id)
end end
def process_params def process_params

View file

@ -1,4 +1,4 @@
class ApiEntreprise::PrivilegesAdapter < ApiEntreprise::Adapter class APIEntreprise::PrivilegesAdapter < APIEntreprise::Adapter
def initialize(token) def initialize(token)
@token = token @token = token
end end
@ -15,6 +15,6 @@ class ApiEntreprise::PrivilegesAdapter < ApiEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.privileges(@token) APIEntreprise::API.privileges(@token)
end end
end end

View file

@ -1,8 +1,8 @@
class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter class APIEntreprise::RNAAdapter < APIEntreprise::Adapter
private private
def get_resource def get_resource
ApiEntreprise::API.rna(@siret, @procedure_id) APIEntreprise::API.rna(@siret, @procedure_id)
end end
def process_params def process_params

View file

@ -1,4 +1,4 @@
class Sendinblue::Api class Sendinblue::API
def self.new_properly_configured! def self.new_properly_configured!
api = self.new api = self.new
if !api.properly_configured? if !api.properly_configured?

View file

@ -1,4 +1,4 @@
class ApiEntrepriseToken class APIEntrepriseToken
attr_reader :token attr_reader :token
def initialize(token) def initialize(token)

View file

@ -625,7 +625,7 @@ class Procedure < ApplicationRecord
end end
def api_entreprise_role?(role) def api_entreprise_role?(role)
ApiEntrepriseToken.new(api_entreprise_token).role?(role) APIEntrepriseToken.new(api_entreprise_token).role?(role)
end end
def api_entreprise_token def api_entreprise_token
@ -633,7 +633,7 @@ class Procedure < ApplicationRecord
end end
def api_entreprise_token_expired? def api_entreprise_token_expired?
ApiEntrepriseToken.new(api_entreprise_token).expired? APIEntrepriseToken.new(api_entreprise_token).expired?
end end
def create_new_revision def create_new_revision

View file

@ -1,3 +1,3 @@
class ModuleApiCartoSerializer < ActiveModel::Serializer class ModuleAPICartoSerializer < ActiveModel::Serializer
attributes :use_api_carto, :cadastre attributes :use_api_carto, :cadastre
end end

View file

@ -13,7 +13,7 @@ class ProcedureSerializer < ActiveModel::Serializer
:link, :link,
:state :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, serializer: TypeDeChampSerializer
has_many :types_de_champ_private, serializer: TypeDeChampSerializer has_many :types_de_champ_private, serializer: TypeDeChampSerializer
has_many :types_de_piece_justificative has_many :types_de_piece_justificative

View file

@ -18,7 +18,7 @@ class AdministrateurUsageStatisticsService
private private
def api def api
@api ||= Sendinblue::Api.new_properly_configured! @api ||= Sendinblue::API.new_properly_configured!
end end
def administrateur_stats(administrateur) def administrateur_stats(administrateur)

View file

@ -1,7 +1,7 @@
class ApiCartoService class APICartoService
def self.generate_qp(coordinates) def self.generate_qp(coordinates)
coordinates.flat_map do |coordinate| coordinates.flat_map do |coordinate|
ApiCarto::QuartiersPrioritairesAdapter.new( APICarto::QuartiersPrioritairesAdapter.new(
coordinate.map { |element| [element['lng'], element['lat']] } coordinate.map { |element| [element['lng'], element['lat']] }
).results ).results
end end
@ -9,7 +9,7 @@ class ApiCartoService
def self.generate_cadastre(coordinates) def self.generate_cadastre(coordinates)
coordinates.flat_map do |coordinate| coordinates.flat_map do |coordinate|
ApiCarto::CadastreAdapter.new( APICarto::CadastreAdapter.new(
coordinate.map { |element| [element['lng'], element['lat']] } coordinate.map { |element| [element['lng'], element['lat']] }
).results ).results
end end

View file

@ -1,27 +1,27 @@
class ApiEntrepriseService class APIEntrepriseService
# create etablissement with EtablissementAdapter # create etablissement with EtablissementAdapter
# enqueue api_entreprise jobs to retrieve # enqueue api_entreprise jobs to retrieve
# all informations we can get about a SIRET. # all informations we can get about a SIRET.
# #
# Returns nil if the SIRET is unknown # 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.) # (timeout, 5XX HTTP error code, etc.)
def self.create_etablissement(dossier_or_champ, siret, user_id = nil) 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? return nil if etablissement_params.empty?
etablissement = dossier_or_champ.build_etablissement(etablissement_params) etablissement = dossier_or_champ.build_etablissement(etablissement_params)
etablissement.save! etablissement.save!
[ [
ApiEntreprise::EntrepriseJob, ApiEntreprise::AssociationJob, ApiEntreprise::ExercicesJob, APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob, APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob,
ApiEntreprise::BilansBdfJob APIEntreprise::BilansBdfJob
].each do |job| ].each do |job|
job.perform_later(etablissement.id, dossier_or_champ.procedure.id) job.perform_later(etablissement.id, dossier_or_champ.procedure.id)
end 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 etablissement
end end

View file

@ -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

View file

@ -24,12 +24,12 @@ namespace :after_party do
def fetch_api_entreprise_infos(etablissement_id, procedure_id, user_id) def fetch_api_entreprise_infos(etablissement_id, procedure_id, user_id)
[ [
ApiEntreprise::EntrepriseJob, ApiEntreprise::AssociationJob, ApiEntreprise::ExercicesJob, APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob, APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob,
ApiEntreprise::BilansBdfJob APIEntreprise::BilansBdfJob
].each do |job| ].each do |job|
job.perform_later(etablissement_id, procedure_id) job.perform_later(etablissement_id, procedure_id)
end end
ApiEntreprise::AttestationFiscaleJob.perform_later(etablissement_id, procedure_id, user_id) APIEntreprise::AttestationFiscaleJob.perform_later(etablissement_id, procedure_id, user_id)
end end
end end

View file

@ -1,2 +1,2 @@
require "graphql/rake_task" 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')

View file

@ -32,9 +32,9 @@ describe Champs::SiretController, type: :controller do
sign_in user sign_in user
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
.to_return(status: api_etablissement_status, body: api_etablissement_body) .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"]) .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 end
context 'when the SIRET is empty' do context 'when the SIRET is empty' do

View file

@ -338,7 +338,7 @@ describe NewAdministrateur::ProceduresController, type: :controller do
subject { patch :update_jeton, params: { id: procedure.id, procedure: { api_entreprise_token: token } } } subject { patch :update_jeton, params: { id: procedure.id, procedure: { api_entreprise_token: token } } }
before do 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 subject
end end

View file

@ -208,9 +208,9 @@ describe Users::DossiersController, type: :controller do
sign_in(user) sign_in(user)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/)
.to_return(status: api_etablissement_status, body: api_etablissement_body) .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"]) .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 end
subject! { post :update_siret, params: { id: dossier.id, user: { siret: params_siret } } } subject! { post :update_siret, params: { id: dossier.id, user: { siret: params_siret } } }

View file

@ -78,8 +78,8 @@ feature 'Creating a new dossier:' do
.to_return(status: 404, body: '') .to_return(status: 404, body: '')
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/)
.to_return(status: 404, body: '') .to_return(status: 404, body: '')
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return([]) 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(:expired?).and_return(false)
end end
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) } before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
after { Timecop.return } after { Timecop.return }

View file

@ -1,4 +1,4 @@
RSpec.describe ApiEntreprise::AssociationJob, type: :job do RSpec.describe APIEntreprise::AssociationJob, type: :job do
let(:siret) { '50480511000013' } let(:siret) { '50480511000013' }
let(:etablissement) { create(:etablissement, siret: siret) } let(:etablissement) { create(:etablissement, siret: siret) }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
@ -9,10 +9,10 @@ RSpec.describe ApiEntreprise::AssociationJob, type: :job do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
.to_return(body: body, status: status) .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 end
subject { ApiEntreprise::AssociationJob.new.perform(etablissement.id, procedure_id) } subject { APIEntreprise::AssociationJob.new.perform(etablissement.id, procedure_id) }
it 'updates etablissement' do it 'updates etablissement' do
subject subject

View file

@ -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(:etablissement) { create(:etablissement, siret: siret) }
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
@ -12,11 +12,11 @@ RSpec.describe ApiEntreprise::AttestationFiscaleJob, type: :job do
.to_return(body: body, status: status) .to_return(body: body, status: status)
stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf") stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156756-f6b7779f99fa95cd60dc03c04fcb-attestation_fiscale_dgfip.pdf")
.to_return(body: "body attestation", status: 200) .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(:roles).and_return(["attestations_fiscales"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end 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 it 'updates etablissement' do
subject subject

View file

@ -1,6 +1,6 @@
include ActiveJob::TestHelper include ActiveJob::TestHelper
RSpec.describe ApiEntreprise::AttestationSocialeJob, type: :job do RSpec.describe APIEntreprise::AttestationSocialeJob, type: :job do
let(:etablissement) { create(:etablissement, siret: siret) } let(:etablissement) { create(:etablissement, siret: siret) }
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
@ -13,11 +13,11 @@ RSpec.describe ApiEntreprise::AttestationSocialeJob, type: :job do
.to_return(body: body, status: status) .to_return(body: body, status: status)
stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156881-f749d75e2bfd443316e2e02d59015f-attestation_vigilance_acoss.pdf") stub_request(:get, "https://storage.entreprise.api.gouv.fr/siade/1569156881-f749d75e2bfd443316e2e02d59015f-attestation_vigilance_acoss.pdf")
.to_return(body: "body attestation", status: 200) .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(:roles).and_return(["attestations_sociales"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end end
subject { ApiEntreprise::AttestationSocialeJob.new.perform(etablissement.id, procedure.id) } subject { APIEntreprise::AttestationSocialeJob.new.perform(etablissement.id, procedure.id) }
it 'updates etablissement' do it 'updates etablissement' do
subject subject

View file

@ -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(:etablissement) { create(:etablissement, siret: siret) }
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
@ -11,11 +11,11 @@ RSpec.describe ApiEntreprise::BilansBdfJob, type: :job do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/)
.to_return(body: body, status: status) .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(:roles).and_return(["bilans_entreprise_bdf"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end end
subject { ApiEntreprise::BilansBdfJob.new.perform(etablissement.id, procedure_id) } subject { APIEntreprise::BilansBdfJob.new.perform(etablissement.id, procedure_id) }
it 'updates etablissement' do it 'updates etablissement' do
subject subject

View file

@ -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(:etablissement) { create(:etablissement, siret: siret) }
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
@ -10,10 +10,10 @@ RSpec.describe ApiEntreprise::EffectifsAnnuelsJob, type: :job do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/)
.to_return(body: body, status: status) .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 end
subject { ApiEntreprise::EffectifsAnnuelsJob.new.perform(etablissement.id, procedure_id) } subject { APIEntreprise::EffectifsAnnuelsJob.new.perform(etablissement.id, procedure_id) }
it 'updates etablissement' do it 'updates etablissement' do
subject subject

View file

@ -1,4 +1,4 @@
RSpec.describe ApiEntreprise::EffectifsJob, type: :job do RSpec.describe APIEntreprise::EffectifsJob, type: :job do
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
let(:etablissement) { create(:etablissement, siret: siret) } let(:etablissement) { create(:etablissement, siret: siret) }
@ -13,13 +13,13 @@ RSpec.describe ApiEntreprise::EffectifsJob, type: :job do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}/)
.to_return(body: body, status: status) .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 end
before { Timecop.freeze(now) } before { Timecop.freeze(now) }
after { Timecop.return } 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 it 'updates etablissement' do
subject subject

View file

@ -1,4 +1,4 @@
RSpec.describe ApiEntreprise::EntrepriseJob, type: :job do RSpec.describe APIEntreprise::EntrepriseJob, type: :job do
let(:siret) { '41816609600051' } let(:siret) { '41816609600051' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
let(:etablissement) { create(:etablissement, siret: siret) } let(:etablissement) { create(:etablissement, siret: siret) }
@ -10,10 +10,10 @@ RSpec.describe ApiEntreprise::EntrepriseJob, type: :job do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
.to_return(body: body, status: status) .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 end
subject { ApiEntreprise::EntrepriseJob.new.perform(etablissement.id, procedure_id) } subject { APIEntreprise::EntrepriseJob.new.perform(etablissement.id, procedure_id) }
it 'updates etablissement' do it 'updates etablissement' do
subject subject

View file

@ -1,4 +1,4 @@
RSpec.describe ApiEntreprise::ExercicesJob, type: :job do RSpec.describe APIEntreprise::ExercicesJob, type: :job do
let(:siret) { '41816609600051' } let(:siret) { '41816609600051' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:etablissement) { create(:etablissement, siret: siret) } let(:etablissement) { create(:etablissement, siret: siret) }
@ -8,10 +8,10 @@ RSpec.describe ApiEntreprise::ExercicesJob, type: :job do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//)
.to_return(body: body, status: status) .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 end
subject { ApiEntreprise::ExercicesJob.new.perform(etablissement.id, procedure.id) } subject { APIEntreprise::ExercicesJob.new.perform(etablissement.id, procedure.id) }
it 'updates etablissement' do it 'updates etablissement' do
subject subject

View file

@ -1,6 +1,6 @@
include ActiveJob::TestHelper 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 # https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html
# #method-i-retry_on # #method-i-retry_on
describe '#perform' do describe '#perform' do
@ -19,7 +19,7 @@ RSpec.describe ApiEntreprise::Job, type: :job do
it 'retries 5 times' do it 'retries 5 times' do
ensure_errors_force_n_retry(errors, 5) 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
end end
@ -34,7 +34,7 @@ RSpec.describe ApiEntreprise::Job, type: :job do
end end
end end
class ErrorJob < ApiEntreprise::Job class ErrorJob < APIEntreprise::Job
def perform(error, etablissement) def perform(error, etablissement)
@etablissement = etablissement @etablissement = etablissement
@ -50,11 +50,11 @@ RSpec.describe ApiEntreprise::Job, type: :job do
case error case error
when :service_unavaible when :service_unavaible
raise ApiEntreprise::API::Error::ServiceUnavailable.new(response) raise APIEntreprise::API::Error::ServiceUnavailable.new(response)
when :bad_gateway when :bad_gateway
raise ApiEntreprise::API::Error::BadGateway.new(response) raise APIEntreprise::API::Error::BadGateway.new(response)
when :timed_out when :timed_out
raise ApiEntreprise::API::Error::TimedOut.new(response) raise APIEntreprise::API::Error::TimedOut.new(response)
else else
raise StandardError raise StandardError
end end

View file

@ -1,4 +1,4 @@
describe ApiCarto::API do describe APICarto::API do
describe '.search_cadastre' do describe '.search_cadastre' do
subject { described_class.search_cadastre(geojson) } subject { described_class.search_cadastre(geojson) }
@ -13,8 +13,8 @@ describe ApiCarto::API do
let(:status) { 404 } let(:status) { 404 }
let(:body) { '' } let(:body) { '' }
it 'raises ApiCarto::API::ResourceNotFound' do it 'raises APICarto::API::ResourceNotFound' do
expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound) expect { subject }.to raise_error(APICarto::API::ResourceNotFound)
end end
end end

View file

@ -1,4 +1,4 @@
describe ApiCarto::CadastreAdapter do describe APICarto::CadastreAdapter do
subject { described_class.new(coordinates).results } subject { described_class.new(coordinates).results }
before do before do
@ -58,6 +58,6 @@ describe ApiCarto::CadastreAdapter do
let(:status) { 404 } let(:status) { 404 }
let(:body) { '' } let(:body) { '' }
it { expect { subject }.to raise_error(ApiCarto::API::ResourceNotFound) } it { expect { subject }.to raise_error(APICarto::API::ResourceNotFound) }
end end
end end

View file

@ -1,4 +1,4 @@
describe ApiEducation::AnnuaireEducationAdapter do describe APIEducation::AnnuaireEducationAdapter do
let(:search_term) { '0050009H' } let(:search_term) { '0050009H' }
let(:adapter) { described_class.new(search_term) } let(:adapter) { described_class.new(search_term) }
subject { adapter.to_params } subject { adapter.to_params }
@ -23,7 +23,7 @@ describe ApiEducation::AnnuaireEducationAdapter do
let(:status) { 200 } let(:status) { 200 }
it '#to_params raise exception' do 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 end
end end

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::API do describe APIEntreprise::API do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
let(:token) { Rails.application.secrets.api_entreprise[:key] } let(:token) { Rails.application.secrets.api_entreprise[:key] }
@ -9,7 +9,7 @@ describe ApiEntreprise::API do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
.to_return(status: status, body: body) .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 end
context 'when the service throws a bad gateaway exception' do context 'when the service throws a bad gateaway exception' do
@ -17,8 +17,8 @@ describe ApiEntreprise::API do
let(:status) { 502 } let(:status) { 502 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_unavailable.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_unavailable.json') }
it 'raises ApiEntreprise::API::Error::RequestFailed' do it 'raises APIEntreprise::API::Error::RequestFailed' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::BadGateway) expect { subject }.to raise_error(APIEntreprise::API::Error::BadGateway)
end end
end end
@ -27,8 +27,8 @@ describe ApiEntreprise::API do
let(:status) { 404 } let(:status) { 404 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end end
end end
@ -37,8 +37,8 @@ describe ApiEntreprise::API do
let(:status) { 400 } let(:status) { 400 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') }
it 'raises ApiEntreprise::API::Error::BadFormatRequest' do it 'raises APIEntreprise::API::Error::BadFormatRequest' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::BadFormatRequest) expect { subject }.to raise_error(APIEntreprise::API::Error::BadFormatRequest)
end end
end end
@ -47,8 +47,8 @@ describe ApiEntreprise::API do
let(:status) { 403 } let(:status) { 403 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_private.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_private.json') }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end end
end end
@ -89,7 +89,7 @@ describe ApiEntreprise::API do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*non_diffusables=true/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*non_diffusables=true/)
.to_return(status: status, body: body) .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 end
context 'when siret does not exist' do context 'when siret does not exist' do
@ -97,8 +97,8 @@ describe ApiEntreprise::API do
let(:status) { 404 } let(:status) { 404 }
let(:body) { '' } let(:body) { '' }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end end
end end
@ -117,7 +117,7 @@ describe ApiEntreprise::API do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//)
.to_return(status: status, body: body) .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 end
context 'when siret does not exist' do context 'when siret does not exist' do
@ -127,8 +127,8 @@ describe ApiEntreprise::API do
let(:status) { 404 } let(:status) { 404 }
let(:body) { '' } let(:body) { '' }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end end
end end
@ -149,7 +149,7 @@ describe ApiEntreprise::API do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
.to_return(status: status, body: body) .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 end
subject { described_class.rna(siren, procedure_id) } subject { described_class.rna(siren, procedure_id) }
@ -159,8 +159,8 @@ describe ApiEntreprise::API do
let(:status) { 404 } let(:status) { 404 }
let(:body) { '' } let(:body) { '' }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound) expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end end
end end
@ -180,8 +180,8 @@ describe ApiEntreprise::API do
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_sociale.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_sociale.json') }
before do before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles) 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(:expired?).and_return(false)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}/)
.to_return(body: body, status: status) .to_return(body: body, status: status)
end end
@ -209,8 +209,8 @@ describe ApiEntreprise::API do
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
before do before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles) 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(:expired?).and_return(false)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}/)
.to_return(body: body, status: status) .to_return(body: body, status: status)
end end
@ -237,8 +237,8 @@ describe ApiEntreprise::API do
let(:body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') } let(:body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') }
before do before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles) 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(:expired?).and_return(false)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/)
.to_return(body: body, status: status) .to_return(body: body, status: status)
end end
@ -263,7 +263,7 @@ describe ApiEntreprise::API do
subject { described_class.entreprise(siren, procedure_id) } subject { described_class.entreprise(siren, procedure_id) }
before do 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 end
it 'makes no call to api-entreprise' do it 'makes no call to api-entreprise' do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::AttestationFiscaleAdapter do describe APIEntreprise::AttestationFiscaleAdapter do
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
@ -9,8 +9,8 @@ describe ApiEntreprise::AttestationFiscaleAdapter do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}/)
.to_return(body: body, status: status) .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(:roles).and_return(["attestations_fiscales"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end end
context "when the SIREN is valid" do context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::AttestationSocialeAdapter do describe APIEntreprise::AttestationSocialeAdapter do
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
@ -8,8 +8,8 @@ describe ApiEntreprise::AttestationSocialeAdapter do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}/)
.to_return(body: body, status: status) .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(:roles).and_return(["attestations_sociales"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end end
context "when the SIREN is valid" do context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::BilansBdfAdapter do describe APIEntreprise::BilansBdfAdapter do
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
@ -9,8 +9,8 @@ describe ApiEntreprise::BilansBdfAdapter do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/)
.to_return(body: body, status: status) .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(:roles).and_return(["bilans_entreprise_bdf"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false) allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end end
context "when the SIREN is valid" do context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::EffectifsAdapter do describe APIEntreprise::EffectifsAdapter do
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
@ -11,7 +11,7 @@ describe ApiEntreprise::EffectifsAdapter do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}/)
.to_return(body: body, status: status) .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 end
context "when the SIREN is valid" do context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::EffectifsAnnuelsAdapter do describe APIEntreprise::EffectifsAnnuelsAdapter do
let(:siret) { '41816609600069' } let(:siret) { '41816609600069' }
let(:siren) { '418166096' } let(:siren) { '418166096' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
@ -9,7 +9,7 @@ describe ApiEntreprise::EffectifsAnnuelsAdapter do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/)
.to_return(body: body, status: status) .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 end
context "when the SIREN is valid" do context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::EntrepriseAdapter do describe APIEntreprise::EntrepriseAdapter do
let(:siren) { '418166096' } let(:siren) { '418166096' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
@ -8,7 +8,7 @@ describe ApiEntreprise::EntrepriseAdapter do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
.to_return(body: body, status: status) .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 end
context "when the SIRET is valid" do context "when the SIRET is valid" do
@ -84,7 +84,7 @@ describe ApiEntreprise::EntrepriseAdapter do
let(:status) { 500 } let(:status) { 500 }
it 'raises an exception' do 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 end
end end

View file

@ -1,9 +1,9 @@
describe ApiEntreprise::EtablissementAdapter do describe APIEntreprise::EtablissementAdapter do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
before do 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 end
context 'SIRET valide avec infos diffusables' do context 'SIRET valide avec infos diffusables' do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::ExercicesAdapter do describe APIEntreprise::ExercicesAdapter do
let(:siret) { '41816609600051' } let(:siret) { '41816609600051' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
subject { described_class.new(siret, procedure.id).to_params } subject { described_class.new(siret, procedure.id).to_params }
@ -6,7 +6,7 @@ describe ApiEntreprise::ExercicesAdapter do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//)
.to_return(body: File.read('spec/fixtures/files/api_entreprise/exercices.json', status: 200)) .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 end
it { is_expected.to be_an_instance_of(Hash) } it { is_expected.to be_an_instance_of(Hash) }

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::RNAAdapter do describe APIEntreprise::RNAAdapter do
let(:siret) { '50480511000013' } let(:siret) { '50480511000013' }
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id } let(:procedure_id) { procedure.id }
@ -11,7 +11,7 @@ describe ApiEntreprise::RNAAdapter do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//) stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
.to_return(body: body, status: status) .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 end
context 'when siret is not valid' do context 'when siret is not valid' do

View file

@ -1,5 +1,5 @@
describe 'graphql' do 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')) } let(:printout_defn) { File.read(Rails.root.join('app', 'graphql', 'schema.graphql')) }
it "update the printed schema with `bin/rake graphql:schema:idl`" do it "update the printed schema with `bin/rake graphql:schema:idl`" do

View file

@ -1,4 +1,4 @@
describe ApiEntrepriseService do describe APIEntrepriseService do
describe '#create_etablissement' do describe '#create_etablissement' do
before do before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}/) 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(:valid_token) { "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
let(:procedure) { create(:procedure, api_entreprise_token: valid_token) } let(:procedure) { create(:procedure, api_entreprise_token: valid_token) }
let(:dossier) { create(:dossier, procedure: procedure) } 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 before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return([]) 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(:expired?).and_return(false)
end end
context 'when service is up' do context 'when service is up' do
@ -24,9 +24,9 @@ describe ApiEntrepriseService do
end end
[ [
ApiEntreprise::EntrepriseJob, ApiEntreprise::AssociationJob, ApiEntreprise::ExercicesJob, APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob, APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob,
ApiEntreprise::BilansBdfJob APIEntreprise::BilansBdfJob
].each do |job| ].each do |job|
it "should enqueue #{job.class.name}" do it "should enqueue #{job.class.name}" do
expect { subject }.to have_enqueued_job(job) expect { subject }.to have_enqueued_job(job)
@ -38,8 +38,8 @@ describe ApiEntrepriseService do
let(:etablissements_status) { 504 } let(:etablissements_status) { 504 }
let(:etablissements_body) { '' } let(:etablissements_body) { '' }
it 'should raise ApiEntreprise::API::Error::RequestFailed' do it 'should raise APIEntreprise::API::Error::RequestFailed' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::RequestFailed) expect { subject }.to raise_error(APIEntreprise::API::Error::RequestFailed)
end end
end end

View file

@ -6,8 +6,8 @@ describe 'users/dossiers/etablissement.html.haml', type: :view do
before do before do
sign_in dossier.user sign_in dossier.user
assign(:dossier, dossier) assign(:dossier, dossier)
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return([]) 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(:expired?).and_return(false)
end end
subject! { render } subject! { render }