Skip to content

Commit

Permalink
wip: test ci
Browse files Browse the repository at this point in the history
fix: resolve VCR cassette usage and sync GraphQL schema comparison

fix: increase field count

fix: add wait time for cassette taking too long

fix: add BASEROW_URL to Dockerfile

fix: add BASEROW_CONFIG_TABLE to Dockerfile

fix: add var to ci

fix: remove useless file

fix: env in ci

fix: increase max_wait_time of capybara due to slow DOM
  • Loading branch information
yhru committed Oct 24, 2024
1 parent 216dc07 commit 710944b
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 104 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
60 changes: 60 additions & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,61 @@ 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
selectedValue: 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 +4803,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
21 changes: 21 additions & 0 deletions app/graphql/types/champs/referentiel_de_polynesie_champ_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Types::Champs
class ReferentielDePolynesieChampType < Types::BaseObject
implements Types::ChampType

field :selected_value, String, null: true
field :table_id, ID, null: true
field :search_field, String, null: true

def selected_value
object.value
end

def table_id
object.table_id
end

def search_field
object.search_field
end
end
end
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
3 changes: 0 additions & 3 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ defaults: &defaults
userpwd: <%= ENV['CERTIGNA_USERPWD'] %>
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
2 changes: 1 addition & 1 deletion spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setup_driver(app, download_path, options)
setup_driver(app, download_path, options)
end

Capybara.default_max_wait_time = 4
Capybara.default_max_wait_time = 10

Capybara.ignore_hidden_elements = false

Expand Down
4 changes: 2 additions & 2 deletions spec/system/administrateurs/types_de_champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@
before { Flipper.enable(:referentiel_de_polynesie, administrateur.user) }

it "add referentiel_de_polynesie champ" do
VCR.use_cassette('baserow_api_available_tables', record: :new_episodes) do
VCR.use_cassette('baserow/baserow_api_available_tables', record: :new_episodes) do
add_champ

select('Referentiel De Polynesie', from: 'Type de champ')
select('Référentiel de Polynésie', from: 'Type de champ')
fill_in 'Libellé du champ', with: 'Libellé de champ Référentiel de Polynésie', fill_options: { clear: :backspace }

expect(page).to have_content('Formulaire enregistré')
Expand Down
Loading

0 comments on commit 710944b

Please sign in to comment.