commit
16bd8acea5
25 changed files with 220 additions and 67 deletions
|
@ -4,7 +4,7 @@ defaults: &defaults
|
|||
working_directory: ~/tps
|
||||
docker:
|
||||
- image: circleci/ruby:2.6.5-node-browsers
|
||||
- image: circleci/postgres:9.5
|
||||
- image: circleci/postgres:10.12
|
||||
environment:
|
||||
POSTGRES_USER: tps_test
|
||||
POSTGRES_PASSWORD: tps_test
|
||||
|
|
|
@ -60,6 +60,7 @@ class ApiEntreprise::API
|
|||
private
|
||||
|
||||
def self.call(resource_name, siret_or_siren, procedure_id, user_id = nil)
|
||||
return if ApiEntrepriseToken.new(token_for_procedure(procedure_id)).expired?
|
||||
url = url(resource_name, siret_or_siren)
|
||||
params = params(siret_or_siren, procedure_id, user_id)
|
||||
|
||||
|
|
25
app/models/api_entreprise_token.rb
Normal file
25
app/models/api_entreprise_token.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
class ApiEntrepriseToken
|
||||
attr_reader :token
|
||||
|
||||
def initialize(token)
|
||||
@token = token
|
||||
end
|
||||
|
||||
def roles
|
||||
decoded_token["roles"] if token.present?
|
||||
end
|
||||
|
||||
def expired?
|
||||
Time.zone.now.to_i >= decoded_token["exp"] if token.present?
|
||||
end
|
||||
|
||||
def role?(role)
|
||||
roles.include?(role)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def decoded_token
|
||||
JWT.decode(token, nil, false)[0]
|
||||
end
|
||||
end
|
|
@ -58,8 +58,8 @@ class Champs::CarteChamp < Champ
|
|||
bounding_box = RGeo::Cartesian::BoundingBox.new(factory)
|
||||
|
||||
if geo_areas.present?
|
||||
geo_areas.each do |area|
|
||||
bounding_box.add(area.rgeo_geometry)
|
||||
geo_areas.map(&:rgeo_geometry).compact.each do |geometry|
|
||||
bounding_box.add(geometry)
|
||||
end
|
||||
elsif dossier.present?
|
||||
point = dossier.geo_position
|
||||
|
|
|
@ -723,8 +723,8 @@ class Dossier < ApplicationRecord
|
|||
factory = RGeo::Geographic.simple_mercator_factory
|
||||
bounding_box = RGeo::Cartesian::BoundingBox.new(factory)
|
||||
|
||||
geo_areas.each do |area|
|
||||
bounding_box.add(area.rgeo_geometry)
|
||||
geo_areas.map(&:rgeo_geometry).compact.each do |geometry|
|
||||
bounding_box.add(geometry)
|
||||
end
|
||||
|
||||
[bounding_box.max_point, bounding_box.min_point].compact.flat_map(&:coordinates)
|
||||
|
|
|
@ -49,6 +49,8 @@ class GeoArea < ApplicationRecord
|
|||
|
||||
def rgeo_geometry
|
||||
RGeo::GeoJSON.decode(geometry.to_json, geo_factory: RGeo::Geographic.simple_mercator_factory)
|
||||
rescue RGeo::Error::InvalidGeometry
|
||||
nil
|
||||
end
|
||||
|
||||
def self.from_feature_collection(feature_collection)
|
||||
|
|
|
@ -552,18 +552,18 @@ class Procedure < ApplicationRecord
|
|||
"Procedure;#{id}"
|
||||
end
|
||||
|
||||
def api_entreprise_roles
|
||||
JWT.decode(api_entreprise_token, nil, false)[0]["roles"] if api_entreprise_token.present?
|
||||
end
|
||||
|
||||
def api_entreprise_role?(role)
|
||||
api_entreprise_roles.include?(role)
|
||||
ApiEntrepriseToken.new(api_entreprise_token).role?(role)
|
||||
end
|
||||
|
||||
def api_entreprise_token
|
||||
self[:api_entreprise_token].presence || Rails.application.secrets.api_entreprise[:key]
|
||||
end
|
||||
|
||||
def api_entreprise_token_expired?
|
||||
ApiEntrepriseToken.new(api_entreprise_token).expired?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def move_type_de_champ_attributes(types_de_champ, type_de_champ, new_index)
|
||||
|
|
|
@ -7,9 +7,9 @@ def render_in_2_columns(pdf, label, text)
|
|||
pdf.text "\n"
|
||||
end
|
||||
|
||||
def format_in_2_lines(pdf, label, nb_lines = 1)
|
||||
add_single_line(pdf, label, 12, :bold)
|
||||
|
||||
def format_in_2_lines(pdf, champ, nb_lines = 1)
|
||||
add_single_line(pdf, champ.libelle, 12, :bold)
|
||||
add_optionnal_description(pdf, champ)
|
||||
height = 10 * (nb_lines+1)
|
||||
pdf.bounding_box([0, pdf.cursor],:width => 460,:height => height) do
|
||||
pdf.stroke_bounds
|
||||
|
@ -89,37 +89,45 @@ def add_explanation(pdf, explanation)
|
|||
add_single_line(pdf, explanation, 9, :italic)
|
||||
end
|
||||
|
||||
def add_optionnal_description(pdf, champ)
|
||||
add_explanation(pdf, champ.description.strip + "\n\n") if champ.description.present?
|
||||
end
|
||||
|
||||
def render_single_champ(pdf, champ)
|
||||
case champ.type
|
||||
when 'Champs::RepetitionChamp'
|
||||
raise 'There should not be a RepetitionChamp here !'
|
||||
when 'Champs::PieceJustificativeChamp'
|
||||
add_single_line(pdf, 'Pièce justificative à joindre', 12, :bold)
|
||||
pdf.text champ.libelle
|
||||
pdf.text champ.description
|
||||
add_single_line(pdf, 'Pièce justificative à joindre en complément du dossier', 12, :bold)
|
||||
format_with_checkbox(pdf, champ.libelle)
|
||||
add_optionnal_description(pdf, champ)
|
||||
pdf.text "\n"
|
||||
when 'Champs::YesNoChamp', 'Champs::CheckboxChamp'
|
||||
add_libelle(pdf, champ)
|
||||
add_optionnal_description(pdf, champ)
|
||||
add_explanation(pdf, 'Cochez la mention applicable')
|
||||
format_with_checkbox(pdf, 'Oui')
|
||||
format_with_checkbox(pdf, 'Non')
|
||||
pdf.text "\n"
|
||||
when 'Champs::CiviliteChamp'
|
||||
add_libelle(pdf, champ)
|
||||
add_optionnal_description(pdf, champ)
|
||||
format_with_checkbox(pdf, Individual::GENDER_FEMALE)
|
||||
format_with_checkbox(pdf, Individual::GENDER_MALE)
|
||||
pdf.text "\n"
|
||||
when 'Champs::HeaderSectionChamp'
|
||||
add_single_line(pdf, champ.libelle, 18, :bold)
|
||||
add_optionnal_description(pdf, champ)
|
||||
pdf.text "\n"
|
||||
when 'Champs::ExplicationChamp'
|
||||
add_libelle(pdf, champ)
|
||||
pdf.text champ.description
|
||||
pdf.text "\n"
|
||||
when 'Champs::AddressChamp', 'Champs::CarteChamp', 'Champs::TextareaChamp'
|
||||
format_in_2_lines(pdf, champ.libelle, 3)
|
||||
format_in_2_lines(pdf, champ, 5)
|
||||
when 'Champs::DropDownListChamp'
|
||||
add_libelle(pdf, champ)
|
||||
add_optionnal_description(pdf, champ)
|
||||
add_explanation(pdf, 'Cochez la mention applicable, une seule valeur possible')
|
||||
champ.drop_down_list.options.reject(&:blank?).each do |option|
|
||||
format_with_checkbox(pdf, option)
|
||||
|
@ -127,6 +135,7 @@ def render_single_champ(pdf, champ)
|
|||
pdf.text "\n"
|
||||
when 'Champs::MultipleDropDownListChamp'
|
||||
add_libelle(pdf, champ)
|
||||
add_optionnal_description(pdf, champ)
|
||||
add_explanation(pdf, 'Cochez la mention applicable, plusieurs valeurs possibles')
|
||||
champ.drop_down_list.options.reject(&:blank?).each do |option|
|
||||
format_with_checkbox(pdf, option)
|
||||
|
@ -144,7 +153,7 @@ def render_single_champ(pdf, champ)
|
|||
when 'Champs::SiretChamp'
|
||||
add_identite_etablissement(pdf, champ.libelle)
|
||||
else
|
||||
format_in_2_lines(pdf, champ.libelle)
|
||||
format_in_2_lines(pdf, champ)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -190,6 +199,7 @@ prawn_document(page_size: "A4") do |pdf|
|
|||
pdf.text "\n"
|
||||
|
||||
add_title(pdf, 'Formulaire')
|
||||
add_single_line(pdf, @procedure.description + "\n", 12, :italic) if @procedure.description.present?
|
||||
add_champs(pdf, @dossier.champs)
|
||||
add_page_numbering(pdf)
|
||||
add_procedure(pdf, @dossier)
|
||||
|
|
|
@ -230,6 +230,8 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:api_entreprise_bilans_bdf_status) { 200 }
|
||||
let(:api_entreprise_bilans_bdf_body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') }
|
||||
|
||||
let(:token_expired) { false }
|
||||
|
||||
def stub_api_entreprise_requests
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
||||
.to_return(status: api_etablissement_status, body: api_etablissement_body)
|
||||
|
@ -258,8 +260,9 @@ describe Users::DossiersController, type: :controller do
|
|||
before do
|
||||
sign_in(user)
|
||||
stub_api_entreprise_requests
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles)
|
||||
.and_return(["attestations_fiscales", "attestations_sociales", "bilans_entreprise_bdf"])
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(token_expired)
|
||||
end
|
||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||
after { Timecop.return }
|
||||
|
@ -316,6 +319,14 @@ describe Users::DossiersController, type: :controller do
|
|||
it_behaves_like 'the request fails with an error', I18n.t('errors.messages.siret_unknown')
|
||||
end
|
||||
|
||||
context 'when default token has expired' do
|
||||
let(:api_etablissement_status) { 200 }
|
||||
let(:api_body_status) { '' }
|
||||
let(:token_expired) { true }
|
||||
|
||||
it_behaves_like 'the request fails with an error', I18n.t('errors.messages.siret_unknown')
|
||||
end
|
||||
|
||||
context 'when the API returns no Entreprise' do
|
||||
let(:api_entreprise_status) { 404 }
|
||||
let(:api_entreprise_body) { '' }
|
||||
|
|
|
@ -35,5 +35,28 @@ FactoryBot.define do
|
|||
}
|
||||
end
|
||||
end
|
||||
|
||||
trait :line_string do
|
||||
geometry do
|
||||
{
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[2.4282521009445195, 46.53841410755813],
|
||||
[2.42824137210846, 46.53847314771794],
|
||||
[2.428284287452698, 46.53847314771794],
|
||||
[2.4284291267395024, 46.538491597754714]
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
trait :point do
|
||||
geometry do
|
||||
{
|
||||
"type": "Point",
|
||||
"coordinates": [2.428439855575562, 46.538476837725796]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,7 +78,8 @@ feature 'Creating a new dossier:' do
|
|||
.to_return(status: 404, body: '')
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
||||
.to_return(status: 404, body: '')
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles).and_return([])
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return([])
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
before { Timecop.freeze(Time.zone.local(2020, 3, 14)) }
|
||||
after { Timecop.return }
|
||||
|
|
|
@ -9,6 +9,7 @@ describe ApiEntreprise::API do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=#{token}/)
|
||||
.to_return(status: status, body: body)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context 'when the service is unavailable' do
|
||||
|
@ -78,6 +79,7 @@ describe ApiEntreprise::API do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*non_diffusables=true&.*token=/)
|
||||
.to_return(status: status, body: body)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context 'when siret does not exist' do
|
||||
|
@ -105,6 +107,7 @@ describe ApiEntreprise::API do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/.*token=/)
|
||||
.to_return(status: status, body: body)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context 'when siret does not exist' do
|
||||
|
@ -136,6 +139,7 @@ describe ApiEntreprise::API do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/.*token=/)
|
||||
.to_return(status: status, body: body)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
subject { described_class.rna(siren, procedure_id) }
|
||||
|
@ -166,7 +170,8 @@ describe ApiEntreprise::API do
|
|||
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_sociale.json') }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_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)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
end
|
||||
|
@ -194,7 +199,8 @@ describe ApiEntreprise::API do
|
|||
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_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)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}?.*token=#{token}&user_id=#{user_id}/)
|
||||
.to_return(body: body, status: status)
|
||||
end
|
||||
|
@ -221,7 +227,8 @@ describe ApiEntreprise::API do
|
|||
let(:body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_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)
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}?.*token=#{token}/)
|
||||
.to_return(body: body, status: status)
|
||||
end
|
||||
|
@ -240,4 +247,18 @@ describe ApiEntreprise::API do
|
|||
it { expect(subject).to eq(JSON.parse(body, symbolize_names: true)) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with expired token' do
|
||||
let(:siren) { '111111111' }
|
||||
subject { described_class.entreprise(siren, procedure_id) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(true)
|
||||
end
|
||||
|
||||
it 'makes no call to api-entreprise' do
|
||||
subject
|
||||
expect(WebMock).not_to have_requested(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=#{token}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,8 @@ describe ApiEntreprise::AttestationFiscaleAdapter do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_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)
|
||||
end
|
||||
|
||||
context "when the SIREN is valid" do
|
||||
|
|
|
@ -7,7 +7,8 @@ describe ApiEntreprise::AttestationSocialeAdapter do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_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)
|
||||
end
|
||||
|
||||
context "when the SIREN is valid" do
|
||||
|
|
|
@ -8,7 +8,8 @@ describe ApiEntreprise::BilansBdfAdapter do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_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)
|
||||
end
|
||||
|
||||
context "when the SIREN is valid" do
|
||||
|
|
|
@ -10,6 +10,7 @@ describe ApiEntreprise::EffectifsAdapter do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context "when the SIREN is valid" do
|
||||
|
|
|
@ -8,6 +8,7 @@ describe ApiEntreprise::EffectifsAnnuelsAdapter do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context "when the SIREN is valid" do
|
||||
|
|
|
@ -8,6 +8,7 @@ describe ApiEntreprise::EntrepriseAdapter do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context "when the SIRET is valid" do
|
||||
|
|
|
@ -2,6 +2,10 @@ describe ApiEntreprise::EtablissementAdapter do
|
|||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context 'SIRET valide avec infos diffusables' do
|
||||
let(:siret) { '41816609600051' }
|
||||
subject { described_class.new(siret, procedure_id).to_params }
|
||||
|
|
|
@ -6,6 +6,7 @@ describe ApiEntreprise::ExercicesAdapter do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/.*token=/)
|
||||
.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)
|
||||
end
|
||||
|
||||
it { is_expected.to be_an_instance_of(Hash) }
|
||||
|
|
|
@ -11,6 +11,7 @@ describe ApiEntreprise::RNAAdapter do
|
|||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/.*token=/)
|
||||
.to_return(body: body, status: status)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context 'when siret is not valid' do
|
||||
|
|
|
@ -1,50 +1,70 @@
|
|||
RSpec.describe GeoArea, type: :model do
|
||||
describe '#area' do
|
||||
let(:geo_area) do
|
||||
create(:geo_area, geometry: {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[2.428439855575562, 46.538476837725796],
|
||||
[2.4284291267395024, 46.53842148758162],
|
||||
[2.4282521009445195, 46.53841410755813],
|
||||
[2.42824137210846, 46.53847314771794],
|
||||
[2.428284287452698, 46.53847314771794],
|
||||
[2.428364753723145, 46.538487907747864],
|
||||
[2.4284291267395024, 46.538491597754714],
|
||||
[2.428439855575562, 46.538476837725796]
|
||||
]
|
||||
]
|
||||
})
|
||||
end
|
||||
let(:geo_area) { create(:geo_area, :polygon) }
|
||||
|
||||
it { expect(geo_area.area).to eq(219.0) }
|
||||
end
|
||||
|
||||
describe '#length' do
|
||||
let(:geo_area) do
|
||||
create(:geo_area, geometry: {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[2.4282521009445195, 46.53841410755813],
|
||||
[2.42824137210846, 46.53847314771794],
|
||||
[2.428284287452698, 46.53847314771794],
|
||||
[2.4284291267395024, 46.538491597754714]
|
||||
]
|
||||
})
|
||||
end
|
||||
let(:geo_area) { create(:geo_area, :line_string) }
|
||||
|
||||
it { expect(geo_area.length).to eq(30.8) }
|
||||
end
|
||||
|
||||
describe '#location' do
|
||||
let(:geo_area) do
|
||||
create(:geo_area, geometry: {
|
||||
"type": "Point",
|
||||
"coordinates": [2.428439855575562, 46.538476837725796]
|
||||
})
|
||||
end
|
||||
let(:geo_area) { create(:geo_area, :point) }
|
||||
|
||||
it { expect(geo_area.location).to eq("2°25'42\"N 46°32'19\"E") }
|
||||
end
|
||||
|
||||
describe '#rgeo_geometry' do
|
||||
let(:geo_area) { create(:geo_area, geometry: geometry) }
|
||||
|
||||
context 'invalid' do
|
||||
let(:geometry) do
|
||||
{
|
||||
"type" => "MultiPolygon",
|
||||
"coordinates" => [
|
||||
[
|
||||
[
|
||||
[5.894422531127931, 48.22810341752755],
|
||||
[5.893049240112306, 48.22427237832278],
|
||||
[5.892534255981446, 48.22593062452037],
|
||||
[5.892791748046875, 48.2260449843468],
|
||||
[5.894422531127931, 48.229933066408215],
|
||||
[5.894422531127931, 48.22810341752755]
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
[5.8950233459472665, 48.229933066408215],
|
||||
[5.893478393554688, 48.228961073585126],
|
||||
[5.892791748046875, 48.228903896961775],
|
||||
[5.892705917358398, 48.230390468407535],
|
||||
[5.8950233459472665, 48.229933066408215]
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
[5.893220901489259, 48.229246955743626],
|
||||
[5.893392562866212, 48.22884672027457],
|
||||
[5.892705917358398, 48.22878954352343],
|
||||
[5.892019271850587, 48.22856083588024],
|
||||
[5.892019271850587, 48.2277031731152],
|
||||
[5.890989303588868, 48.22787470681807],
|
||||
[5.889959335327149, 48.22787470681807],
|
||||
[5.890560150146485, 48.22838930447709],
|
||||
[5.890645980834962, 48.22878954352343],
|
||||
[5.890989303588868, 48.229018250144584],
|
||||
[5.892362594604493, 48.22930413198368],
|
||||
[5.893220901489259, 48.229246955743626]
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
it { expect(geo_area.rgeo_geometry).to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -334,6 +334,31 @@ describe Procedure do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'api_entreprise_token_expired?' do
|
||||
let(:token) { "mon-token" }
|
||||
let(:procedure) { create(:procedure, api_entreprise_token: token) }
|
||||
let(:payload) {
|
||||
[
|
||||
{ "exp" => expiration_time }
|
||||
]
|
||||
}
|
||||
let(:subject) { procedure.api_entreprise_token_expired? }
|
||||
|
||||
before do
|
||||
allow(JWT).to receive(:decode).with(token, nil, false).and_return(payload)
|
||||
end
|
||||
|
||||
context "with token expired" do
|
||||
let(:expiration_time) { (Time.zone.now - 1.day).to_i }
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context "with token not expired" do
|
||||
let(:expiration_time) { (Time.zone.now + 1.day).to_i }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'clone' do
|
||||
let!(:service) { create(:service) }
|
||||
let(:procedure) { create(:procedure, received_mail: received_mail, service: service) }
|
||||
|
|
|
@ -68,8 +68,9 @@ describe ApiEntrepriseService do
|
|||
let(:result) { ApiEntrepriseService.get_etablissement_params_for_siret(siret, procedure.id) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Procedure).to receive(:api_entreprise_roles)
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles)
|
||||
.and_return(["attestations_sociales", "attestations_fiscales", "bilans_entreprise_bdf"])
|
||||
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
|
||||
end
|
||||
|
||||
context 'when service is up' do
|
||||
|
|
|
@ -4,6 +4,7 @@ describe ExpiredDossiersDeletionService do
|
|||
let(:user) { create(:user) }
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
let(:procedure_2) { create(:procedure, :published) }
|
||||
let(:reference_date) { Date.parse("March 8") }
|
||||
|
||||
describe '#process_expired_dossiers_brouillon' do
|
||||
let(:today) { Time.zone.now.at_midnight }
|
||||
|
@ -43,7 +44,7 @@ describe ExpiredDossiersDeletionService do
|
|||
end
|
||||
|
||||
describe '#send_brouillon_expiration_notices' do
|
||||
before { Timecop.freeze(Time.zone.now) }
|
||||
before { Timecop.freeze(reference_date) }
|
||||
after { Timecop.return }
|
||||
|
||||
before do
|
||||
|
@ -83,7 +84,7 @@ describe ExpiredDossiersDeletionService do
|
|||
end
|
||||
|
||||
describe '#delete_expired_brouillons_and_notify' do
|
||||
before { Timecop.freeze(Time.zone.now) }
|
||||
before { Timecop.freeze(reference_date) }
|
||||
after { Timecop.return }
|
||||
|
||||
before do
|
||||
|
@ -131,7 +132,7 @@ describe ExpiredDossiersDeletionService do
|
|||
end
|
||||
|
||||
describe '#send_en_construction_expiration_notices' do
|
||||
before { Timecop.freeze(Time.zone.now) }
|
||||
before { Timecop.freeze(reference_date) }
|
||||
after { Timecop.return }
|
||||
|
||||
before do
|
||||
|
@ -202,7 +203,7 @@ describe ExpiredDossiersDeletionService do
|
|||
describe '#delete_expired_en_construction_and_notify' do
|
||||
let!(:warning_period) { 1.month + 5.days }
|
||||
|
||||
before { Timecop.freeze(Time.zone.now) }
|
||||
before { Timecop.freeze(reference_date) }
|
||||
after { Timecop.return }
|
||||
|
||||
before do
|
||||
|
@ -270,7 +271,7 @@ describe ExpiredDossiersDeletionService do
|
|||
end
|
||||
|
||||
describe '#send_termine_expiration_notices' do
|
||||
before { Timecop.freeze(Time.zone.now) }
|
||||
before { Timecop.freeze(reference_date) }
|
||||
after { Timecop.return }
|
||||
|
||||
before do
|
||||
|
@ -339,7 +340,7 @@ describe ExpiredDossiersDeletionService do
|
|||
end
|
||||
|
||||
describe '#delete_expired_termine_and_notify' do
|
||||
before { Timecop.freeze(Time.zone.now) }
|
||||
before { Timecop.freeze(reference_date) }
|
||||
after { Timecop.return }
|
||||
|
||||
before do
|
||||
|
|
Loading…
Reference in a new issue