Merge pull request #5774 from betagouv/dev

2020-12-08-01
This commit is contained in:
LeSim 2020-12-08 15:00:13 +01:00 committed by GitHub
commit 57d920b30e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 1056 additions and 133 deletions

View file

@ -16,7 +16,7 @@ class Champs::SiretController < ApplicationController
begin
etablissement = find_etablissement_with_siret
rescue ApiEntreprise::API::RequestFailed, ApiEntreprise::API::ServiceUnavailable
rescue ApiEntreprise::API::Error::RequestFailed, ApiEntreprise::API::Error::ServiceUnavailable
return siret_error(:network_error)
end
if etablissement.nil?

View file

@ -22,7 +22,13 @@ class SuperAdminsController < ApplicationController
def generate_qr_code
issuer = 'DSManager'
issuer += "-dev" if Rails.env.development?
if Rails.env.development?
issuer += " (local)"
elsif staging?
issuer += " (dev)"
end
label = "#{issuer}:#{current_super_admin.email}"
RQRCode::QRCode.new(current_super_admin.otp_provisioning_uri(label, issuer: issuer))
end

View file

@ -105,7 +105,7 @@ module Users
sanitized_siret = siret_model.siret
begin
etablissement = ApiEntrepriseService.create_etablissement(@dossier, sanitized_siret, current_user.id)
rescue ApiEntreprise::API::RequestFailed, ApiEntreprise::API::BadGateway
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?

View file

@ -0,0 +1,21 @@
import React from 'react';
import { ReactQueryCacheProvider } from 'react-query';
import ComboSearch from './ComboSearch';
import { queryCache } from './shared/queryCache';
function ComboPaysSearch(params) {
return (
<ReactQueryCacheProvider queryCache={queryCache}>
<ComboSearch
required={params.mandatory}
hiddenFieldId={params.hiddenFieldId}
scope="pays"
minimumInputLength={0}
transformResult={({ nom }) => [nom, nom]}
/>
</ReactQueryCacheProvider>
);
}
export default ComboPaysSearch;

View file

@ -1,5 +1,6 @@
import { QueryCache } from 'react-query';
import { isNumeric } from '@utils';
import matchSorter from 'match-sorter';
const { api_geo_url, api_adresse_url } = gon.autocomplete || {};
@ -31,9 +32,21 @@ function buildOptions() {
}
async function defaultQueryFn(scope, term) {
if (scope == 'pays') {
return matchSorter(await getPays(), term, { keys: ['nom'] });
}
const url = buildURL(scope, term);
const [options, controller] = buildOptions();
const promise = fetch(url, options).then((response) => response.json());
promise.cancel = () => controller && controller.abort();
return promise;
}
let paysCache;
async function getPays() {
if (!paysCache) {
paysCache = await fetch('/pays.json').then((response) => response.json());
}
return paysCache;
}

View file

@ -0,0 +1,3 @@
import Loadable from '../components/Loadable';
export default Loadable(() => import('../components/ComboPaysSearch'));

View file

@ -1,5 +1,5 @@
class ApiEntreprise::ExercicesJob < ApiEntreprise::Job
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
rescue_from(ApiEntreprise::API::Error::BadFormatRequest) do |exception|
end
def perform(etablissement_id, procedure_id)

View file

@ -1,21 +1,31 @@
class ApiEntreprise::Job < ApplicationJob
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
queue_as :api_entreprise
retry_on ApiEntreprise::API::ServiceUnavailable,
ApiEntreprise::API::BadGateway,
# BadGateway could mean
# - acoss: réessayer ultérieurement
# - bdf: erreur interne
# so we retry every day for 5 days
# same logic for ServiceUnavailable
retry_on ApiEntreprise::API::Error::ServiceUnavailable,
ApiEntreprise::API::Error::BadGateway,
wait: 1.day
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
# 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
# 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::ResourceNotFound) do |exception|
rescue_from(ApiEntreprise::API::Error::ResourceNotFound) do |exception|
error(self, exception)
end
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
rescue_from(ApiEntreprise::API::Error::BadFormatRequest) do |exception|
error(self, exception)
end

View file

@ -1,4 +1,4 @@
class AdministrateurActivateBeforeExpirationJob < CronJob
class Cron::AdministrateurActivateBeforeExpirationJob < Cron::CronJob
self.schedule_expression = "every day at 8 am"
def perform(*args)

View file

@ -1,4 +1,4 @@
class AutoArchiveProcedureJob < CronJob
class Cron::AutoArchiveProcedureJob < Cron::CronJob
self.schedule_expression = "every 1 minute"
def perform(*args)

View file

