Skip to content

Commit

Permalink
Merge pull request #32 from govpf/feature/ci_rdp
Browse files Browse the repository at this point in the history
fix: CI
  • Loading branch information
yhru authored Oct 28, 2024
2 parents 216dc07 + fc38f26 commit f34a70e
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 112 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ jobs:
timeout-minutes: 20
env:
RUBY_YJIT_ENABLE: "1"
API_BASEROW_URL: "https://api.baserow.io"
API_BASEROW_TOKEN: ${{ secrets.API_BASEROW_TOKEN }}
API_BASEROW_USER: ${{ secrets.API_BASEROW_USER }}
API_BASEROW_CONFIG_TABLE: "202600"
services:
postgres:
image: postgis/postgis:14-3.3
Expand Down Expand Up @@ -124,6 +128,10 @@ jobs:
timeout-minutes: 20
env:
RUBY_YJIT_ENABLE: "1"
API_BASEROW_URL: "https://api.baserow.io"
API_BASEROW_TOKEN: ${{ secrets.API_BASEROW_TOKEN }}
API_BASEROW_USER: ${{ secrets.API_BASEROW_USER }}
API_BASEROW_CONFIG_TABLE: "202600"
services:
postgres:
image: postgis/postgis:14-3.3
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ ENV \
WATERMARK_FILE="watermark_pf.png"\
WEASYPRINT_URL="http://weasyprint:5000/pdf"\
YAHOO_CLIENT_ID=""\
YAHOO_CLIENT_SECRET=""
YAHOO_CLIENT_SECRET=""\
API_BASEROW_URL="https://api.baserow.io"\
API_BASEROW_CONFIG_TABLE="202600"

COPY --chown=userapp:userapp . ${APP_PATH}
RUN rm -fr .git
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/api/v2/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def self.resolve_type(type_definition, object, ctx)
Types::Champs::TextChampType,
Types::Champs::TitreIdentiteChampType,
Types::Champs::VisaChampType,
Types::Champs::ReferentielDePolynesieChampType,
Types::Champs::EngagementJuridiqueChampType,
Types::GeoAreas::ParcelleCadastraleType,
Types::GeoAreas::SelectionUtilisateurType,
Expand Down Expand Up @@ -128,6 +129,7 @@ def self.resolve_type(type_definition, object, ctx)
Types::Champs::Descriptor::TextChampDescriptorType,
Types::Champs::Descriptor::TitreIdentiteChampDescriptorType,
Types::Champs::Descriptor::VisaChampDescriptorType,
Types::Champs::Descriptor::ReferentielDePolynesieChampDescriptorType,
Types::Champs::Descriptor::YesNoChampDescriptorType,
Types::Champs::Descriptor::ExpressionReguliereChampDescriptorType,
Types::Champs::Descriptor::EngagementJuridiqueChampDescriptorType
Expand Down
59 changes: 59 additions & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,60 @@ type RNFChampDescriptor implements ChampDescriptor {
type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.")
}

type ReferentielDePolynesieChamp implements Champ {
"""
L'identifiant du champDescriptor de ce champ
"""
champDescriptorId: String!
id: ID!

"""
Libellé du champ.
"""
label: String!
prefilled: Boolean!
searchField: String

"""
La valeur du champ sous forme texte.
"""
stringValue: String
tableId: ID

"""
Date de dernière modification du champ.
"""
updatedAt: ISO8601DateTime!
}

type ReferentielDePolynesieChampDescriptor implements ChampDescriptor {
"""
Description des champs d’un bloc répétable.
"""
champDescriptors: [ChampDescriptor!] @deprecated(reason: "Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.")

"""
Description du champ.
"""
description: String
id: ID!

"""
Libellé du champ.
"""
label: String!

"""
Est-ce que le champ est obligatoire ?
"""
required: Boolean!

"""
Type de la valeur du champ.
"""
type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.")
}

