From b5f7be59016209457fa517c55bab396c9bbfd480 Mon Sep 17 00:00:00 2001 From: "maxim.joseau" Date: Wed, 16 Oct 2024 15:16:40 +0200 Subject: [PATCH 1/7] wip: refactor table_row_selector to referentiel_de_polynesie --- Gemfile.lock | 6 +- .../champs_rows_show_component.html.haml | 4 +- .../referentiel_de_polynesie.rb | 12 ++ ...ferentiel_de_polynesie_component.html.haml | 7 + .../table_row_selector_component.rb | 20 +-- .../table_row_selector_component.html.haml | 12 +- .../champ_component/champ_component.html.haml | 2 +- .../referentiel_de_polynesie_controller.rb | 20 +++ .../champs/table_row_selector_controller.rb | 32 ++--- .../ComboReferentielDePolynesieSearch.tsx.tsx | 32 +++++ .../ComboTableRowSelectorSearch.tsx | 56 ++++---- .../components/shared/queryClient.ts | 4 +- app/lib/referentiel_de_polynesie/api.rb | 22 +++ .../referentiel_de_polynesie/baserow_api.rb | 86 ++++++++++++ app/lib/table_row_selector/api.rb | 4 +- app/lib/table_row_selector/api_old.rb | 22 +++ app/lib/table_row_selector/baserow_api.rb | 2 +- .../champs/referentiel_de_polynesie_champ.rb | 16 +++ app/models/champs/table_row_selector_champ.rb | 26 ++-- app/models/logic/champ_value.rb | 10 +- app/models/type_de_champ.rb | 19 ++- .../referentiel_de_polynesie_type_de_champ.rb | 4 + .../table_row_selector_type_de_champ.rb | 4 - config/initializers/flipper.rb | 3 +- config/locales/shared.en.yml | 2 +- config/locales/shared.fr.yml | 2 +- config/routes.rb | 2 +- spec/factories/type_de_champ.rb | 3 + .../baserow_api_spec.rb | 72 ++++++++++ .../table_row_selector/baserow_api_spec.rb | 131 ++++++++++-------- spec/support/capybara.rb | 4 +- .../administrateurs/types_de_champ_spec.rb | 19 +++ spec/vcr_cassettes/baserow404_error.yml | 49 +++++++ .../baserow_available_tables.yml | 4 +- spec/vcr_cassettes/baserow_fetch_row.yml | 8 +- spec/vcr_cassettes/baserow_search.yml | 4 +- 36 files changed, 554 insertions(+), 171 deletions(-) create mode 100644 app/components/editable_champ/referentiel_de_polynesie.rb create mode 100644 app/components/editable_champ/referentiel_de_polynesie_component/referentiel_de_polynesie_component.html.haml create mode 100644 app/controllers/champs/referentiel_de_polynesie_controller.rb create mode 100644 app/javascript/components/ComboReferentielDePolynesieSearch.tsx.tsx create mode 100644 app/lib/referentiel_de_polynesie/api.rb create mode 100644 app/lib/referentiel_de_polynesie/baserow_api.rb create mode 100644 app/lib/table_row_selector/api_old.rb create mode 100644 app/models/champs/referentiel_de_polynesie_champ.rb create mode 100644 app/models/types_de_champ/referentiel_de_polynesie_type_de_champ.rb delete mode 100644 app/models/types_de_champ/table_row_selector_type_de_champ.rb create mode 100644 spec/models/referentiel_de_polynesie/baserow_api_spec.rb create mode 100644 spec/vcr_cassettes/baserow404_error.yml diff --git a/Gemfile.lock b/Gemfile.lock index 4e8faecdfbe..6b64abdb40e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -462,6 +462,7 @@ GEM rake mini_magick (4.12.0) mini_mime (1.1.5) + mini_portile2 (2.8.6) minitest (5.23.0) msgpack (1.7.2) multi_json (1.15.0) @@ -479,9 +480,10 @@ GEM net-smtp (0.5.0) net-protocol nio4r (2.7.3) - nokogiri (1.16.5-x86_64-darwin) + nokogiri (1.16.5) + mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.16.5-x86_64-linux) + nokogiri (1.16.5-x86_64-darwin) racc (~> 1.4) openid_connect (2.3.0) activemodel diff --git a/app/components/dossiers/champs_rows_show_component/champs_rows_show_component.html.haml b/app/components/dossiers/champs_rows_show_component/champs_rows_show_component.html.haml index fafbc29807e..3127c4a3e7a 100644 --- a/app/components/dossiers/champs_rows_show_component/champs_rows_show_component.html.haml +++ b/app/components/dossiers/champs_rows_show_component/champs_rows_show_component.html.haml @@ -56,8 +56,8 @@ = render partial: "shared/champs/te_fenua/show", locals: { champ: champ, profile: @profile } - when TypeDeChamp.type_champs.fetch(:numero_dn) = render partial: "shared/champs/numero_dn/show", locals: { champ: champ, profile: @profile } - - when TypeDeChamp.type_champs.fetch(:table_row_selector) - = render partial: "shared/champs/table_row_selector/show", locals: { champ: champ, profile: @profile } + - when TypeDeChamp.type_champs.fetch(:referentiel_de_polynesie) + = render partial: "shared/champs/referentiel_de_polynesie/show", locals: { champ: champ, profile: @profile } - when TypeDeChamp.type_champs.fetch(:cojo) = render partial: "shared/champs/cojo/show", locals: { champ: champ, profile: @profile } - when TypeDeChamp.type_champs.fetch(:date) diff --git a/app/components/editable_champ/referentiel_de_polynesie.rb b/app/components/editable_champ/referentiel_de_polynesie.rb new file mode 100644 index 00000000000..d832050fc7a --- /dev/null +++ b/app/components/editable_champ/referentiel_de_polynesie.rb @@ -0,0 +1,12 @@ +class EditableChamp::ReferentielDePolynesie < EditableChamp::ComboSearchComponent + def dsfr_input_classname + 'fr-input' + end + + def react_input_opts + opts = input_opts(id: @champ.input_id, required: @champ.required?, aria: { describedby: @champ.describedby_id }, scopeExtra: @champ.table_id) + opts[:className] = "#{opts.delete(:class)} fr-mt-1w" + + opts + end +end diff --git a/app/components/editable_champ/referentiel_de_polynesie_component/referentiel_de_polynesie_component.html.haml b/app/components/editable_champ/referentiel_de_polynesie_component/referentiel_de_polynesie_component.html.haml new file mode 100644 index 00000000000..8bb52823954 --- /dev/null +++ b/app/components/editable_champ/referentiel_de_polynesie_component/referentiel_de_polynesie_component.html.haml @@ -0,0 +1,7 @@ +- render_parent + += @form.hidden_field :value += @form.hidden_field :external_id += react_component("ComboReferentielDePolynesieSearch", + **react_input_opts, + **react_combo_props) diff --git a/app/components/editable_champ/table_row_selector_component.rb b/app/components/editable_champ/table_row_selector_component.rb index db834f21224..35f4bf840da 100644 --- a/app/components/editable_champ/table_row_selector_component.rb +++ b/app/components/editable_champ/table_row_selector_component.rb @@ -1,12 +1,12 @@ -class EditableChamp::TableRowSelectorComponent < EditableChamp::ComboSearchComponent - def dsfr_input_classname - 'fr-input' - end +# class EditableChamp::TableRowSelectorComponent < EditableChamp::ComboSearchComponent +# def dsfr_input_classname +# 'fr-input' +# end - def react_input_opts - opts = input_opts(id: @champ.input_id, required: @champ.required?, aria: { describedby: @champ.describedby_id }, scopeExtra: @champ.table_id) - opts[:className] = "#{opts.delete(:class)} fr-mt-1w" +# def react_input_opts +# opts = input_opts(id: @champ.input_id, required: @champ.required?, aria: { describedby: @champ.describedby_id }, scopeExtra: @champ.table_id) +# opts[:className] = "#{opts.delete(:class)} fr-mt-1w" - opts - end -end +# opts +# end +# end diff --git a/app/components/editable_champ/table_row_selector_component/table_row_selector_component.html.haml b/app/components/editable_champ/table_row_selector_component/table_row_selector_component.html.haml index 318537126de..812b52f8e3b 100644 --- a/app/components/editable_champ/table_row_selector_component/table_row_selector_component.html.haml +++ b/app/components/editable_champ/table_row_selector_component/table_row_selector_component.html.haml @@ -1,7 +1,7 @@ -- render_parent +-# - render_parent -= @form.hidden_field :value -= @form.hidden_field :external_id -= react_component("ComboTableRowSelectorSearch", - **react_input_opts, - **react_combo_props) +-# = @form.hidden_field :value +-# = @form.hidden_field :external_id +-# = react_component("ComboTableRowSelectorSearch", +-# **react_input_opts, +-# **react_combo_props) diff --git a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml index 2a8ed91768e..018ad3a3fae 100644 --- a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml +++ b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml @@ -103,7 +103,7 @@ .cell.width-100 = form.label :accredited_user_string, "Mails des personnes accréditées", for: dom_id(type_de_champ, :accredited_user_string) = form.text_area :accredited_user_string, class: 'fr-input small-margin small', rows: 7, id: dom_id(type_de_champ, :accredited_user_string), placeholder: 'Ecrire un email par ligne' - - if type_de_champ.table_row_selector? + - if type_de_champ.referentiel_de_polynesie? .flex.width-33 .flex.column.flex-grow.justify-start .cell.width-100 diff --git a/app/controllers/champs/referentiel_de_polynesie_controller.rb b/app/controllers/champs/referentiel_de_polynesie_controller.rb new file mode 100644 index 00000000000..58154270fae --- /dev/null +++ b/app/controllers/champs/referentiel_de_polynesie_controller.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class Champs::ReferentielDePolynesieController < ApplicationController + before_action :authenticate_logged_user! + + def search + @params = search_params + if bad_parameters + render json: [], status: 400 + else + render json: ReferentielDePolynesie::API.search(@params[:domain], @params[:term]) + end + end + + def bad_parameters + @params[:domain].blank? || @params[:domain].to_i == 0 || @params[:term].blank? + end + + def search_params = params.permit(:domain, :term) +end diff --git a/app/controllers/champs/table_row_selector_controller.rb b/app/controllers/champs/table_row_selector_controller.rb index 1ec76fd85ff..4154a953ec8 100644 --- a/app/controllers/champs/table_row_selector_controller.rb +++ b/app/controllers/champs/table_row_selector_controller.rb @@ -1,20 +1,20 @@ -# frozen_string_literal: true +# # frozen_string_literal: true -class Champs::TableRowSelectorController < ApplicationController - before_action :authenticate_logged_user! +# class Champs::TableRowSelectorController < ApplicationController +# before_action :authenticate_logged_user! - def search - @params = search_params - if bad_parameters - render json: [], status: 400 - else - render json: TableRowSelector::API.search(@params[:domain], @params[:term]) - end - end +# def search +# @params = search_params +# if bad_parameters +# render json: [], status: 400 +# else +# render json: TableRowSelector::API.search(@params[:domain], @params[:term]) +# end +# end - def bad_parameters - @params[:domain].blank? || @params[:domain].to_i == 0 || @params[:term].blank? - end +# def bad_parameters +# @params[:domain].blank? || @params[:domain].to_i == 0 || @params[:term].blank? +# end - def search_params = params.permit(:domain, :term) -end +# def search_params = params.permit(:domain, :term) +# end diff --git a/app/javascript/components/ComboReferentielDePolynesieSearch.tsx.tsx b/app/javascript/components/ComboReferentielDePolynesieSearch.tsx.tsx new file mode 100644 index 00000000000..37ad61c7816 --- /dev/null +++ b/app/javascript/components/ComboReferentielDePolynesieSearch.tsx.tsx @@ -0,0 +1,32 @@ +import React from 'react'; +import { QueryClientProvider } from 'react-query'; + +import ComboSearch, { ComboSearchProps } from './ComboSearch'; +import { queryClient } from './shared/queryClient'; + +type ReferentielDePolynesieResult = { + name: string; + id: string; + domain: string; +}; + +function transformResults(_: unknown, result: unknown) { + return result as ReferentielDePolynesieResult[]; +} + +export default function ComboReferentielDePolynesieResultSearch( + props: ComboSearchProps +) { + return ( + + [`${domain}:${id}`, name]} + /> + + ); +} diff --git a/app/javascript/components/ComboTableRowSelectorSearch.tsx b/app/javascript/components/ComboTableRowSelectorSearch.tsx index 86df683a21b..0fbe562ec22 100644 --- a/app/javascript/components/ComboTableRowSelectorSearch.tsx +++ b/app/javascript/components/ComboTableRowSelectorSearch.tsx @@ -1,32 +1,32 @@ -import React from 'react'; -import { QueryClientProvider } from 'react-query'; +// import React from 'react'; +// import { QueryClientProvider } from 'react-query'; -import ComboSearch, { ComboSearchProps } from './ComboSearch'; -import { queryClient } from './shared/queryClient'; +// import ComboSearch, { ComboSearchProps } from './ComboSearch'; +// import { queryClient } from './shared/queryClient'; -type TableRowSelectorResult = { - name: string; - id: string; - domain: string; -}; +// type TableRowSelectorResult = { +// name: string; +// id: string; +// domain: string; +// }; -function transformResults(_: unknown, result: unknown) { - return result as TableRowSelectorResult[]; -} +// function transformResults(_: unknown, result: unknown) { +// return result as TableRowSelectorResult[]; +// } -export default function ComboTableRowSelectorSearch( - props: ComboSearchProps -) { - return ( - - [`${domain}:${id}`, name]} - /> - - ); -} +// export default function ComboTableRowSelectorSearch( +// props: ComboSearchProps +// ) { +// return ( +// +// [`${domain}:${id}`, name]} +// /> +// +// ); +// } diff --git a/app/javascript/components/shared/queryClient.ts b/app/javascript/components/shared/queryClient.ts index 1a60257394c..44b188724c5 100644 --- a/app/javascript/components/shared/queryClient.ts +++ b/app/javascript/components/shared/queryClient.ts @@ -24,8 +24,8 @@ function buildURL(scope: string, term: string, extra: string) { params.set('q', term); params.set('rows', `${API_EDUCATION_QUERY_LIMIT}`); params.set('dataset', 'fr-en-annuaire-education'); - } else if (scope == 'table-row-selector') { - path = '/champs/table_row_selector/search'; + } else if (scope == 'referentiel-de-polynesie') { + path = '/champs/referentiel_de_polynesie/search'; params.set('domain', extra); params.set('term', term); } diff --git a/app/lib/referentiel_de_polynesie/api.rb b/app/lib/referentiel_de_polynesie/api.rb new file mode 100644 index 00000000000..89f78bc9bc0 --- /dev/null +++ b/app/lib/referentiel_de_polynesie/api.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class ReferentielDePolynesie::API + class << self + def available_tables + engine&.available_tables + end + + def 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) + end + + def engine + @engine ||= ENV['API_BASEROW_URL'].present? ? ReferentielDePolynesie::BaserowAPI : nil + end + end +end diff --git a/app/lib/referentiel_de_polynesie/baserow_api.rb b/app/lib/referentiel_de_polynesie/baserow_api.rb new file mode 100644 index 00000000000..7063dd8951b --- /dev/null +++ b/app/lib/referentiel_de_polynesie/baserow_api.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +class ReferentielDePolynesie::BaserowAPI + class << self + SECRETS = Rails.application.secrets.baserow + + def search(domain_id, term) + config = config(domain_id) + 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 }] + end + end + + def available_tables + response = Typhoeus.get(rows_url(SECRETS[:config_table]), headers: config_database_headers, params: default_params) + if response.success? + JSON.parse(response.body, symbolize_names: true)[:results]&.filter { _1[:Actif] }&.map do + { name: _1[:Nom], id: _1[:id] } + end + end + end + + def fetch_row(domain_id, row) + return {} if row.to_i.zero? + + config = config(domain_id) + response = Typhoeus.get(row_url(config['Table'], row), headers: database_headers(config['Token'])) + if response.success? + model = fields(config) + usager_fields = field_names(model, config['Champs usager']) + instructeur_fields = field_names(model, config['Champs instructeur']) + row = JSON.parse(response.body).filter { |name, _| name.start_with?('field_') }.transform_keys do |key| + model[key[6..-1].to_i] + end + { usager_fields:, instructeur_fields:, row: } + end + end + + def field_names(model, field_ids) + field_ids&.split(/,/)&.map(&:strip)&.map { model[_1.to_i] } || [] + end + + def config(row_id) + response = Typhoeus.get(row_url(SECRETS[:config_table], row_id), headers: config_database_headers, params: default_params) + response.success? ? JSON.parse(response.body) : nil + end + + def fields(config) + response = Typhoeus.get(list_database_table_fields(config['Table']), headers: database_headers(config['Token'])) + if response.success? + JSON.parse(response.body).map { [_1['id'], _1['name']] }.to_h + end + end + + def rows_url(table_id) = "#{SECRETS[:url]}/api/database/rows/table/#{table_id}/" + + def row_url(table_id, row_id) = "#{rows_url(table_id)}#{row_id}/" + + def list_database_table_fields(table_id) = "#{SECRETS[:url]}/api/database/fields/table/#{table_id}/" + + def config_database_headers = database_headers(SECRETS[:token]) + + def database_headers(token) = { 'Authorization' => "Token #{token}" } + + def default_params = { user_field_names: true } + + JWT_URL = "#{SECRETS[:url]}/api/user/token-auth/" + MUTEX = Mutex.new + + def meta_headers + credentials = { username: SECRETS[:user], password: SECRETS[:password] } + response = Typhoeus.post(JWT_URL, body: credentials) + if response.success? + jwt = JSON.parse(response.body)['token'] + { authorization: "JWT #{jwt}" } + end + end + end +end diff --git a/app/lib/table_row_selector/api.rb b/app/lib/table_row_selector/api.rb index 6a17cbbf345..89f78bc9bc0 100644 --- a/app/lib/table_row_selector/api.rb +++ b/app/lib/table_row_selector/api.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class TableRowSelector::API +class ReferentielDePolynesie::API class << self def available_tables engine&.available_tables @@ -16,7 +16,7 @@ def fetch_row(external_id) end def engine - @engine ||= ENV['API_BASEROW_URL'].present? ? TableRowSelector::BaserowAPI : nil + @engine ||= ENV['API_BASEROW_URL'].present? ? ReferentielDePolynesie::BaserowAPI : nil end end end diff --git a/app/lib/table_row_selector/api_old.rb b/app/lib/table_row_selector/api_old.rb new file mode 100644 index 00000000000..84aeb2bc785 --- /dev/null +++ b/app/lib/table_row_selector/api_old.rb @@ -0,0 +1,22 @@ +# # frozen_string_literal: true + +# class TableRowSelector::API +# class << self +# def available_tables +# engine&.available_tables +# end + +# def 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) +# end + +# def engine +# @engine ||= ENV['API_BASEROW_URL'].present? ? TableRowSelector::BaserowAPI : nil +# end +# end +# end diff --git a/app/lib/table_row_selector/baserow_api.rb b/app/lib/table_row_selector/baserow_api.rb index 4e9b0ec51fc..7063dd8951b 100644 --- a/app/lib/table_row_selector/baserow_api.rb +++ b/app/lib/table_row_selector/baserow_api.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class TableRowSelector::BaserowAPI +class ReferentielDePolynesie::BaserowAPI class << self SECRETS = Rails.application.secrets.baserow diff --git a/app/models/champs/referentiel_de_polynesie_champ.rb b/app/models/champs/referentiel_de_polynesie_champ.rb new file mode 100644 index 00000000000..1b003f66ecb --- /dev/null +++ b/app/models/champs/referentiel_de_polynesie_champ.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class Champs::ReferentielDePolynesieChamp < Champs::TextChamp + def fetch_external_data? + true + end + + def fetch_external_data + # APIEducation::AnnuaireEducationAdapter.new(external_id).to_params + ReferentielDePolynesie::API.fetch_row(external_id) + end + + def update_with_external_data!(data:) + update!(data: data) if data&.is_a?(Hash) + end +end diff --git a/app/models/champs/table_row_selector_champ.rb b/app/models/champs/table_row_selector_champ.rb index 83ddef28877..1779453fb96 100644 --- a/app/models/champs/table_row_selector_champ.rb +++ b/app/models/champs/table_row_selector_champ.rb @@ -1,16 +1,16 @@ -# frozen_string_literal: true +# # frozen_string_literal: true -class Champs::TableRowSelectorChamp < Champs::TextChamp - def fetch_external_data? - true - end +# class Champs::TableRowSelectorChamp < Champs::TextChamp +# def fetch_external_data? +# true +# end - def fetch_external_data - # APIEducation::AnnuaireEducationAdapter.new(external_id).to_params - TableRowSelector::API.fetch_row(external_id) - end +# def fetch_external_data +# # APIEducation::AnnuaireEducationAdapter.new(external_id).to_params +# TableRowSelector::API.fetch_row(external_id) +# end - def update_with_external_data!(data:) - update!(data: data) if data&.is_a?(Hash) - end -end +# def update_with_external_data!(data:) +# update!(data: data) if data&.is_a?(Hash) +# end +# end diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb index e5618a64d54..c053ee91980 100644 --- a/app/models/logic/champ_value.rb +++ b/app/models/logic/champ_value.rb @@ -1,5 +1,5 @@ class Logic::ChampValue < Logic::Term - INSTANCE_MANAGED_TYPE_DE_CHAMP = [:table_row_selector] + INSTANCE_MANAGED_TYPE_DE_CHAMP = [:referentiel_de_polynesie] MANAGED_TYPE_DE_CHAMP = TypeDeChamp.type_champs.slice( *INSTANCE_MANAGED_TYPE_DE_CHAMP, @@ -71,7 +71,9 @@ def compute(champs) code_departement: targeted_champ.code_departement, code_region: targeted_champ.code_region } - when "Champs::TableRowSelectorChamp" + # when "Champs::TableRowSelectorChamp" + # targeted_champ.value + when "Champs::ReferentielDePolynesieChamp" targeted_champ.value when "Champs::CommuneDePolynesieChamp", "Champs::CodePostalDePolynesieChamp" { @@ -104,7 +106,7 @@ def type(type_de_champs) CHAMP_VALUE_TYPE.fetch(:departement_enum) when MANAGED_TYPE_DE_CHAMP.fetch(:multiple_drop_down_list) CHAMP_VALUE_TYPE.fetch(:enums) - when MANAGED_TYPE_DE_CHAMP.fetch(:table_row_selector) + when MANAGED_TYPE_DE_CHAMP.fetch(:referentiel_de_polynesie) CHAMP_VALUE_TYPE.fetch(:enum) else CHAMP_VALUE_TYPE.fetch(:unmanaged) @@ -143,7 +145,7 @@ def options(type_de_champs, operator_name = nil) APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] } elsif operator_name.in?([Logic::InArchipelOperator.name, Logic::NotInArchipelOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:commune_de_polynesie), MANAGED_TYPE_DE_CHAMP.fetch(:code_postal_de_polynesie)]) APIGeo::API.archipels_de_polynesie.map { [_1, _1] } - elsif tdc.type_champ == MANAGED_TYPE_DE_CHAMP.fetch(:table_row_selector) + elsif tdc.type_champ == MANAGED_TYPE_DE_CHAMP.fetch(:referentiel_de_polynesie) [['Autre', 'Autre']] else tdc.drop_down_list_enabled_non_empty_options(other: true).map { _1.is_a?(Array) ? _1 : [_1, _1] } diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index c793d9803f5..b8b1fbf70ae 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -4,9 +4,9 @@ class TypeDeChamp < ApplicationRecord FILE_MAX_SIZE = 200.megabytes FEATURE_FLAGS = { visa: :visa, + referentiel_de_polynesie: :referentiel_de_polynesie, tefenua: :tefenua, engagement_juridique: :engagement_juridique_type_de_champ, - cojo: :cojo_type_de_champ, expression_reguliere: :expression_reguliere_type_de_champ } @@ -18,7 +18,8 @@ class TypeDeChamp < ApplicationRecord commune_de_polynesie: 'commune_de_polynesie', code_postal_de_polynesie: 'code_postal_de_polynesie', numero_dn: 'numero_dn', - table_row_selector: 'table_row_selector', + # referentiel_de_polynesie: 'referentiel_de_polynesie', + referentiel_de_polynesie: 'referentiel_de_polynesie', te_fenua: 'te_fenua', visa: 'visa' } @@ -40,7 +41,7 @@ class TypeDeChamp < ApplicationRecord code_postal_de_polynesie: LOCALISATION, numero_dn: REFERENTIEL_EXTERNE, te_fenua: REFERENTIEL_EXTERNE, - table_row_selector: REFERENTIEL_EXTERNE, + referentiel_de_polynesie: REFERENTIEL_EXTERNE, visa: STRUCTURE } @@ -463,8 +464,8 @@ def visa? type_champ == TypeDeChamp.type_champs.fetch(:visa) end - def table_row_selector? - type_champ == TypeDeChamp.type_champs.fetch(:table_row_selector) + def referentiel_de_polynesie? + type_champ == TypeDeChamp.type_champs.fetch(:referentiel_de_polynesie) end def te_fenua? @@ -669,8 +670,12 @@ def accredited_user_list accredited_users.presence || [] end + # def available_tables + # TableRowSelector::API.available_tables.map { [_1[:name], _1[:id]] } + # end + def available_tables - TableRowSelector::API.available_tables.map { [_1[:name], _1[:id]] } + ReferentielDePolynesie::API.available_tables.map { [_1[:name], _1[:id]] } end def to_typed_id @@ -732,7 +737,7 @@ def self.refresh_after_update?(type_champ) type_champs.fetch(:siret), type_champs.fetch(:numero_dn), type_champs.fetch(:te_fenua), - type_champs.fetch(:table_row_selector) + type_champs.fetch(:referentiel_de_polynesie) false else true diff --git a/app/models/types_de_champ/referentiel_de_polynesie_type_de_champ.rb b/app/models/types_de_champ/referentiel_de_polynesie_type_de_champ.rb new file mode 100644 index 00000000000..8aaf14e581d --- /dev/null +++ b/app/models/types_de_champ/referentiel_de_polynesie_type_de_champ.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class TypesDeChamp::ReferentielDePolynesieTypeDeChamp < TypesDeChamp::TypeDeChampBase +end diff --git a/app/models/types_de_champ/table_row_selector_type_de_champ.rb b/app/models/types_de_champ/table_row_selector_type_de_champ.rb deleted file mode 100644 index 61059883c99..00000000000 --- a/app/models/types_de_champ/table_row_selector_type_de_champ.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -class TypesDeChamp::TableRowSelectorTypeDeChamp < TypesDeChamp::TypeDeChampBase -end diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb index 053de3b119b..911067c50d7 100644 --- a/config/initializers/flipper.rb +++ b/config/initializers/flipper.rb @@ -29,7 +29,8 @@ def setup_features(features) :qrcoded_pdf, :sva, :switch_domain, - :visa + :visa, + :referentiel_de_polynesie ] def database_exists? diff --git a/config/locales/shared.en.yml b/config/locales/shared.en.yml index 0ff5d5d1271..db27fbe01ee 100644 --- a/config/locales/shared.en.yml +++ b/config/locales/shared.en.yml @@ -17,7 +17,7 @@ en: refuse: "Expires on %{date} (%{duree_conservation_totale} months after this file was processed)" sans_suite: "Expires on %{date} (%{duree_conservation_totale} months after this file was processed)" champs: - table_row_selector: + referentiel_de_polynesie: show: toggle_champ: "Show/hide fields of « %{champ} »" cnaf: diff --git a/config/locales/shared.fr.yml b/config/locales/shared.fr.yml index 27a84a81306..adde4361a75 100644 --- a/config/locales/shared.fr.yml +++ b/config/locales/shared.fr.yml @@ -19,7 +19,7 @@ fr: champs: - table_row_selector: + referentiel_de_polynesie: show: toggle_champ: "Afficher/Cacher les champs de « %{champ} »" cnaf: diff --git a/config/routes.rb b/config/routes.rb index cba04bb8e34..5b8176ba4df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -204,7 +204,7 @@ post ':dossier_id/:stable_id/repetition', to: 'repetition#add', as: :repetition delete ':dossier_id/:stable_id/repetition', to: 'repetition#remove' - get 'table_row_selector/search', to: 'table_row_selector#search' + get 'referentiel_de_polynesie/search', to: 'referentiel_de_polynesie#search' get ':dossier_id/:stable_id/siret', to: 'siret#show', as: :siret get ':dossier_id/:stable_id/rna', to: 'rna#show', as: :rna diff --git a/spec/factories/type_de_champ.rb b/spec/factories/type_de_champ.rb index 1e2bd8509ea..304cb77b41b 100644 --- a/spec/factories/type_de_champ.rb +++ b/spec/factories/type_de_champ.rb @@ -199,6 +199,9 @@ factory :type_de_champ_visa do type_champ { TypeDeChamp.type_champs.fetch(:visa) } end + factory :type_de_champ_referentiel_de_polynesie do + type_champ { TypeDeChamp.type_champs.fetch(:referentiel_de_polynesie) } + end factory :type_de_champ_epci do type_champ { TypeDeChamp.type_champs.fetch(:epci) } end diff --git a/spec/models/referentiel_de_polynesie/baserow_api_spec.rb b/spec/models/referentiel_de_polynesie/baserow_api_spec.rb new file mode 100644 index 00000000000..fe0e46682ac --- /dev/null +++ b/spec/models/referentiel_de_polynesie/baserow_api_spec.rb @@ -0,0 +1,72 @@ +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 + 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") + + 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 + end + + describe '#fetch_row' do + it 'fetch a specific line in a Baserow table', :vcr 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) + + 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 + end + + it 'return a 404 error if the row does not exist', :vcr 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) + + expect(results).to eq(nil) + end + end + end + + describe '#available_tables' do + it 'fetch the available tables', :vcr do + allow(ReferentielDePolynesie::BaserowAPI).to receive(:config) + + VCR.use_cassette('baserow_available_tables') do + 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 + end + end +end diff --git a/spec/models/table_row_selector/baserow_api_spec.rb b/spec/models/table_row_selector/baserow_api_spec.rb index 1da58537dac..36028e53801 100644 --- a/spec/models/table_row_selector/baserow_api_spec.rb +++ b/spec/models/table_row_selector/baserow_api_spec.rb @@ -1,59 +1,72 @@ -require 'rails_helper' -require 'webmock/rspec' -require 'vcr' - -RSpec.describe TableRowSelector::BaserowAPI, type: :model do - describe '#search' do - it 'search in a Baserow table and return the result', :vcr do - allow(TableRowSelector::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 = TableRowSelector::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 - end - end - - describe '#fetch_row' do - it 'fetch a specific line in a Baserow table', :vcr do - allow(TableRowSelector::BaserowAPI).to receive(:config).and_return({ - 'Table' => '202600', - 'Token' => ENV['API_BASEROW_TOKEN'].to_s - }) - - VCR.use_cassette('baserow_fetch_row') do - result = TableRowSelector::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 - end - end - - describe '#available_tables' do - it 'fetch the available tables', :vcr do - allow(TableRowSelector::BaserowAPI).to receive(:config) - - VCR.use_cassette('baserow_available_tables') do - results = TableRowSelector::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 - end - end -end +# 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 +# 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") + +# 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 +# end + +# describe '#fetch_row' do +# it 'fetch a specific line in a Baserow table', :vcr 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) + +# 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 +# end + +# it 'return a 404 error if the row does not exist', :vcr 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) + +# expect(results).to eq(nil) +# end +# end +# end + +# describe '#available_tables' do +# it 'fetch the available tables', :vcr do +# allow(ReferentielDePolynesie::BaserowAPI).to receive(:config) + +# VCR.use_cassette('baserow_available_tables') do +# 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 +# end +# end +# end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index a29cf8eb7c7..6f42891acab 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -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 = 1 Capybara.ignore_hidden_elements = false @@ -64,7 +64,7 @@ def setup_driver(app, download_path, options) Capybara.disable_animation = true # Save a snapshot of the HTML page when an integration test fails -Capybara::Screenshot.autosave_on_failure = true +Capybara::Screenshot.autosave_on_failure = false # Keep only the screenshots generated from the last failing test suite Capybara::Screenshot.prune_strategy = :keep_last_run # Tell Capybara::Screenshot how to take screenshots when using the headless_chrome driver diff --git a/spec/system/administrateurs/types_de_champ_spec.rb b/spec/system/administrateurs/types_de_champ_spec.rb index 03f1a4c62fb..1a1867a2958 100644 --- a/spec/system/administrateurs/types_de_champ_spec.rb +++ b/spec/system/administrateurs/types_de_champ_spec.rb @@ -206,6 +206,25 @@ end end + context 'referentiel_de_polynesie enabled' do + before { Flipper.enable(:referentiel_de_polynesie, administrateur.user) } + + it "add referentiel_de_polynesie champ" do + add_champ + + select('Referentiel De Polynesie', from: 'Type de champ') + fill_in 'Libellé du champ', with: 'Libellé de champ referentiel de Polynesie', fill_options: { clear: :baskspace } + + expect(page).to have_content('Formulaire enregistré') + + waint_until { procedure.draft_types_de_champ_public.first.libelle == 'Libellé du champ référentiel de Polynesie' } + + page.refresh + + expect(page).to have_content('Libellé de champ referentiel de polynesie') + end + end + context "estimated duration visible" do scenario "displaying the estimated fill duration" do # It doesn't display anything when there are no champs diff --git a/spec/vcr_cassettes/baserow404_error.yml b/spec/vcr_cassettes/baserow404_error.yml new file mode 100644 index 00000000000..044b5792f5e --- /dev/null +++ b/spec/vcr_cassettes/baserow404_error.yml @@ -0,0 +1,49 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.baserow.io/api/database/rows/table/202600/99999/ + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - mes-demarches.gov.pf + Authorization: + - Token TqdlHPclwJkEouMLjtiFOcmKjgsDWtaL + Expect: + - '' + response: + status: + code: 404 + message: '' + headers: + Allow: + - GET, PATCH, DELETE, HEAD, OPTIONS + Alt-Svc: + - h3=":443"; ma=2592000 + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 16 Oct 2024 10:46:54 GMT + Referrer-Policy: + - same-origin + Server: + - Caddy + - gunicorn + Vary: + - origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + Content-Length: + - '80' + body: + encoding: ASCII-8BIT + string: '{"error":"ERROR_ROW_DOES_NOT_EXIST","detail":"The rows [''99999''] + do not exist."}' + recorded_at: Wed, 16 Oct 2024 10:46:50 GMT +recorded_with: VCR 6.2.0 diff --git a/spec/vcr_cassettes/baserow_available_tables.yml b/spec/vcr_cassettes/baserow_available_tables.yml index e011ab4e184..28e57b434f6 100644 --- a/spec/vcr_cassettes/baserow_available_tables.yml +++ b/spec/vcr_cassettes/baserow_available_tables.yml @@ -27,7 +27,7 @@ http_interactions: Cross-Origin-Opener-Policy: - same-origin Date: - - Tue, 15 Oct 2024 12:30:42 GMT + - Wed, 16 Oct 2024 10:46:54 GMT Referrer-Policy: - same-origin Server: @@ -45,5 +45,5 @@ http_interactions: encoding: ASCII-8BIT string: !binary |- eyJjb3VudCI6NywibmV4dCI6bnVsbCwicHJldmlvdXMiOm51bGwsInJlc3VsdHMiOlt7ImlkIjoxLCJvcmRlciI6IjEuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiJDb21tdW5lcyBkZSBwb2x5bsOpc2llIiwiTm90ZXMiOiIiLCJBY3RpZiI6dHJ1ZSwiVGFibGUiOiIyMDI1NzgiLCJDaGFtcHMgdXNhZ2VyIjoiMTM5MTc0NywxMzkxNzUwLDEzOTE3NTUsMTM5MTc1NiIsIkNoYW1wIGRlIHJlY2hlcmNoZSI6IjEzOTE3NDciLCJDaGFtcHMgaW5zdHJ1Y3RldXIiOiIxMzkxNzQ3LDEzOTE3NTAsMTM5MTc1NSwxMzkxNzU2IiwiVG9rZW4iOiJUcWRsSFBjbHdKa0VvdU1ManRpRk9jbUtqZ3NEV3RhTCJ9LHsiaWQiOjI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iTm9tIjoiU2Vzc2lvbnMgZGUgZm9ybWF0aW9uIC0gQ0NJU00iLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOiIyMDI1ODQiLCJDaGFtcHMgdXNhZ2VyIjoiIiwiQ2hhbXAgZGUgcmVjaGVyY2hlIjoiMTM5MTc3OCIsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfSx7ImlkIjo3LCJvcmRlciI6IjYuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiJTdWJzdGFuY2VzIGFjdGl2ZXMgLSBEQlMiLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOiIyMTYyODQiLCJDaGFtcHMgdXNhZ2VyIjoiIiwiQ2hhbXAgZGUgcmVjaGVyY2hlIjoiMTUwMDAwMCIsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfSx7ImlkIjo4LCJvcmRlciI6IjcuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiIiLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOm51bGwsIkNoYW1wcyB1c2FnZXIiOiIiLCJDaGFtcCBkZSByZWNoZXJjaGUiOm51bGwsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfV19 - recorded_at: Tue, 15 Oct 2024 12:30:41 GMT + recorded_at: Wed, 16 Oct 2024 10:46:50 GMT recorded_with: VCR 6.2.0 diff --git a/spec/vcr_cassettes/baserow_fetch_row.yml b/spec/vcr_cassettes/baserow_fetch_row.yml index dd13ca21f0a..3a134464368 100644 --- a/spec/vcr_cassettes/baserow_fetch_row.yml +++ b/spec/vcr_cassettes/baserow_fetch_row.yml @@ -27,7 +27,7 @@ http_interactions: Cross-Origin-Opener-Policy: - same-origin Date: - - Tue, 15 Oct 2024 12:30:42 GMT + - Wed, 16 Oct 2024 10:46:54 GMT Referrer-Policy: - same-origin Server: @@ -45,7 +45,7 @@ http_interactions: encoding: ASCII-8BIT string: !binary |- eyJpZCI6MSwib3JkZXIiOiIxLjAwMDAwMDAwMDAwMDAwMDAwMDAwIiwiZmllbGRfMTM5MTg5NiI6IkNvbW11bmVzIGRlIHBvbHluw6lzaWUiLCJmaWVsZF8xMzkxODk3IjoiIiwiZmllbGRfMTM5MTg5OCI6dHJ1ZSwiZmllbGRfMTM5MTg5OSI6IjIwMjU3OCIsImZpZWxkXzEzOTE5MDAiOiIxMzkxNzQ3LDEzOTE3NTAsMTM5MTc1NSwxMzkxNzU2IiwiZmllbGRfMTM5MTkwMSI6IjEzOTE3NDciLCJmaWVsZF8xMzkxOTAzIjoiMTM5MTc0NywxMzkxNzUwLDEzOTE3NTUsMTM5MTc1NiIsImZpZWxkXzI3NzQ1ODEiOiJUcWRsSFBjbHdKa0VvdU1ManRpRk9jbUtqZ3NEV3RhTCJ9 - recorded_at: Tue, 15 Oct 2024 12:30:41 GMT + recorded_at: Wed, 16 Oct 2024 10:46:50 GMT - request: method: get uri: https://api.baserow.io/api/database/fields/table/202600/ @@ -73,7 +73,7 @@ http_interactions: Cross-Origin-Opener-Policy: - same-origin Date: - - Tue, 15 Oct 2024 12:30:42 GMT + - Wed, 16 Oct 2024 10:46:54 GMT Referrer-Policy: - same-origin Server: @@ -93,5 +93,5 @@ http_interactions: usager","order":4,"type":"text","primary":false,"read_only":false,"immutable_type":false,"immutable_properties":false,"description":null,"text_default":""},{"id":1391901,"table_id":202600,"name":"Champ de recherche","order":5,"type":"number","primary":false,"read_only":false,"immutable_type":false,"immutable_properties":false,"description":null,"number_decimal_places":0,"number_negative":false},{"id":1391903,"table_id":202600,"name":"Champs instructeur","order":6,"type":"text","primary":false,"read_only":false,"immutable_type":false,"immutable_properties":false,"description":null,"text_default":""},{"id":2774581,"table_id":202600,"name":"Token","order":7,"type":"text","primary":false,"read_only":false,"immutable_type":false,"immutable_properties":false,"description":null,"text_default":""}]' - recorded_at: Tue, 15 Oct 2024 12:30:41 GMT + recorded_at: Wed, 16 Oct 2024 10:46:50 GMT recorded_with: VCR 6.2.0 diff --git a/spec/vcr_cassettes/baserow_search.yml b/spec/vcr_cassettes/baserow_search.yml index 858c0c50667..e30048b8bc5 100644 --- a/spec/vcr_cassettes/baserow_search.yml +++ b/spec/vcr_cassettes/baserow_search.yml @@ -27,7 +27,7 @@ http_interactions: Cross-Origin-Opener-Policy: - same-origin Date: - - Tue, 15 Oct 2024 12:30:42 GMT + - Wed, 16 Oct 2024 10:46:54 GMT Referrer-Policy: - same-origin Server: @@ -45,5 +45,5 @@ http_interactions: encoding: ASCII-8BIT string: !binary |- eyJjb3VudCI6NywibmV4dCI6bnVsbCwicHJldmlvdXMiOm51bGwsInJlc3VsdHMiOlt7ImlkIjoxLCJvcmRlciI6IjEuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJmaWVsZF8xMzkxODk2IjoiQ29tbXVuZXMgZGUgcG9seW7DqXNpZSIsImZpZWxkXzEzOTE4OTciOiIiLCJmaWVsZF8xMzkxODk4Ijp0cnVlLCJmaWVsZF8xMzkxODk5IjoiMjAyNTc4IiwiZmllbGRfMTM5MTkwMCI6IjEzOTE3NDcsMTM5MTc1MCwxMzkxNzU1LDEzOTE3NTYiLCJmaWVsZF8xMzkxOTAxIjoiMTM5MTc0NyIsImZpZWxkXzEzOTE5MDMiOiIxMzkxNzQ3LDEzOTE3NTAsMTM5MTc1NSwxMzkxNzU2IiwiZmllbGRfMjc3NDU4MSI6IlRxZGxIUGNsd0prRW91TUxqdGlGT2NtS2pnc0RXdGFMIn0seyJpZCI6Miwib3JkZXIiOiIyLjAwMDAwMDAwMDAwMDAwMDAwMDAwIiwiZmllbGRfMTM5MTg5NiI6Ik1hdMOpcmllbHMgYWZmZWN0w6lzIGF1eCBhZ2VudHMiLCJmaWVsZF8xMzkxODk3IjoiIiwiZmllbGRfMTM5MTg5OCI6dHJ1ZSwiZmllbGRfMTM5MTg5OSI6IjIwMjU2N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iwiZmllbGRfMTM5MTg5OCI6ZmFsc2UsImZpZWxkXzEzOTE4OTkiOiIyMDI1ODQiLCJmaWVsZF8xMzkxOTAwIjoiIiwiZmllbGRfMTM5MTkwMSI6IjEzOTE3NzgiLCJmaWVsZF8xMzkxOTAzIjoiIiwiZmllbGRfMjc3NDU4MSI6bnVsbH0seyJpZCI6Nywib3JkZXIiOiI2LjAwMDAwMDAwMDAwMDAwMDAwMDAwIiwiZmllbGRfMTM5MTg5NiI6IlN1YnN0YW5jZXMgYWN0aXZlcyAtIERCUyIsImZpZWxkXzEzOTE4OTciOiIiLCJmaWVsZF8xMzkxODk4IjpmYWxzZSwiZmllbGRfMTM5MTg5OSI6IjIxNjI4NCIsImZpZWxkXzEzOTE5MDAiOiIiLCJmaWVsZF8xMzkxOTAxIjoiMTUwMDAwMCIsImZpZWxkXzEzOTE5MDMiOiIiLCJmaWVsZF8yNzc0NTgxIjpudWxsfSx7ImlkIjo4LCJvcmRlciI6IjcuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJmaWVsZF8xMzkxODk2IjoiIiwiZmllbGRfMTM5MTg5NyI6IiIsImZpZWxkXzEzOTE4OTgiOmZhbHNlLCJmaWVsZF8xMzkxODk5IjpudWxsLCJmaWVsZF8xMzkxOTAwIjoiIiwiZmllbGRfMTM5MTkwMSI6bnVsbCwiZmllbGRfMTM5MTkwMyI6IiIsImZpZWxkXzI3NzQ1ODEiOm51bGx9XX0= - recorded_at: Tue, 15 Oct 2024 12:30:41 GMT + recorded_at: Wed, 16 Oct 2024 10:46:50 GMT recorded_with: VCR 6.2.0 From 34f9b26d318f386254152f812f51b993ea5cc94a Mon Sep 17 00:00:00 2001 From: "maxim.joseau" Date: Thu, 17 Oct 2024 16:06:21 +0200 Subject: [PATCH 2/7] feature: add feature_flag to referentiel_de_polynesie field --- app/models/type_de_champ.rb | 1 - ..._flag_referentiel_de_polynesie_champs.rake | 24 ++ spec/factories/champ.rb | 4 + .../administrateurs/types_de_champ_spec.rb | 17 +- .../baserow_api_available_tables.yml | 233 ++++++++++++++++++ 5 files changed, 270 insertions(+), 9 deletions(-) create mode 100644 lib/tasks/deployment/20241017092100_feature_flag_referentiel_de_polynesie_champs.rake create mode 100644 spec/vcr_cassettes/baserow_api_available_tables.yml diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index b8b1fbf70ae..75d0061ca34 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -18,7 +18,6 @@ class TypeDeChamp < ApplicationRecord commune_de_polynesie: 'commune_de_polynesie', code_postal_de_polynesie: 'code_postal_de_polynesie', numero_dn: 'numero_dn', - # referentiel_de_polynesie: 'referentiel_de_polynesie', referentiel_de_polynesie: 'referentiel_de_polynesie', te_fenua: 'te_fenua', visa: 'visa' diff --git a/lib/tasks/deployment/20241017092100_feature_flag_referentiel_de_polynesie_champs.rake b/lib/tasks/deployment/20241017092100_feature_flag_referentiel_de_polynesie_champs.rake new file mode 100644 index 00000000000..b886c4e976a --- /dev/null +++ b/lib/tasks/deployment/20241017092100_feature_flag_referentiel_de_polynesie_champs.rake @@ -0,0 +1,24 @@ +namespace :after_party do + desc 'Deployment task: Enable feature flag for referentiel_de_polynesie' + task feature_flag_referentiel_de_polynesie: :environment do + puts "Running deploy task 'feature_flag_referentiel_de_polynesie'" + + progress = ProgressReport.new(User.count) + User.find_each do |user| + if Flipper.enabled?(:referentiel_de_polynesie, user) && user.administrateur? + user.administrateur.procedures.each do |procedure| + if procedure.types_de_champ_for_tags.where(type_champ: 'referentiel_de_polynesie').any? + Flipper.enable(:referentiel_de_polynesie, procedure) + end + end + Flipper.disable(:referentiel_de_polynesie, user) + end + progress.inc + end + + progress.finish + + AfterParty::TaskRecord + .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp + end +end diff --git a/spec/factories/champ.rb b/spec/factories/champ.rb index 042ff0df6e6..c8ba640b0d3 100644 --- a/spec/factories/champ.rb +++ b/spec/factories/champ.rb @@ -245,6 +245,10 @@ type_de_champ { association :type_de_champ_annuaire_education, procedure: dossier.procedure } end + factory :champ_referentiel_de_polynesie, class: 'Champs::ReferentielDePolynesieChamp' do + type_de_champ { association :type_de_champ_referentiel_de_polynesie, procedure: dossier.procedure } + end + factory :champ_visa, class: 'Champs::VisaChamp' do type_de_champ { association :type_de_champ_visa, procedure: dossier.procedure } end diff --git a/spec/system/administrateurs/types_de_champ_spec.rb b/spec/system/administrateurs/types_de_champ_spec.rb index 1a1867a2958..0911550de2e 100644 --- a/spec/system/administrateurs/types_de_champ_spec.rb +++ b/spec/system/administrateurs/types_de_champ_spec.rb @@ -210,18 +210,19 @@ before { Flipper.enable(:referentiel_de_polynesie, administrateur.user) } it "add referentiel_de_polynesie champ" do - add_champ - - select('Referentiel De Polynesie', from: 'Type de champ') - fill_in 'Libellé du champ', with: 'Libellé de champ referentiel de Polynesie', fill_options: { clear: :baskspace } + VCR.use_cassette('baserow_api_available_tables', record: :new_episodes) do + add_champ - expect(page).to have_content('Formulaire enregistré') + select('Referentiel De Polynesie', from: 'Type de champ') + fill_in 'Libellé du champ', with: 'Libellé de champ Référentiel de Polynésie', fill_options: { clear: :backspace } - waint_until { procedure.draft_types_de_champ_public.first.libelle == 'Libellé du champ référentiel de Polynesie' } + expect(page).to have_content('Formulaire enregistré') - page.refresh + wait_until { procedure.draft_types_de_champ_public.first.libelle == 'Libellé de champ Référentiel de Polynésie' } - expect(page).to have_content('Libellé de champ referentiel de polynesie') + page.refresh + expect(page).to have_content('Libellé de champ Référentiel de Polynésie') + end end end diff --git a/spec/vcr_cassettes/baserow_api_available_tables.yml b/spec/vcr_cassettes/baserow_api_available_tables.yml new file mode 100644 index 00000000000..e719e267361 --- /dev/null +++ b/spec/vcr_cassettes/baserow_api_available_tables.yml @@ -0,0 +1,233 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.baserow.io/api/database/rows/table/202600/?user_field_names=true + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - mes-demarches.gov.pf + Authorization: + - Token TqdlHPclwJkEouMLjtiFOcmKjgsDWtaL + Expect: + - '' + response: + status: + code: 200 + message: '' + headers: + Allow: + - GET, POST, HEAD, OPTIONS + Alt-Svc: + - h3=":443"; ma=2592000 + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Thu, 17 Oct 2024 13:53:33 GMT + Referrer-Policy: + - same-origin + Server: + - Caddy + - gunicorn + Vary: + - origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + Content-Length: + - '1668' + body: + encoding: ASCII-8BIT + string: !binary |- + eyJjb3VudCI6NywibmV4dCI6bnVsbCwicHJldmlvdXMiOm51bGwsInJlc3VsdHMiOlt7ImlkIjoxLCJvcmRlciI6IjEuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiJDb21tdW5lcyBkZSBwb2x5bsOpc2llIiwiTm90ZXMiOiIiLCJBY3RpZiI6dHJ1ZSwiVGFibGUiOiIyMDI1NzgiLCJDaGFtcHMgdXNhZ2VyIjoiMTM5MTc0NywxMzkxNzUwLDEzOTE3NTUsMTM5MTc1NiIsIkNoYW1wIGRlIHJlY2hlcmNoZSI6IjEzOTE3NDciLCJDaGFtcHMgaW5zdHJ1Y3RldXIiOiIxMzkxNzQ3LDEzOTE3NTAsMTM5MTc1NSwxMzkxNzU2IiwiVG9rZW4iOiJUcWRsSFBjbHdKa0VvdU1ManRpRk9jbUtqZ3NEV3RhTCJ9LHsiaWQiOjIsIm9yZGVyIjoiMi4wMDAwMDAwMDAwMDAwMDAwMDAwMCIsIk5vbSI6Ik1hdMOpcmllbHMgYWZmZWN0w6lzIGF1eCBhZ2VudHMiLCJOb3RlcyI6IiIsIkFjdGlmIjp0cnVlLCJUYWJsZSI6IjIwMjU2NyIsIkNoYW1wcyB1c2FnZXIiOiIxMzkxNjQ1LDEzOTE2NDYsMTM5MTY1NiIsIkNoYW1wIGRlIHJlY2hlcmNoZSI6IjEzOTE2NDUiLCJDaGFtcHMgaW5zdHJ1Y3RldXIiOi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20iOiJTdWJzdGFuY2VzIGFjdGl2ZXMgLSBEQlMiLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOiIyMTYyODQiLCJDaGFtcHMgdXNhZ2VyIjoiIiwiQ2hhbXAgZGUgcmVjaGVyY2hlIjoiMTUwMDAwMCIsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfSx7ImlkIjo4LCJvcmRlciI6IjcuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiIiLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOm51bGwsIkNoYW1wcyB1c2FnZXIiOiIiLCJDaGFtcCBkZSByZWNoZXJjaGUiOm51bGwsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfV19 + recorded_at: Thu, 17 Oct 2024 13:53:32 GMT +- request: + method: get + uri: https://api.baserow.io/api/database/rows/table/202600/?user_field_names=true + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - mes-demarches.gov.pf + Authorization: + - Token TqdlHPclwJkEouMLjtiFOcmKjgsDWtaL + Expect: + - '' + response: + status: + code: 200 + message: '' + headers: + Allow: + - GET, POST, HEAD, OPTIONS + Alt-Svc: + - h3=":443"; ma=2592000 + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Thu, 17 Oct 2024 13:53:34 GMT + Referrer-Policy: + - same-origin + Server: + - Caddy + - gunicorn + Vary: + - origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + Content-Length: + - '1668' + body: + encoding: ASCII-8BIT + string: !binary |- + eyJjb3VudCI6NywibmV4dCI6bnVsbCwicHJldmlvdXMiOm51bGwsInJlc3VsdHMiOlt7ImlkIjoxLCJvcmRlciI6IjEuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiJDb21tdW5lcyBkZSBwb2x5bsOpc2llIiwiTm90ZXMiOiIiLCJBY3RpZiI6d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T +- request: + method: get + uri: https://api.baserow.io/api/database/rows/table/202600/?user_field_names=true + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - mes-demarches.gov.pf + Authorization: + - Token TqdlHPclwJkEouMLjtiFOcmKjgsDWtaL + Expect: + - '' + response: + status: + code: 200 + message: '' + headers: + Allow: + - GET, POST, HEAD, OPTIONS + Alt-Svc: + - h3=":443"; ma=2592000 + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Thu, 17 Oct 2024 13:53:34 GMT + Referrer-Policy: + - same-origin + Server: + - Caddy + - gunicorn + Vary: + - origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + Content-Length: + - '1668' + body: + encoding: ASCII-8BIT + string: !binary |- + eyJjb3VudCI6NywibmV4dCI6bnVsbCwicHJldmlvdXMiOm51bGwsInJlc3VsdHMiOlt7ImlkIjoxLCJvcmRlciI6IjEuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiJDb21tdW5lcyBkZSBwb2x5bsOpc2llIiwiTm90ZXMiOiIiLCJBY3RpZiI6dHJ1ZSwiVGFibGUiOiIyMDI1NzgiLCJDaGFtcHMgdXNhZ2VyIjoiMTM5MTc0NywxMzkxNzUwLDEzOTE3NTUsMTM5MTc1NiIsIkNoYW1wIGRlIHJlY2hlcmNoZSI6IjEzOTE3NDciLCJDaGFtcHMgaW5zdHJ1Y3RldXIiOiIxMzkxNzQ3LDEzOTE3NTAsMTM5MTc1NSwxMzkxNzU2IiwiVG9rZW4iOiJUcWRsSFBjbHdKa0VvdU1ManRpRk9jbUtqZ3NEV3RhTCJ9LHsiaWQiOjIsIm9yZGVyIjoiMi4wMDAwMDAwMDAwMDAwMDAwMDAwMCIsIk5vbSI6Ik1hdMOpcmllbHMgYWZmZWN0w6lzIGF1eCBhZ2VudHMiLCJOb3RlcyI6IiIsIkFjdGlmIjp0cnVlLCJUYWJsZSI6IjIwMjU2NyIsIkNoYW1wcyB1c2FnZXIiOiIxMzkx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1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfSx7ImlkIjo3LCJvcmRlciI6IjYuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiJTdWJzdGFuY2VzIGFjdGl2ZXMgLSBEQlMiLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOiIyMTYyODQiLCJDaGFtcHMgdXNhZ2VyIjoiIiwiQ2hhbXAgZGUgcmVjaGVyY2hlIjoiMTUwMDAwMCIsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfSx7ImlkIjo4LCJvcmRlciI6IjcuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiIiLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOm51bGwsIkNoYW1wcyB1c2FnZXIiOiIiLCJDaGFtcCBkZSByZWNoZXJjaGUiOm51bGwsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfV19 + recorded_at: Thu, 17 Oct 2024 13:53:32 GMT +- request: + method: get + uri: https://api.baserow.io/api/database/rows/table/202600/?user_field_names=true + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - mes-demarches.gov.pf + Authorization: + - Token TqdlHPclwJkEouMLjtiFOcmKjgsDWtaL + Expect: + - '' + response: + status: + code: 200 + message: '' + headers: + Allow: + - GET, POST, HEAD, OPTIONS + Alt-Svc: + - h3=":443"; ma=2592000 + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Thu, 17 Oct 2024 13:53:34 GMT + Referrer-Policy: + - same-origin + Server: + - Caddy + - gunicorn + Vary: + - origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + Content-Length: + - '1668' + body: + encoding: ASCII-8BIT + string: !binary |- + eyJjb3VudCI6NywibmV4dCI6bnVsbCwicHJldmlvdXMiOm51bGwsInJlc3VsdHMiOlt7ImlkIjoxLCJvcmRlci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SByZWNoZXJjaGUiOm51bGwsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfV19 + recorded_at: Thu, 17 Oct 2024 13:53:32 GMT +- request: + method: get + uri: https://api.baserow.io/api/database/rows/table/202600/?user_field_names=true + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - mes-demarches.gov.pf + Authorization: + - Token TqdlHPclwJkEouMLjtiFOcmKjgsDWtaL + Expect: + - '' + response: + status: + code: 200 + message: '' + headers: + Allow: + - GET, POST, HEAD, OPTIONS + Alt-Svc: + - h3=":443"; ma=2592000 + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Thu, 17 Oct 2024 13:53:34 GMT + Referrer-Policy: + - same-origin + Server: + - Caddy + - gunicorn + Vary: + - origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + Content-Length: + - '1668' + body: + encoding: ASCII-8BIT + string: !binary |- + eyJjb3VudCI6NywibmV4dCI6bnVsbCwicHJldmlvdXMiOm51bGwsInJlc3VsdHMiOlt7ImlkIjoxLCJvcmRlciI6IjEuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiJDb21tdW5lcyBkZSBwb2x5bsOpc2llIiwiTm90ZXMiOiIiLCJBY3RpZiI6dHJ1ZSwiVGFibGUiOiIyMDI1NzgiLCJDaGFtcHMgdXNhZ2VyIjoiMTM5MTc0NywxMzkxNzUwLDEzOTE3NTUsMTM5MTc1NiIsIkNoYW1wIGRlIHJlY2hlcmNoZSI6IjEzOTE3NDciLCJDaGFtcHMgaW5zdHJ1Y3RldXIiOiIxMzkxNzQ3LDEzOTE3NTAsMTM5MTc1NSwxMzkxNzU2IiwiVG9rZW4iOiJUcWRsSFBjbHdKa0VvdU1ManRpRk9jbUtqZ3NEV3RhTCJ9LHsiaWQiOjIsIm9yZGVyIjoiMi4wMDAwMDAwMDAwMDAwMDAwMDAwMCIsIk5vbSI6Ik1hdMOpcmllbHMgYWZmZWN0w6lz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zZSwiVGFibGUiOiIyMDI1ODQiLCJDaGFtcHMgdXNhZ2VyIjoiIiwiQ2hhbXAgZGUgcmVjaGVyY2hlIjoiMTM5MTc3OCIsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfSx7ImlkIjo3LCJvcmRlciI6IjYuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiJTdWJzdGFuY2VzIGFjdGl2ZXMgLSBEQlMiLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOiIyMTYyODQiLCJDaGFtcHMgdXNhZ2VyIjoiIiwiQ2hhbXAgZGUgcmVjaGVyY2hlIjoiMTUwMDAwMCIsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfSx7ImlkIjo4LCJvcmRlciI6IjcuMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJOb20iOiIiLCJOb3RlcyI6IiIsIkFjdGlmIjpmYWxzZSwiVGFibGUiOm51bGwsIkNoYW1wcyB1c2FnZXIiOiIiLCJDaGFtcCBkZSByZWNoZXJjaGUiOm51bGwsIkNoYW1wcyBpbnN0cnVjdGV1ciI6IiIsIlRva2VuIjpudWxsfV19 + recorded_at: Thu, 17 Oct 2024 13:53:33 GMT +recorded_with: VCR 6.2.0 From a267921ef8654a26d38f0ded4f6f899b9080e5ae Mon Sep 17 00:00:00 2001 From: "maxim.joseau" Date: Thu, 17 Oct 2024 16:23:48 +0200 Subject: [PATCH 3/7] feature: remove old table_row_selector files --- .../table_row_selector_component.rb | 12 --- .../table_row_selector_component.html.haml | 7 -- .../champs/table_row_selector_controller.rb | 20 ----- .../ComboTableRowSelectorSearch.tsx | 32 ------- app/lib/table_row_selector/api.rb | 22 ----- app/lib/table_row_selector/api_old.rb | 22 ----- app/lib/table_row_selector/baserow_api.rb | 86 ------------------- app/models/champs/table_row_selector_champ.rb | 16 ---- app/models/logic/champ_value.rb | 2 - app/models/type_de_champ.rb | 4 - spec/support/capybara.rb | 4 +- 11 files changed, 2 insertions(+), 225 deletions(-) delete mode 100644 app/components/editable_champ/table_row_selector_component.rb delete mode 100644 app/components/editable_champ/table_row_selector_component/table_row_selector_component.html.haml delete mode 100644 app/controllers/champs/table_row_selector_controller.rb delete mode 100644 app/javascript/components/ComboTableRowSelectorSearch.tsx delete mode 100644 app/lib/table_row_selector/api.rb delete mode 100644 app/lib/table_row_selector/api_old.rb delete mode 100644 app/lib/table_row_selector/baserow_api.rb delete mode 100644 app/models/champs/table_row_selector_champ.rb diff --git a/app/components/editable_champ/table_row_selector_component.rb b/app/components/editable_champ/table_row_selector_component.rb deleted file mode 100644 index 35f4bf840da..00000000000 --- a/app/components/editable_champ/table_row_selector_component.rb +++ /dev/null @@ -1,12 +0,0 @@ -# class EditableChamp::TableRowSelectorComponent < EditableChamp::ComboSearchComponent -# def dsfr_input_classname -# 'fr-input' -# end - -# def react_input_opts -# opts = input_opts(id: @champ.input_id, required: @champ.required?, aria: { describedby: @champ.describedby_id }, scopeExtra: @champ.table_id) -# opts[:className] = "#{opts.delete(:class)} fr-mt-1w" - -# opts -# end -# end diff --git a/app/components/editable_champ/table_row_selector_component/table_row_selector_component.html.haml b/app/components/editable_champ/table_row_selector_component/table_row_selector_component.html.haml deleted file mode 100644 index 812b52f8e3b..00000000000 --- a/app/components/editable_champ/table_row_selector_component/table_row_selector_component.html.haml +++ /dev/null @@ -1,7 +0,0 @@ --# - render_parent - --# = @form.hidden_field :value --# = @form.hidden_field :external_id --# = react_component("ComboTableRowSelectorSearch", --# **react_input_opts, --# **react_combo_props) diff --git a/app/controllers/champs/table_row_selector_controller.rb b/app/controllers/champs/table_row_selector_controller.rb deleted file mode 100644 index 4154a953ec8..00000000000 --- a/app/controllers/champs/table_row_selector_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -# # frozen_string_literal: true - -# class Champs::TableRowSelectorController < ApplicationController -# before_action :authenticate_logged_user! - -# def search -# @params = search_params -# if bad_parameters -# render json: [], status: 400 -# else -# render json: TableRowSelector::API.search(@params[:domain], @params[:term]) -# end -# end - -# def bad_parameters -# @params[:domain].blank? || @params[:domain].to_i == 0 || @params[:term].blank? -# end - -# def search_params = params.permit(:domain, :term) -# end diff --git a/app/javascript/components/ComboTableRowSelectorSearch.tsx b/app/javascript/components/ComboTableRowSelectorSearch.tsx deleted file mode 100644 index 0fbe562ec22..00000000000 --- a/app/javascript/components/ComboTableRowSelectorSearch.tsx +++ /dev/null @@ -1,32 +0,0 @@ -// import React from 'react'; -// import { QueryClientProvider } from 'react-query'; - -// import ComboSearch, { ComboSearchProps } from './ComboSearch'; -// import { queryClient } from './shared/queryClient'; - -// type TableRowSelectorResult = { -// name: string; -// id: string; -// domain: string; -// }; - -// function transformResults(_: unknown, result: unknown) { -// return result as TableRowSelectorResult[]; -// } - -// export default function ComboTableRowSelectorSearch( -// props: ComboSearchProps -// ) { -// return ( -// -// [`${domain}:${id}`, name]} -// /> -// -// ); -// } diff --git a/app/lib/table_row_selector/api.rb b/app/lib/table_row_selector/api.rb deleted file mode 100644 index 89f78bc9bc0..00000000000 --- a/app/lib/table_row_selector/api.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -class ReferentielDePolynesie::API - class << self - def available_tables - engine&.available_tables - end - - def 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) - end - - def engine - @engine ||= ENV['API_BASEROW_URL'].present? ? ReferentielDePolynesie::BaserowAPI : nil - end - end -end diff --git a/app/lib/table_row_selector/api_old.rb b/app/lib/table_row_selector/api_old.rb deleted file mode 100644 index 84aeb2bc785..00000000000 --- a/app/lib/table_row_selector/api_old.rb +++ /dev/null @@ -1,22 +0,0 @@ -# # frozen_string_literal: true - -# class TableRowSelector::API -# class << self -# def available_tables -# engine&.available_tables -# end - -# def 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) -# end - -# def engine -# @engine ||= ENV['API_BASEROW_URL'].present? ? TableRowSelector::BaserowAPI : nil -# end -# end -# end diff --git a/app/lib/table_row_selector/baserow_api.rb b/app/lib/table_row_selector/baserow_api.rb deleted file mode 100644 index 7063dd8951b..00000000000 --- a/app/lib/table_row_selector/baserow_api.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -class ReferentielDePolynesie::BaserowAPI - class << self - SECRETS = Rails.application.secrets.baserow - - def search(domain_id, term) - config = config(domain_id) - 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 }] - end - end - - def available_tables - response = Typhoeus.get(rows_url(SECRETS[:config_table]), headers: config_database_headers, params: default_params) - if response.success? - JSON.parse(response.body, symbolize_names: true)[:results]&.filter { _1[:Actif] }&.map do - { name: _1[:Nom], id: _1[:id] } - end - end - end - - def fetch_row(domain_id, row) - return {} if row.to_i.zero? - - config = config(domain_id) - response = Typhoeus.get(row_url(config['Table'], row), headers: database_headers(config['Token'])) - if response.success? - model = fields(config) - usager_fields = field_names(model, config['Champs usager']) - instructeur_fields = field_names(model, config['Champs instructeur']) - row = JSON.parse(response.body).filter { |name, _| name.start_with?('field_') }.transform_keys do |key| - model[key[6..-1].to_i] - end - { usager_fields:, instructeur_fields:, row: } - end - end - - def field_names(model, field_ids) - field_ids&.split(/,/)&.map(&:strip)&.map { model[_1.to_i] } || [] - end - - def config(row_id) - response = Typhoeus.get(row_url(SECRETS[:config_table], row_id), headers: config_database_headers, params: default_params) - response.success? ? JSON.parse(response.body) : nil - end - - def fields(config) - response = Typhoeus.get(list_database_table_fields(config['Table']), headers: database_headers(config['Token'])) - if response.success? - JSON.parse(response.body).map { [_1['id'], _1['name']] }.to_h - end - end - - def rows_url(table_id) = "#{SECRETS[:url]}/api/database/rows/table/#{table_id}/" - - def row_url(table_id, row_id) = "#{rows_url(table_id)}#{row_id}/" - - def list_database_table_fields(table_id) = "#{SECRETS[:url]}/api/database/fields/table/#{table_id}/" - - def config_database_headers = database_headers(SECRETS[:token]) - - def database_headers(token) = { 'Authorization' => "Token #{token}" } - - def default_params = { user_field_names: true } - - JWT_URL = "#{SECRETS[:url]}/api/user/token-auth/" - MUTEX = Mutex.new - - def meta_headers - credentials = { username: SECRETS[:user], password: SECRETS[:password] } - response = Typhoeus.post(JWT_URL, body: credentials) - if response.success? - jwt = JSON.parse(response.body)['token'] - { authorization: "JWT #{jwt}" } - end - end - end -end diff --git a/app/models/champs/table_row_selector_champ.rb b/app/models/champs/table_row_selector_champ.rb deleted file mode 100644 index 1779453fb96..00000000000 --- a/app/models/champs/table_row_selector_champ.rb +++ /dev/null @@ -1,16 +0,0 @@ -# # frozen_string_literal: true - -# class Champs::TableRowSelectorChamp < Champs::TextChamp -# def fetch_external_data? -# true -# end - -# def fetch_external_data -# # APIEducation::AnnuaireEducationAdapter.new(external_id).to_params -# TableRowSelector::API.fetch_row(external_id) -# end - -# def update_with_external_data!(data:) -# update!(data: data) if data&.is_a?(Hash) -# end -# end diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb index c053ee91980..dfcf28ff76c 100644 --- a/app/models/logic/champ_value.rb +++ b/app/models/logic/champ_value.rb @@ -71,8 +71,6 @@ def compute(champs) code_departement: targeted_champ.code_departement, code_region: targeted_champ.code_region } - # when "Champs::TableRowSelectorChamp" - # targeted_champ.value when "Champs::ReferentielDePolynesieChamp" targeted_champ.value when "Champs::CommuneDePolynesieChamp", "Champs::CodePostalDePolynesieChamp" diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 75d0061ca34..834717a176e 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -669,10 +669,6 @@ def accredited_user_list accredited_users.presence || [] end - # def available_tables - # TableRowSelector::API.available_tables.map { [_1[:name], _1[:id]] } - # end - def available_tables ReferentielDePolynesie::API.available_tables.map { [_1[:name], _1[:id]] } end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 6f42891acab..a29cf8eb7c7 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -55,7 +55,7 @@ def setup_driver(app, download_path, options) setup_driver(app, download_path, options) end -Capybara.default_max_wait_time = 1 +Capybara.default_max_wait_time = 4 Capybara.ignore_hidden_elements = false @@ -64,7 +64,7 @@ def setup_driver(app, download_path, options) Capybara.disable_animation = true # Save a snapshot of the HTML page when an integration test fails -Capybara::Screenshot.autosave_on_failure = false +Capybara::Screenshot.autosave_on_failure = true # Keep only the screenshots generated from the last failing test suite Capybara::Screenshot.prune_strategy = :keep_last_run # Tell Capybara::Screenshot how to take screenshots when using the headless_chrome driver From e6aa184bb48905f1d6c0fb27e7cf24056e3c12bb Mon Sep 17 00:00:00 2001 From: "maxim.joseau" Date: Thu, 17 Oct 2024 16:52:30 +0200 Subject: [PATCH 4/7] chore: change files name to match project --- ...el_de_polynesie.rb => referentiel_de_polynesie_component.rb} | 2 +- ...esieSearch.tsx.tsx => ComboReferentielDePolynesieSearch.tsx} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename app/components/editable_champ/{referentiel_de_polynesie.rb => referentiel_de_polynesie_component.rb} (76%) rename app/javascript/components/{ComboReferentielDePolynesieSearch.tsx.tsx => ComboReferentielDePolynesieSearch.tsx} (100%) diff --git a/app/components/editable_champ/referentiel_de_polynesie.rb b/app/components/editable_champ/referentiel_de_polynesie_component.rb similarity index 76% rename from app/components/editable_champ/referentiel_de_polynesie.rb rename to app/components/editable_champ/referentiel_de_polynesie_component.rb index d832050fc7a..3271ff27c88 100644 --- a/app/components/editable_champ/referentiel_de_polynesie.rb +++ b/app/components/editable_champ/referentiel_de_polynesie_component.rb @@ -1,4 +1,4 @@ -class EditableChamp::ReferentielDePolynesie < EditableChamp::ComboSearchComponent +class EditableChamp::ReferentielDePolynesieComponent < EditableChamp::ComboSearchComponent def dsfr_input_classname 'fr-input' end diff --git a/app/javascript/components/ComboReferentielDePolynesieSearch.tsx.tsx b/app/javascript/components/ComboReferentielDePolynesieSearch.tsx similarity index 100% rename from app/javascript/components/ComboReferentielDePolynesieSearch.tsx.tsx rename to app/javascript/components/ComboReferentielDePolynesieSearch.tsx From 3766b3dc78fe46b1b977434e996270eacc3816c7 Mon Sep 17 00:00:00 2001 From: "maxim.joseau" Date: Fri, 18 Oct 2024 09:43:05 +0200 Subject: [PATCH 5/7] chore: show partial in the good folder --- .../_show.html.haml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/views/shared/champs/{table_row_selector => referentiel_de_polynesie}/_show.html.haml (100%) diff --git a/app/views/shared/champs/table_row_selector/_show.html.haml b/app/views/shared/champs/referentiel_de_polynesie/_show.html.haml similarity index 100% rename from app/views/shared/champs/table_row_selector/_show.html.haml rename to app/views/shared/champs/referentiel_de_polynesie/_show.html.haml From 7709cc793de3f4da4c34a2b3e622090316a2b7c0 Mon Sep 17 00:00:00 2001 From: "maxim.joseau" Date: Tue, 22 Oct 2024 10:40:30 +0200 Subject: [PATCH 6/7] feature: add brouillon.spec test --- ...flag_referentiel_de_polynesie.rake_spec.rb | 39 +++++++ spec/system/users/brouillon_spec.rb | 28 +++++ ..._dossier_with_referentiel_de_polynesie.yml | 102 ++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 spec/lib/tasks/deployment/20241021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb create mode 100644 spec/vcr_cassettes/The_user/fill_a_dossier_with_referentiel_de_polynesie.yml diff --git a/spec/lib/tasks/deployment/20241021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb b/spec/lib/tasks/deployment/20241021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb new file mode 100644 index 00000000000..ec5a4636772 --- /dev/null +++ b/spec/lib/tasks/deployment/20241021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb @@ -0,0 +1,39 @@ +describe 'deployment:20241021111111:feature_flag_referentiel_de_polynesie' do + let(:rake_task) { Rake::Task['after_party:feature_flag_referentiel_de_polynesie'] } + let!(:procedure_with_admin_featured) { create(:procedure) } + let!(:types_de_champ_private) { [{ type: :referentiel_de_polynesie }] } + let!(:procedure_with_referentiel_de_polynesie_with_admin_featured) { create(:procedure, types_de_champ_private:, administrateurs: [procedure_with_admin_featured.administrateurs.first]) } + let!(:procedure_without_admin_featured) { create(:procedure) } + let!(:procedure_with_referentiel_de_polynesie_without_admin_featured) { create(:procedure, types_de_champ_private:, administrateurs: [procedure_without_admin_featured.administrateurs.first]) } + + subject(:run_task) do + rake_task.invoke + end + + before { Flipper.enable(:referentiel_de_polynesie, procedure_with_admin_featured.administrateurs.first.user) } + + after { rake_task.reenable } + + describe 'feature_flag_referentiel_de_polynesie' do + it "with bad champs" do + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_admin_featured.administrateurs.first.user)).to eq(true) + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_admin_featured)).to eq(false) + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_with_admin_featured)).to eq(false) + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_without_admin_featured)).to eq(false) + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_without_admin_featured)).to eq(false) + + run_task + + procedure_with_admin_featured.reload + procedure_with_referentiel_de_polynesie_with_admin_featured.reload + procedure_without_admin_featured.reload + procedure_with_referentiel_de_polynesie_without_admin_featured.reload + + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_admin_featured.administrateurs.first.user)).to eq(false) + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_admin_featured)).to eq(false) + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_with_admin_featured)).to eq(true) + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_without_admin_featured)).to eq(false) + expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_without_admin_featured)).to eq(false) + end + end +end \ No newline at end of file diff --git a/spec/system/users/brouillon_spec.rb b/spec/system/users/brouillon_spec.rb index 2fce0c29d7b..2f40517e428 100644 --- a/spec/system/users/brouillon_spec.rb +++ b/spec/system/users/brouillon_spec.rb @@ -178,6 +178,34 @@ ]) } + let(:simple_procedure_with_referentiel_de_polynesie) { + create(:procedure, :published, :for_individual, types_de_champ_public: [ + { mandatory: false, libelle: 'referentiel de polynesie', type_champ: 'referentiel_de_polynesie', table_id: "1" } + ]) + } + + scenario 'fill a dossier with referentiel_de_polynesie', js: true, vcr: true do + log_in(user, simple_procedure_with_referentiel_de_polynesie) + fill_individual + + find_field('referentiel de polynesie').click + fill_in('referentiel de polynesie', with: 'Mahina') + + using_wait_time 5 do + expect(page).to have_selector('input[aria-expanded="true"]', visible: true, wait: 10) + end + + using_wait_time 5 do + expect(page).to have_selector('ul[role="listbox"]', visible: true, wait: 10) + expect(page).to have_selector('ul[role="listbox"] li', text: 'Mahina - Tahiti - 98709') + end + + find('ul[role="listbox"] li', text: 'Mahina - Tahiti - 98709').click + click_on 'Déposer le dossier' + + expect(page).to have_content('Vous avez désormais accès à votre dossier en ligne.') + end + scenario 'save an incomplete dossier as draft but cannot not submit it', js: true do log_in(user, simple_procedure) fill_individual diff --git a/spec/vcr_cassettes/The_user/fill_a_dossier_with_referentiel_de_polynesie.yml b/spec/vcr_cassettes/The_user/fill_a_dossier_with_referentiel_de_polynesie.yml new file mode 100644 index 00000000000..3a08b085ddc --- /dev/null +++ b/spec/vcr_cassettes/The_user/fill_a_dossier_with_referentiel_de_polynesie.yml @@ -0,0 +1,102 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.baserow.io/api/database/rows/table/202600/1/?user_field_names=true + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - mes-demarches.gov.pf + Authorization: + - Token TqdlHPclwJkEouMLjtiFOcmKjgsDWtaL + Expect: + - '' + response: + status: + code: 200 + message: '' + headers: + Allow: + - GET, PATCH, DELETE, HEAD, OPTIONS + Alt-Svc: + - h3=":443"; ma=2592000 + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Mon, 21 Oct 2024 18:22:13 GMT + Referrer-Policy: + - same-origin + Server: + - Caddy + - gunicorn + Vary: + - origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + Content-Length: + - '292' + body: + encoding: ASCII-8BIT + string: !binary |- + eyJpZCI6MSwib3JkZXIiOiIxLjAwMDAwMDAwMDAwMDAwMDAwMDAwIiwiTm9tIjoiQ29tbXVuZXMgZGUgcG9seW7DqXNpZSIsIk5vdGVzIjoiIiwiQWN0aWYiOnRydWUsIlRhYmxlIjoiMjAyNTc4IiwiQ2hhbXBzIHVzYWdlciI6IjEzOTE3NDcsMTM5MTc1MCwxMzkxNzU1LDEzOTE3NTYiLCJDaGFtcCBkZSByZWNoZXJjaGUiOiIxMzkxNzQ3IiwiQ2hhbXBzIGluc3RydWN0ZXVyIjoiMTM5MTc0NywxMzkxNzUwLDEzOTE3NTUsMTM5MTc1NiIsIlRva2VuIjoiVHFkbEhQY2x3SmtFb3VNTGp0aUZPY21LamdzRFd0YUwifQ== + recorded_at: Mon, 21 Oct 2024 18:22:12 GMT +- request: + method: get + uri: https://api.baserow.io/api/database/rows/table/202578/?filter__field_1391747__contains=Mahina + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - mes-demarches.gov.pf + Authorization: + - Token TqdlHPclwJkEouMLjtiFOcmKjgsDWtaL + Expect: + - '' + response: + status: + code: 200 + message: '' + headers: + Allow: + - GET, POST, HEAD, OPTIONS + Alt-Svc: + - h3=":443"; ma=2592000 + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Mon, 21 Oct 2024 18:22:14 GMT + Referrer-Policy: + - same-origin + Server: + - Caddy + - gunicorn + Vary: + - origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + Content-Length: + - '1363' + body: + encoding: ASCII-8BIT + string: '{"count":3,"next":null,"previous":null,"results":[{"id":10,"order":"10.00000000000000000000","field_1391747":"Mahina + - Tahiti - 98709","field_1391748":"Mahina","field_1391749":"98709","field_1391750":"14351","field_1391751":"","field_1391754":[{"ids":{"database_table_202575":2,"database_table_202576":7},"value":"Iles + Du Vent"}],"field_1391755":"","field_1391756":[{"id":7,"value":"Mahina - Tahiti + - 98709"}],"field_1391765":[{"id":7,"value":"Tahiti"}]},{"id":11,"order":"11.00000000000000000000","field_1391747":"Orofara + (Village) - Mahina - Tahiti - 98710","field_1391748":"Orofara (Village)","field_1391749":"98710","field_1391750":null,"field_1391751":"Mahina","field_1391754":[{"ids":{"database_table_202575":2,"database_table_202576":7},"value":"Iles + Du Vent"}],"field_1391755":"","field_1391756":[{"id":7,"value":"Orofara (Village) + - Mahina - Tahiti - 98710"}],"field_1391765":[{"id":7,"value":"Tahiti"}]},{"id":164,"order":"164.00000000000000000000","field_1391747":"Pukapuka + - Teonemahina - 98774","field_1391748":"Pukapuka","field_1391749":"98774","field_1391750":null,"field_1391751":"Teonemahina","field_1391754":[{"ids":{"database_table_202575":5,"database_table_202576":85},"value":"Tuamotu-Gambiers"}],"field_1391755":"Pukapuka","field_1391756":[{"id":85,"value":"Pukapuka + - Teonemahina - 98774"}],"field_1391765":[{"id":85,"value":"Pukapuka"}]}]}' + recorded_at: Mon, 21 Oct 2024 18:22:13 GMT +recorded_with: VCR 6.2.0 From 3a500607fed4d65007831ba92515ad8f643294f9 Mon Sep 17 00:00:00 2001 From: "maxim.joseau" Date: Tue, 22 Oct 2024 10:43:32 +0200 Subject: [PATCH 7/7] chore: linter --- ...021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/tasks/deployment/20241021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb b/spec/lib/tasks/deployment/20241021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb index ec5a4636772..a4e340a2df1 100644 --- a/spec/lib/tasks/deployment/20241021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb +++ b/spec/lib/tasks/deployment/20241021111111_feature_flag_referentiel_de_polynesie.rake_spec.rb @@ -36,4 +36,4 @@ expect(Flipper.enabled?(:referentiel_de_polynesie, procedure_with_referentiel_de_polynesie_without_admin_featured)).to eq(false) end end -end \ No newline at end of file +end