@ -1,4 +1,4 @@
class CronJob < ApplicationJob
class Cron::CronJob < ApplicationJob
queue_as :cron
class_attribute :schedule_expression

View file

@ -1,4 +1,4 @@
class DeclarativeProceduresJob < CronJob
class Cron::DeclarativeProceduresJob < Cron::CronJob
self.schedule_expression = "every 1 minute"
def perform(*args)

View file

@ -1,4 +1,4 @@
class DiscardedDossiersDeletionJob < CronJob
class Cron::DiscardedDossiersDeletionJob < Cron::CronJob
self.schedule_expression = "every day at 2 am"
def perform(*args)

View file

@ -1,4 +1,4 @@
class DiscardedProceduresDeletionJob < CronJob
class Cron::DiscardedProceduresDeletionJob < Cron::CronJob
self.schedule_expression = "every day at 1 am"
def perform(*args)

View file

@ -1,4 +1,4 @@
class ExpiredDossiersDeletionJob < CronJob
class Cron::ExpiredDossiersDeletionJob < Cron::CronJob
self.schedule_expression = "every day at 7 am"
def perform(*args)

View file

@ -1,4 +1,4 @@
class FindDubiousProceduresJob < CronJob
class Cron::FindDubiousProceduresJob < Cron::CronJob
self.schedule_expression = "every day at midnight"
FORBIDDEN_KEYWORDS = [

View file

@ -1,4 +1,4 @@
class InstructeurEmailNotificationJob < CronJob
class Cron::InstructeurEmailNotificationJob < Cron::CronJob
self.schedule_expression = "from monday through friday at 10 am"
def perform(*args)

View file

@ -1,4 +1,4 @@
class NotifyDraftNotSubmittedJob < CronJob
class Cron::NotifyDraftNotSubmittedJob < Cron::CronJob
self.schedule_expression = "from monday through friday at 7 am"
def perform(*args)

View file

@ -1,4 +1,4 @@
class OperationsSignatureJob < CronJob
class Cron::OperationsSignatureJob < Cron::CronJob
self.schedule_expression = "every day at 6 am"
def perform(*args)

View file

@ -1,4 +1,4 @@
class PurgeStaleExportsJob < CronJob
class Cron::PurgeStaleExportsJob < Cron::CronJob
self.schedule_expression = "every 5 minutes"
def perform

View file

@ -1,4 +1,4 @@
class PurgeUnattachedBlobsJob < CronJob
class Cron::PurgeUnattachedBlobsJob < Cron::CronJob
self.schedule_expression = "every day at midnight"
def perform(*args)

View file

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

View file

@ -1,4 +1,4 @@
class UpdateStatsJob < CronJob
class Cron::UpdateStatsJob < Cron::CronJob
self.schedule_expression = "every 1 hour"
def perform(*args)

View file

@ -1,4 +1,4 @@
class WeeklyOverviewJob < CronJob
class Cron::WeeklyOverviewJob < Cron::CronJob
self.schedule_expression = "every monday at 7 am"
def perform(*args)

View file

@ -9,7 +9,7 @@ class ApiEntreprise::Adapter
def data_source
begin
@data_source ||= get_resource
rescue ApiEntreprise::API::ResourceNotFound
rescue ApiEntreprise::API::Error::ResourceNotFound
@data_source = nil
end
end

View file

@ -10,22 +10,7 @@ class ApiEntreprise::API
BILANS_BDF_RESOURCE_NAME = "bilans_entreprises_bdf"
PRIVILEGES_RESOURCE_NAME = "privileges"
TIMEOUT = 15
class ResourceNotFound < StandardError
end
class RequestFailed < StandardError
end
class BadFormatRequest < StandardError
end
class BadGateway < StandardError
end
class ServiceUnavailable < StandardError
end
TIMEOUT = 20
def self.entreprise(siren, procedure_id)
call_with_siret(ENTREPRISE_RESOURCE_NAME, siren, procedure_id)
@ -81,7 +66,7 @@ class ApiEntreprise::API
if response.success?
JSON.parse(response.body, symbolize_names: true)
else
raise RequestFailed, "HTTP Error Code: #{response.code} for #{url}\nheaders: #{response.headers}\nbody: #{response.body}"
raise RequestFailed.new(response)
end
end
@ -97,22 +82,17 @@ class ApiEntreprise::API
if response.success?
JSON.parse(response.body, symbolize_names: true)
elsif response.code&.between?(401, 499)
raise ResourceNotFound, "url: #{url}"
raise Error::ResourceNotFound.new(response)
elsif response.code == 400
raise BadFormatRequest, "url: #{url}"
raise Error::BadFormatRequest.new(response)
elsif response.code == 502
raise BadGateway, "url: #{url}"
raise Error::BadGateway.new(response)
elsif response.code == 503
raise ServiceUnavailable, "url: #{url}"
raise Error::ServiceUnavailable.new(response)
elsif response.timed_out?
raise Error::TimedOut.new(response)
else
raise RequestFailed,
<<~TEXT
HTTP Error Code: #{response.code} for #{url}
headers: #{response.headers}
body: #{response.body}
curl message: #{response.return_message}
timeout: #{response.timed_out?}
TEXT
raise Error::RequestFailed.new(response)
end
end

View file

@ -0,0 +1,18 @@
class ApiEntreprise::API::Error < ::StandardError
def initialize(response)
# use uri to avoid sending token
uri = URI.parse(response.effective_url)
msg = <<~TEXT
url: #{uri.host}#{uri.path}
HTTP error code: #{response.code}
body: #{CGI.escape(response.body)}
curl message: #{response.return_message}
total time: #{response.total_time}
connect time: #{response.connect_time}
response headers: #{response.headers}
TEXT
super(msg)
end
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -15,13 +15,4 @@
# type_de_champ_id :integer
#
class Champs::PaysChamp < Champs::TextChamp
PAYS = JSON.parse(Rails.root.join('app', 'lib', 'api_geo', 'pays.json').read, symbolize_names: true)
def self.pays
PAYS.pluck(:nom)
end
def self.disabled_options
pays.filter { |v| (v =~ /^--.*--$/).present? }
end
end

View file

@ -5,7 +5,7 @@ class ApiEntrepriseService
#
# Returns nil if the SIRET is unknown
#
# Raises a ApiEntreprise::API::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

View file

@ -1,5 +1,3 @@
= form.select :value,
Champs::PaysChamp.pays,
{ disabled: Champs::PaysChamp.disabled_options, include_blank: true },
required: champ.mandatory?,
class: 'select2 pays'
- hidden_field_id = SecureRandom.uuid
= form.hidden_field :value, { data: { uuid: hidden_field_id } }
= react_component("ComboPaysSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id)

848
public/pays.json Normal file
View file

@ -0,0 +1,848 @@
[
{
"nom": "FRANCE"
},
{
"nom": "ACORES, MADERE"
},
{
"nom": "AFGHANISTAN"
},
{
"nom": "AFRIQUE DU SUD"
},
{
"nom": "ALASKA"
},
{
"nom": "ALBANIE"
},
{
"nom": "ALGERIE"
},
{
"nom": "ALLEMAGNE"
},
{
"nom": "ANDORRE"
},
{
"nom": "ANGOLA"
},
{
"nom": "ANGUILLA"
},
{
"nom": "ANTIGUA-ET-BARBUDA"
},
{
"nom": "ANTILLES NEERLANDAISES"
},
{
"nom": "ARABIE SAOUDITE"
},
{
"nom": "ARGENTINE"
},
{
"nom": "ARMENIE"
},
{
"nom": "ARUBA"
},
{
"nom": "AUSTRALIE"
},
{
"nom": "AUTRICHE"
},
{
"nom": "AZERBAIDJAN"
},
{
"nom": "BAHAMAS"
},
{
"nom": "BAHREIN"
},
{
"nom": "BANGLADESH"
},
{
"nom": "BARBADE"
},
{
"nom": "BELGIQUE"
},
{
"nom": "BELIZE"
},
{
"nom": "BENIN"
},
{
"nom": "BERMUDES"
},
{
"nom": "BHOUTAN"
},
{
"nom": "BIELORUSSIE"
},
{
"nom": "BIRMANIE"
},
{
"nom": "BOLIVIE"
},
{
"nom": "BONAIRE, SAINT EUSTACHE ET SABA"
},
{
"nom": "BOSNIE-HERZEGOVINE"
},
{
"nom": "BOTSWANA"
},
{
"nom": "BOUVET (ILE)"
},
{
"nom": "BRESIL"
},
{
"nom": "BRUNEI"
},
{
"nom": "BULGARIE"
},
{
"nom": "BURKINA"
},
{
"nom": "BURUNDI"
},
{
"nom": "CAIMANES (ILES)"
},
{
"nom": "CAMBODGE"
},
{
"nom": "CAMEROUN"
},
{
"nom": "CAMEROUN ET TOGO"
},
{
"nom": "CANADA"
},
{
"nom": "CANARIES (ILES)"
},
{
"nom": "CAP-VERT"
},
{
"nom": "CENTRAFRICAINE (REPUBLIQUE)"
},
{
"nom": "CHILI"
},
{
"nom": "CHINE"
},
{
"nom": "CHRISTMAS (ILE)"
},
{
"nom": "CHYPRE"
},
{
"nom": "CLIPPERTON (ILE)"
},
{
"nom": "COCOS ou KEELING (ILES)"
},
{
"nom": "COLOMBIE"
},
{
"nom": "COMORES"
},
{
"nom": "CONGO"
},
{
"nom": "CONGO (REPUBLIQUE DEMOCRATIQUE)"
},
{
"nom": "COOK (ILES)"
},
{
"nom": "COREE"
},
{
"nom": "COREE (REPUBLIQUE DE)"
},
{
"nom": "COREE (REPUBLIQUE POPULAIRE DEMOCRATIQUE DE)"
},
{
"nom": "COSTA RICA"
},
{
"nom": "COTE D'IVOIRE"
},
{
"nom": "CROATIE"
},
{
"nom": "CUBA"
},
{
"nom": "CURAÇAO"
},
{
"nom": "DANEMARK"
},
{
"nom": "DJIBOUTI"
},
{
"nom": "DOMINICAINE (REPUBLIQUE)"
},
{
"nom": "DOMINIQUE"
},
{
"nom": "EGYPTE"
},
{
"nom": "EL SALVADOR"
},
{
"nom": "EMIRATS ARABES UNIS"
},
{
"nom": "EQUATEUR"
},
{
"nom": "ERYTHREE"
},
{
"nom": "ESPAGNE"
},
{
"nom": "ESTONIE"
},
{
"nom": "ETATS MALAIS NON FEDERES"
},
{
"nom": "ETATS-UNIS"
},
{
"nom": "ETHIOPIE"
},
{
"nom": "FEROE (ILES)"
},
{
"nom": "FIDJI"
},
{
"nom": "FINLANDE"
},
{
"nom": "GABON"
},
{
"nom": "GAMBIE"
},
{
"nom": "GEORGIE"
},
{
"nom": "GEORGIE DU SUD ET LES ILES SANDWICH DU SUD"
},
{
"nom": "GHANA"
},
{
"nom": "GIBRALTAR"
},
{
"nom": "GOA"
},
{
"nom": "GRECE"
},
{
"nom": "GRENADE"
},
{
"nom": "GROENLAND"
},
{
"nom": "GUADELOUPE"
},
{
"nom": "GUAM"
},
{
"nom": "GUATEMALA"
},
{
"nom": "GUERNESEY"
},
{
"nom": "GUINEE"
},
{
"nom": "GUINEE EQUATORIALE"
},
{
"nom": "GUINEE-BISSAU"
},
{
"nom": "GUYANA"
},
{
"nom": "GUYANE"
},
{
"nom": "HAITI"
},
{
"nom": "HAWAII (ILES)"
},
{
"nom": "HEARD ET MACDONALD (ILES)"
},
{
"nom": "HONDURAS"
},
{
"nom": "HONG-KONG"
},
{
"nom": "HONGRIE"
},
{
"nom": "ILES PORTUGAISES DE L'OCEAN INDIEN"
},
{
"nom": "INDE"
},
{
"nom": "INDONESIE"
},
{
"nom": "IRAN"
},
{
"nom": "IRAQ"
},
{
"nom": "IRLANDE, ou EIRE"
},
{
"nom": "ISLANDE"
},
{
"nom": "ISRAEL"
},
{
"nom": "ITALIE"
},
{
"nom": "JAMAIQUE"
},
{
"nom": "JAPON"
},
{
"nom": "JERSEY"
},
{
"nom": "JORDANIE"
},
{
"nom": "KAMTCHATKA"
},
{
"nom": "KAZAKHSTAN"
},
{
"nom": "KENYA"
},
{
"nom": "KIRGHIZISTAN"
},
{
"nom": "KIRIBATI"
},
{
"nom": "KOSOVO"
},
{
"nom": "KOWEIT"
},
{
"nom": "LA REUNION"
},
{
"nom": "LABRADOR"
},
{
"nom": "LAOS"
},
{
"nom": "LESOTHO"
},
{
"nom": "LETTONIE"
},
{
"nom": "LIBAN"
},
{
"nom": "LIBERIA"
},
{
"nom": "LIBYE"
},
{
"nom": "LIECHTENSTEIN"
},
{
"nom": "LITUANIE"
},
{
"nom": "LUXEMBOURG"
},
{
"nom": "MACAO"
},
{
"nom": "MACEDOINE DU NORD (REPUBLIQUE DE)"
},
{
"nom": "MADAGASCAR"
},
{
"nom": "MALAISIE"
},
{
"nom": "MALAWI"
},
{
"nom": "MALDIVES"
},
{
"nom": "MALI"
},
{
"nom": "MALOUINES, OU FALKLAND (ILES)"
},
{
"nom": "MALTE"
},
{
"nom": "MAN (ILE)"
},
{
"nom": "MANDCHOURIE"
},
{
"nom": "MARIANNES DU NORD (ILES)"
},
{
"nom": "MAROC"
},
{
"nom": "MARSHALL (ILES)"
},
{
"nom": "MARTINIQUE"
},
{
"nom": "MAURICE"
},
{
"nom": "MAURITANIE"
},
{
"nom": "MAYOTTE"
},
{
"nom": "MEXIQUE"
},
{
"nom": "MICRONESIE (ETATS FEDERES DE)"
},
{
"nom": "MOLDAVIE"
},
{
"nom": "MONACO"
},
{
"nom": "MONGOLIE"
},
{
"nom": "MONTENEGRO"
},
{
"nom": "MONTSERRAT"
},
{
"nom": "MOZAMBIQUE"
},
{
"nom": "NAMIBIE"
},
{
"nom": "NAURU"
},
{
"nom": "NEPAL"
},
{
"nom": "NICARAGUA"
},
{
"nom": "NIGER"
},
{
"nom": "NIGERIA"
},
{
"nom": "NIUE"
},
{
"nom": "NORFOLK (ILE)"
},
{
"nom": "NORVEGE"
},
{
"nom": "NOUVELLE-CALEDONIE"
},
{
"nom": "NOUVELLE-ZELANDE"
},
{
"nom": "OCEAN INDIEN (TERRITOIRE BRITANNIQUE DE L')"
},
{
"nom": "OMAN"
},
{
"nom": "OUGANDA"
},
{
"nom": "OUZBEKISTAN"
},
{
"nom": "PAKISTAN"
},
{
"nom": "PALAOS (ILES)"
},
{
"nom": "PALESTINE (Etat de)"
},
{
"nom": "PANAMA"
},
{
"nom": "PAPOUASIE-NOUVELLE-GUINEE"
},
{
"nom": "PARAGUAY"
},
{
"nom": "PAYS-BAS"
},
{
"nom": "PEROU"
},
{
"nom": "PHILIPPINES"
},
{
"nom": "PITCAIRN (ILE)"
},
{
"nom": "POLOGNE"
},
{
"nom": "POLYNESIE FRANCAISE"
},
{
"nom": "PORTO RICO"
},
{
"nom": "PORTUGAL"
},
{
"nom": "POSSESSIONS BRITANNIQUES AU PROCHE-ORIENT"
},
{
"nom": "PRESIDES"
},
{
"nom": "PROVINCES ESPAGNOLES D'AFRIQUE"
},
{
"nom": "QATAR"
},
{
"nom": "REPUBLIQUE DEMOCRATIQUE ALLEMANDE"
},
{
"nom": "REPUBLIQUE FEDERALE D'ALLEMAGNE"
},
{
"nom": "ROUMANIE"
},
{
"nom": "ROYAUME-UNI"
},
{
"nom": "RUSSIE"
},
{
"nom": "RWANDA"
},
{
"nom": "SAHARA OCCIDENTAL"
},
{
"nom": "SAINT-BARTHELEMY"
},
{
"nom": "SAINT-CHRISTOPHE-ET-NIEVES"
},
{
"nom": "SAINT-MARIN"
},
{
"nom": "SAINT-MARTIN"
},
{
"nom": "SAINT-MARTIN (PARTIE NEERLANDAISE)"
},
{
"nom": "SAINT-PIERRE-ET-MIQUELON"
},
{
"nom": "SAINT-VINCENT-ET-LES GRENADINES"
},
{
"nom": "SAINTE HELENE, ASCENSION ET TRISTAN DA CUNHA"
},
{
"nom": "SAINTE-LUCIE"
},
{
"nom": "SALOMON (ILES)"
},
{
"nom": "SAMOA AMERICAINES"
},
{
"nom": "SAMOA OCCIDENTALES"
},
{
"nom": "SAO TOME-ET-PRINCIPE"
},
{
"nom": "SENEGAL"
},
{
"nom": "SERBIE"
},
{
"nom": "SEYCHELLES"
},
{
"nom": "SIBERIE"
},
{
"nom": "SIERRA LEONE"
},
{
"nom": "SINGAPOUR"
},
{
"nom": "SLOVAQUIE"
},
{
"nom": "SLOVENIE"
},
{
"nom": "SOMALIE"
},
{
"nom": "SOUDAN"
},
{
"nom": "SOUDAN ANGLO-EGYPTIEN, KENYA, OUGANDA"
},
{
"nom": "SOUDAN DU SUD"
},
{
"nom": "SRI LANKA"
},
{
"nom": "SUEDE"
},
{
"nom": "SUISSE"
},
{
"nom": "SURINAME"
},
{
"nom": "SVALBARD et ILE JAN MAYEN"
},
{
"nom": "SWAZILAND"
},
{
"nom": "SYRIE"
},
{
"nom": "TADJIKISTAN"
},
{
"nom": "TAIWAN"
},
{
"nom": "TANGER"
},
{
"nom": "TANZANIE"
},
{
"nom": "TCHAD"
},
{
"nom": "TCHECOSLOVAQUIE"
},
{
"nom": "TCHEQUE (REPUBLIQUE)"
},
{
"nom": "TERR. DES ETATS-UNIS D'AMERIQUE EN AMERIQUE"
},
{
"nom": "TERR. DES ETATS-UNIS D'AMERIQUE EN OCEANIE"
},
{
"nom": "TERR. DU ROYAUME-UNI DANS L'ATLANTIQUE SUD"
},
{
"nom": "TERRE-NEUVE"
},
{
"nom": "TERRES AUSTRALES FRANCAISES"
},
{
"nom": "TERRITOIRES DU ROYAUME-UNI AUX ANTILLES"
},
{
"nom": "THAILANDE"
},
{
"nom": "TIMOR ORIENTAL"
},
{
"nom": "TOGO"
},
{
"nom": "TOKELAU"
},
{
"nom": "TONGA"
},
{
"nom": "TRINITE-ET-TOBAGO"
},
{
"nom": "TUNISIE"
},
{
"nom": "TURKESTAN RUSSE"
},
{
"nom": "TURKMENISTAN"
},
{
"nom": "TURKS ET CAIQUES (ILES)"
},
{
"nom": "TURQUIE"
},
{
"nom": "TURQUIE D'EUROPE"
},
{
"nom": "TUVALU"
},
{
"nom": "UKRAINE"
},
{
"nom": "URUGUAY"
},
{
"nom": "VANUATU"
},
{
"nom": "VATICAN, ou SAINT-SIEGE"
},
{
"nom": "VENEZUELA"
},
{
"nom": "VIERGES BRITANNIQUES (ILES)"
},
{
"nom": "VIERGES DES ETATS-UNIS (ILES)"
},
{
"nom": "VIET NAM"
},
{
"nom": "VIET NAM DU NORD"
},
{
"nom": "VIET NAM DU SUD"
},
{
"nom": "WALLIS-ET-FUTUNA"
},
{
"nom": "YEMEN"
},
{
"nom": "YEMEN (REPUBLIQUE ARABE DU)"
},
{
"nom": "YEMEN DEMOCRATIQUE"
},
{
"nom": "ZAMBIE"
},
{
"nom": "ZANZIBAR"
},
{
"nom": "ZIMBABWE"
}
]

View file

@ -27,7 +27,7 @@ feature 'The user' do
select('bravo', from: form_id_for('simple_choice_drop_down_list_long'))
select('alpha', from: form_id_for('multiple_choice_drop_down_list_long'))
select('charly', from: form_id_for('multiple_choice_drop_down_list_long'))
select('AUSTRALIE', from: 'pays')
select_champ_geo('pays', 'aust', 'AUSTRALIE')
select_champ_geo('regions', 'Ma', 'Martinique')
@ -40,6 +40,7 @@ feature 'The user' do
find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
blur
sleep(0.7)
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
# check data on the dossier
@ -83,7 +84,7 @@ feature 'The user' do
expect(page).to have_checked_field('val3')
expect(page).to have_selected_value('simple_choice_drop_down_list_long', selected: 'bravo')
expect(page).to have_selected_value('multiple_choice_drop_down_list_long', selected: ['alpha', 'charly'])
expect(page).to have_selected_value('pays', selected: 'AUSTRALIE')
expect(page).to have_hidden_field('pays', with: 'AUSTRALIE')
expect(page).to have_hidden_field('regions', with: 'Martinique')
expect(page).to have_hidden_field('departements', with: '02 - Aisne')
expect(page).to have_hidden_field('communes', with: 'Ambléon (01300)')

View file

@ -1,43 +1,53 @@
include ActiveJob::TestHelper
RSpec.describe ApiEntreprise::Job, type: :job do
# https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html#method-i-retry_on
context 'when an exception is raised' do
subject do
assert_performed_jobs(try) do
ExceptionJob.perform_later(error) rescue StandardError
# https://api.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html
# #method-i-retry_on
describe '#perform' do
context 'when a un retryable error is raised' do
let(:errors) { [:standard_error] }
it 'does not retry' do
ensure_errors_force_n_retry(errors, 1)
end
end
context 'when it is a service_unavaible' do
let(:error) { :standard_error }
let(:try) { 1 }
context 'when a retryable error is raised' do
let(:errors) { [:service_unavaible, :bad_gateway, :timed_out] }
it { subject }
it 'retries 5 times' do
ensure_errors_force_n_retry(errors, 5)
end
end
context 'when it is a service_unavaible' do
let(:error) { :service_unavaible }
let(:try) { 5 }
it { subject }
end
context 'when it is a bad gateway' do
let(:error) { :bad_gateway }
let(:try) { 5 }
it { subject }
def ensure_errors_force_n_retry(errors, retry_nb)
errors.each do |error|
assert_performed_jobs(retry_nb) do
ErrorJob.perform_later(error) rescue StandardError
end
end
end
end
class ExceptionJob < ApiEntreprise::Job
def perform(exception)
case exception
class ErrorJob < ApiEntreprise::Job
def perform(error)
response = OpenStruct.new(
effective_url: 'http://host.com/path',
code: '666',
body: 'body',
return_message: 'return_message',
total_time: 10,
connect_time: 20,
headers: 'headers'
)
case error
when :service_unavaible
raise ApiEntreprise::API::ServiceUnavailable
raise ApiEntreprise::API::Error::ServiceUnavailable.new(response)
when :bad_gateway
raise ApiEntreprise::API::BadGateway
raise ApiEntreprise::API::Error::BadGateway.new(response)
when :timed_out
raise ApiEntreprise::API::Error::TimedOut.new(response)
else
raise StandardError
end

View file

@ -1,10 +1,10 @@
RSpec.describe AdministrateurActivateBeforeExpirationJob, type: :job do
RSpec.describe Cron::AdministrateurActivateBeforeExpirationJob, type: :job do
describe 'perform' do
let(:administrateur) { create(:administrateur) }
let(:user) { administrateur.user }
let(:mailer_double) { double('mailer', deliver_later: true) }
subject { AdministrateurActivateBeforeExpirationJob.perform_now }
subject { Cron::AdministrateurActivateBeforeExpirationJob.perform_now }
before do
Timecop.freeze(Time.zone.local(2018, 03, 20))

View file

@ -1,10 +1,10 @@
RSpec.describe AutoArchiveProcedureJob, type: :job do
RSpec.describe Cron::AutoArchiveProcedureJob, type: :job do
let!(:procedure) { create(:procedure, :published, :with_instructeur, auto_archive_on: nil) }
let!(:procedure_hier) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago.to_date) }
let!(:procedure_aujourdhui) { create(:procedure, :published, :with_instructeur, auto_archive_on: Time.zone.today) }
let!(:procedure_demain) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.from_now.to_date) }
subject { AutoArchiveProcedureJob.new.perform }
subject { Cron::AutoArchiveProcedureJob.new.perform }
context "when procedures have no auto_archive_on" do
before do