type Region {
code: String!
name: String!
Expand Down Expand Up @@ -4748,6 +4802,11 @@ enum TypeDeChamp {
"""
pole_emploi

"""
Référentiel de Polynésie
"""
referentiel_de_polynesie

"""
Régions
"""
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/champ_descriptor_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def resolve_type(object, context)
Types::Champs::Descriptor::TeFenuaChampDescriptorType
when TypeDeChamp.type_champs.fetch(:visa)
Types::Champs::Descriptor::VisaChampDescriptorType
when TypeDeChamp.type_champs.fetch(:referentiel_de_polynesie)
Types::Champs::Descriptor::ReferentielDePolynesieChampDescriptorType

# ----- DS champs
when TypeDeChamp.type_champs.fetch(:engagement_juridique)
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/champ_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def resolve_type(object, context)
Types::Champs::TitreIdentiteChampType
when ::Champs::VisaChamp
Types::Champs::VisaChampType
when ::Champs::ReferentielDePolynesieChamp
Types::Champs::ReferentielDePolynesieChampType
when ::Champs::EpciChamp
Types::Champs::EpciChampType
when ::Champs::RNAChamp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class ReferentielDePolynesieChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Types::Champs
class ReferentielDePolynesieChampType < Types::BaseObject
implements Types::ChampType

field :table_id, ID, null: true
field :search_field, String, null: true
end
end
6 changes: 3 additions & 3 deletions app/lib/referentiel_de_polynesie/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
class ReferentielDePolynesie::API
class << self
def available_tables
engine&.available_tables
engine&.available_tables || []
end

def search(domain_id, term)
engine&.search(domain_id, term)
engine&.search(domain_id, term) || []
end

def fetch_row(external_id)
table, id = external_id.split(':')
engine.fetch_row(table, id)
engine&.fetch_row(table, id) || {}
end

def engine
Expand Down
21 changes: 15 additions & 6 deletions app/lib/referentiel_de_polynesie/baserow_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ class << self

def search(domain_id, term)
config = config(domain_id)
return [] unless config
search_field = config['Champ de recherche']
params = { "filter__field_#{search_field}__contains" => term }
url = rows_url(config['Table'])
response = Typhoeus.get(url, headers: database_headers(config['Token']), params: params)
pp response
if response.success?
JSON.parse(response.body, symbolize_names: true)[:results].map do
{ name: _1[:"field_#{search_field}"], id: _1[:id], domain: domain_id }
end + [{ name: 'Autre', id: 0, domain: domain_id }]
begin
response = Typhoeus.get(url, headers: database_headers(config['Token']), params: params)
pp response
if response.success?
JSON.parse(response.body, symbolize_names: true)[:results].map do |result|
{ name: result[:"field_#{search_field}"], id: result[:id], domain: domain_id }
end + [{ name: 'Autre', id: 0, domain: domain_id }]
else
Rails.logger.error("Baserow API error: #{response.code} - #{response.body}")
[]
end
rescue Typhoeus::Errors::TyphoeusError => e
Rails.logger.error("Baserow API error: #{e.message}")
[]
end
end

Expand Down
3 changes: 3 additions & 0 deletions config/env.example
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ STRICT_EMAIL_VALIDATION_STARTS_ON="2024-02-19"
# Weasyprint endpoint generating attestations v2
# See https://github.com/demarches-simplifiees/weasyprint_server
WEASYPRINT_URL="http://127.0.0.1:5000/pdf"

API_BASEROW_URL="https://api.baserow.io"
API_BASEROW_CONFIG_TABLE="202600"
1 change: 1 addition & 0 deletions config/locales/models/type_de_champ/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fr:
numero_dn: 'Numéro DN'
te_fenua: 'Carte de Polynésie'
visa: 'Visa'
referentiel_de_polynesie: 'Référentiel de Polynésie'
header_section: 'Titre de section'
repetition: 'Bloc répétable'
dossier_link: 'Lien vers un autre dossier'
Expand Down
2 changes: 0 additions & 2 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ defaults: &defaults
baserow:
url: <%= ENV['API_BASEROW_URL'] %>
token: <%= ENV['API_BASEROW_TOKEN'] %>
user: <%= ENV['API_BASEROW_USER'] %>
config_table: <%= ENV['API_BASEROW_CONFIG_TABLE'] %>
password: "<%= ENV['API_BASEROW_PASSWORD'] %>"
autocomplete:
api_geo_url: <%= ENV['API_GEO_URL'] %>
api_adresse_url: <%= ENV['API_ADRESSE_URL'] %>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let(:procedure) { create(:procedure, :with_all_champs) }
let(:dossier) { create(:dossier, :with_populated_champs, procedure: procedure) }
let(:champ_repetition) { dossier.champs_public.find(&:repetition?) }
let(:champ_count) { 50 }
let(:champ_count) { 51 }

subject(:run_task) do
dossier
Expand All @@ -16,7 +16,9 @@
describe 'remove_unused_champs' do
it "with bad champs" do
expect(Champ.where(dossier: dossier).count).to eq(champ_count)

run_task

expect(Champ.where(dossier: dossier).count).to eq(champ_count - 1)
end
end
Expand Down
55 changes: 23 additions & 32 deletions spec/models/referentiel_de_polynesie/baserow_api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,72 +1,63 @@
require 'rails_helper'
require 'webmock/rspec'
require 'vcr'

RSpec.describe ReferentielDePolynesie::BaserowAPI, type: :model do
describe '#search' do
it 'search in a Baserow table and return the result', :vcr do
it 'searches in a Baserow table and returns the result', vcr: { cassette_name: 'baserow/baserow_search' } do
allow(ReferentielDePolynesie::BaserowAPI).to receive(:config).and_return({
'Table' => '202600',
'Champ de recherche' => 'search_field',
'Token' => ENV['API_BASEROW_TOKEN'].to_s
})

VCR.use_cassette('baserow_search') do
results = ReferentielDePolynesie::BaserowAPI.search(123, "term")
results = ReferentielDePolynesie::BaserowAPI.search(123, "term")

expect(results).to be_an(Array)
expect(results.length).to be > 0
expect(results.first).to have_key(:name)
expect(results.first).to have_key(:id)
end
expect(results).to be_an(Array)
expect(results.length).to be > 0
expect(results.first).to have_key(:name)
expect(results.first).to have_key(:id)
end
end

describe '#fetch_row' do
it 'fetch a specific line in a Baserow table', :vcr do
it 'fetches a specific line in a Baserow table', vcr: { cassette_name: 'baserow/baserow_fetch_row' } do
allow(ReferentielDePolynesie::BaserowAPI).to receive(:config).and_return({
'Table' => '202600',
'Token' => ENV['API_BASEROW_TOKEN'].to_s
})

VCR.use_cassette('baserow_fetch_row') do
result = ReferentielDePolynesie::BaserowAPI.fetch_row(123, 1)
result = ReferentielDePolynesie::BaserowAPI.fetch_row(123, 1)

expect(result[:row]["Nom"]).to eq("Communes de polynésie")
expect(result[:row]["Notes"]).to eq("")
expect(result[:row]["Actif"]).to eq(true)
expect(result[:row]["Table"]).to eq("202578")
expect(result[:row]["Champs usager"]).to eq("1391747,1391750,1391755,1391756")
expect(result[:row]["Champ de recherche"]).to eq("1391747")
expect(result[:row]["Champs instructeur"]).to eq("1391747,1391750,1391755,1391756")
end
expect(result[:row]["Nom"]).to eq("Communes de polynésie")
expect(result[:row]["Notes"]).to eq("")
expect(result[:row]["Actif"]).to eq(true)
expect(result[:row]["Table"]).to eq("202578")
expect(result[:row]["Champs usager"]).to eq("1391747,1391750,1391755,1391756")
expect(result[:row]["Champ de recherche"]).to eq("1391747")
expect(result[:row]["Champs instructeur"]).to eq("1391747,1391750,1391755,1391756")
end

it 'return a 404 error if the row does not exist', :vcr do
it 'returns a 404 error if the row does not exist', vcr: { cassette_name: 'baserow/baserow404_error' } do
allow(ReferentielDePolynesie::BaserowAPI).to receive(:config).and_return({
'Table' => '202600',
'Token' => ENV['API_BASEROW_TOKEN'].to_s
})

VCR.use_cassette('baserow404_error') do
results = ReferentielDePolynesie::BaserowAPI.fetch_row(123, 99999)
results = ReferentielDePolynesie::BaserowAPI.fetch_row(123, 99999)

expect(results).to eq(nil)
end
expect(results).to eq(nil)
end
end

describe '#available_tables' do
it 'fetch the available tables', :vcr do
it 'fetches the available tables', vcr: { cassette_name: 'baserow/baserow_api_available_tables' } do
allow(ReferentielDePolynesie::BaserowAPI).to receive(:config)

VCR.use_cassette('baserow_available_tables') do
results = ReferentielDePolynesie::BaserowAPI.available_tables
results = ReferentielDePolynesie::BaserowAPI.available_tables

expect(results).to be_an(Array)
expect(results.first[:name]).to eq("Communes de polynésie")
expect(results.first[:id]).to eq(1)
end
expect(results).to be_an(Array)
expect(results.first[:name]).to eq("Communes de polynésie")
expect(results.first[:id]).to eq(1)
end
end
end
7 changes: 0 additions & 7 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@
end
end

VCR.configure do |config|
config.cassette_library_dir = 'spec/vcr_cassettes'
config.hook_into :webmock
config.configure_rspec_metadata!
config.allow_http_connections_when_no_cassette = false
end

config.include ActiveSupport::Testing::TimeHelpers
config.include Shoulda::Matchers::ActiveRecord, type: :model
config.include Shoulda::Matchers::ActiveModel, type: :model
Expand Down
Loading

0 comments on commit f34a70e

Please sign in to comment.