View file

@ -1,4 +1,4 @@
RSpec.describe DeclarativeProceduresJob, type: :job do
RSpec.describe Cron::DeclarativeProceduresJob, type: :job do
describe "perform" do
let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) }
let(:instruction_date) { date + 120 }
@ -20,7 +20,7 @@ RSpec.describe DeclarativeProceduresJob, type: :job do
]
create(:attestation_template, procedure: procedure)
DeclarativeProceduresJob.new.perform
Cron::DeclarativeProceduresJob.new.perform
dossiers.each(&:reload)
end

View file

@ -1,4 +1,4 @@
RSpec.describe FindDubiousProceduresJob, type: :job do
RSpec.describe Cron::FindDubiousProceduresJob, type: :job do
describe 'perform' do
let(:mailer_double) { double('mailer', deliver_later: true) }
let(:procedure) { create(:procedure, types_de_champ: tdcs) }
@ -11,7 +11,7 @@ RSpec.describe FindDubiousProceduresJob, type: :job do
@dubious_procedures_args = arg
end.and_return(mailer_double)
FindDubiousProceduresJob.new.perform
Cron::FindDubiousProceduresJob.new.perform
end
context 'with suspicious champs' do

View file

@ -1,4 +1,4 @@
RSpec.describe WeeklyOverviewJob, type: :job do
RSpec.describe Cron::WeeklyOverviewJob, type: :job do
describe 'perform' do
let!(:instructeur) { create(:instructeur) }
let(:overview) { double('overview') }
@ -16,7 +16,7 @@ RSpec.describe WeeklyOverviewJob, type: :job do
before do
expect_any_instance_of(Instructeur).to receive(:last_week_overview).and_return(overview)
allow(InstructeurMailer).to receive(:last_week_overview).and_return(mailer_double)
WeeklyOverviewJob.new.perform
Cron::WeeklyOverviewJob.new.perform
end
it { expect(InstructeurMailer).to have_received(:last_week_overview).with(instructeur) }
@ -27,7 +27,7 @@ RSpec.describe WeeklyOverviewJob, type: :job do
before do
expect_any_instance_of(Instructeur).to receive(:last_week_overview).and_return(nil)
allow(InstructeurMailer).to receive(:last_week_overview)
WeeklyOverviewJob.new.perform
Cron::WeeklyOverviewJob.new.perform
end
it { expect(InstructeurMailer).not_to have_received(:last_week_overview) }
@ -37,7 +37,7 @@ RSpec.describe WeeklyOverviewJob, type: :job do
context 'if the feature is disabled' do
before do
allow(Instructeur).to receive(:all)
WeeklyOverviewJob.new.perform
Cron::WeeklyOverviewJob.new.perform
end
it { expect(Instructeur).not_to receive(:all) }

View file

@ -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::RequestFailed' do
expect { subject }.to raise_error(ApiEntreprise::API::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::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::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::BadFormatRequest' do
expect { subject }.to raise_error(ApiEntreprise::API::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::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::ResourceNotFound)
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
end
end
@ -97,8 +97,8 @@ describe ApiEntreprise::API do
let(:status) { 404 }
let(:body) { '' }
it 'raises ApiEntreprise::API::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::ResourceNotFound)
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
end
end
@ -127,8 +127,8 @@ describe ApiEntreprise::API do
let(:status) { 404 }
let(:body) { '' }
it 'raises ApiEntreprise::API::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::ResourceNotFound)
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
end
end
@ -159,8 +159,8 @@ describe ApiEntreprise::API do
let(:status) { 404 }
let(:body) { '' }
it 'raises ApiEntreprise::API::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::ResourceNotFound)
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
end
end

View file

@ -84,7 +84,7 @@ describe ApiEntreprise::EntrepriseAdapter do
let(:status) { 500 }
it 'raises an exception' do
expect { subject }.to raise_error(ApiEntreprise::API::RequestFailed)
expect { subject }.to raise_error(ApiEntreprise::API::Error::RequestFailed)
end
end
end

View file

@ -455,7 +455,7 @@ describe Instructeur, type: :model do
before do
procedure_to_assign.update(declarative_with_state: "en_instruction")
DeclarativeProceduresJob.new.perform
Cron::DeclarativeProceduresJob.new.perform
dossier.reload
end
@ -480,7 +480,7 @@ describe Instructeur, type: :model do
before do
procedure_to_assign.update(declarative_with_state: "accepte")
DeclarativeProceduresJob.new.perform
Cron::DeclarativeProceduresJob.new.perform
dossier.reload
end
@ -497,7 +497,7 @@ describe Instructeur, type: :model do
before do
procedure_to_assign.update(declarative_with_state: "accepte")
DeclarativeProceduresJob.new.perform
Cron::DeclarativeProceduresJob.new.perform
dossier.traitements.last.update(processed_at: Time.zone.yesterday.beginning_of_day)
dossier.reload
end

View file

@ -38,8 +38,8 @@ describe ApiEntrepriseService do
let(:etablissements_status) { 504 }
let(:etablissements_body) { '' }
it 'should raise ApiEntreprise::API::RequestFailed' do
expect { subject }.to raise_error(ApiEntreprise::API::RequestFailed)
it 'should raise ApiEntreprise::API::Error::RequestFailed' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::RequestFailed)
end
end

View file

@ -51,7 +51,7 @@ describe NotificationService do
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
before do
procedure.update(declarative_with_state: "en_instruction")
DeclarativeProceduresJob.new.perform
Cron::DeclarativeProceduresJob.new.perform
dossier.reload
end
@ -65,7 +65,7 @@ describe NotificationService do
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
before do
procedure.update(declarative_with_state: "accepte")
DeclarativeProceduresJob.new.perform
Cron::DeclarativeProceduresJob.new.perform
dossier.traitements.last.update!(processed_at: Time.zone.yesterday.beginning_of_day)
dossier.reload
end
@ -80,7 +80,7 @@ describe NotificationService do
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
before do
procedure.update(declarative_with_state: "accepte")
DeclarativeProceduresJob.new.perform
Cron::DeclarativeProceduresJob.new.perform
dossier.reload
end