Schema graph_ql (#8406)
* First draft schema graph_ql * Add tests for json schema procedures
This commit is contained in:
parent
68ddae7382
commit
962016e32e
7 changed files with 79 additions and 0 deletions
|
@ -0,0 +1,25 @@
|
||||||
|
class API::Public::V1::JSONDescriptionProceduresController < API::Public::V1::BaseController
|
||||||
|
skip_before_action :check_content_type_is_json
|
||||||
|
before_action :retrieve_procedure
|
||||||
|
|
||||||
|
def show
|
||||||
|
render json: procedure_graph_ql_schema, status: 200
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def retrieve_procedure
|
||||||
|
@procedure = Procedure.publiees_ou_brouillons.opendata.find_by(path: params[:path])
|
||||||
|
render_not_found("procedure", params[:path]) if @procedure.blank?
|
||||||
|
end
|
||||||
|
|
||||||
|
def procedure_graph_ql_schema
|
||||||
|
API::V2::Schema.execute(API::V2::StoredQuery.get('ds-query-v2'),
|
||||||
|
variables: {
|
||||||
|
demarche: { "number": @procedure.id },
|
||||||
|
includeRevision: true
|
||||||
|
},
|
||||||
|
operation_name: "getDemarcheDescriptor")
|
||||||
|
.to_h.dig("data", "demarcheDescriptor").to_json
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
= render Dsfr::CalloutComponent.new(title: t("views.prefill_descriptions.edit.json_description_title"), theme: :success, icon: "fr-icon-layout-grid-fill") do |c|
|
||||||
|
- c.with_body do
|
||||||
|
= t("views.prefill_descriptions.edit.json_description_info")
|
||||||
|
%pre
|
||||||
|
%code.code-block
|
||||||
|
= prefill_json_description_url(procedure.path)
|
||||||
|
- c.with_bottom do
|
||||||
|
= render Dsfr::CopyButtonComponent.new(title: t("views.prefill_descriptions.edit.json_description_copy"), text: prefill_json_description_url(procedure.path))
|
|
@ -19,3 +19,5 @@
|
||||||
= render "prefill_link", prefill_description: @prefill_description
|
= render "prefill_link", prefill_description: @prefill_description
|
||||||
|
|
||||||
= render "prefill_query", prefill_description: @prefill_description
|
= render "prefill_query", prefill_description: @prefill_description
|
||||||
|
|
||||||
|
= render "json_description", procedure: @prefill_description
|
||||||
|
|
|
@ -149,6 +149,9 @@ en:
|
||||||
prefill_query_info: Use the button to copy the query, then remplace the values with your data.
|
prefill_query_info: Use the button to copy the query, then remplace the values with your data.
|
||||||
prefill_query_response_html: '# Response:<br># {<br># "dossier_url": "%{url}",<br># "dossier_id": "aBase64Id==",<br># "dossier_number": 42<br># }'
|
prefill_query_response_html: '# Response:<br># {<br># "dossier_url": "%{url}",<br># "dossier_id": "aBase64Id==",<br># "dossier_number": 42<br># }'
|
||||||
prefill_query_copy: Copy prefill query
|
prefill_query_copy: Copy prefill query
|
||||||
|
json_description_title: JSON description of the procedure
|
||||||
|
json_description_info: Use the button to copy the query and learn more about the procedure and its fields thanks to a JSON description.
|
||||||
|
json_description_copy: Copy the JSON description query
|
||||||
registrations:
|
registrations:
|
||||||
new:
|
new:
|
||||||
title: "Create an account %{name}"
|
title: "Create an account %{name}"
|
||||||
|
|
|
@ -141,6 +141,9 @@ fr:
|
||||||
prefill_query_info: Copiez la requête grâce au bouton ci-dessous et remplacez les valeurs par les données dont vous disposez.
|
prefill_query_info: Copiez la requête grâce au bouton ci-dessous et remplacez les valeurs par les données dont vous disposez.
|
||||||
prefill_query_response_html: '# Response:<br># {<br># "dossier_url": "%{url}",<br># "dossier_id": "aBase64Id==",<br># "dossier_number": 42<br># }'
|
prefill_query_response_html: '# Response:<br># {<br># "dossier_url": "%{url}",<br># "dossier_id": "aBase64Id==",<br># "dossier_number": 42<br># }'
|
||||||
prefill_query_copy: Copier la requête de préremplissage
|
prefill_query_copy: Copier la requête de préremplissage
|
||||||
|
json_description_title: Description JSON de la démarche
|
||||||
|
json_description_info: Copiez la requête grâce au bouton ci-dessous pour découvrir les détails de la démarche et de ses champs au format JSON
|
||||||
|
json_description_copy: Copier la requête d'obtention de la description JSON
|
||||||
registrations:
|
registrations:
|
||||||
new:
|
new:
|
||||||
title: "Creation de compte sur %{name}"
|
title: "Creation de compte sur %{name}"
|
||||||
|
|
|
@ -198,6 +198,7 @@ Rails.application.routes.draw do
|
||||||
match "webhooks/helpscout", to: lambda { |_| [204, {}, nil] }, via: :head
|
match "webhooks/helpscout", to: lambda { |_| [204, {}, nil] }, via: :head
|
||||||
|
|
||||||
get '/preremplir/:path', to: 'prefill_descriptions#edit', as: :preremplir
|
get '/preremplir/:path', to: 'prefill_descriptions#edit', as: :preremplir
|
||||||
|
get '/preremplir/:path/schema', to: 'api/public/v1/json_description_procedures#show', as: :prefill_json_description, defaults: { format: :json }
|
||||||
resources :procedures, only: [], param: :path do
|
resources :procedures, only: [], param: :path do
|
||||||
member do
|
member do
|
||||||
resource :prefill_description, only: :update
|
resource :prefill_description, only: :update
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
RSpec.describe API::Public::V1::JSONDescriptionProceduresController, type: :controller do
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
|
describe '#show' do
|
||||||
|
let(:procedure) { create(:procedure, :published, :with_type_de_champ) }
|
||||||
|
subject(:show_request) do
|
||||||
|
get :show, params: params
|
||||||
|
end
|
||||||
|
|
||||||
|
before { show_request }
|
||||||
|
|
||||||
|
context 'the procedure is found' do
|
||||||
|
let(:params) { { path: procedure.path } }
|
||||||
|
let(:expected_response) do
|
||||||
|
API::V2::Schema.execute(API::V2::StoredQuery.get('ds-query-v2'),
|
||||||
|
variables: {
|
||||||
|
demarche: { "number": procedure.id },
|
||||||
|
includeRevision: true
|
||||||
|
},
|
||||||
|
operation_name: "getDemarcheDescriptor")
|
||||||
|
.to_h.dig("data", "demarcheDescriptor").to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:success) }
|
||||||
|
|
||||||
|
it { expect(response.body).to eq(expected_response) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "the procedure is not found" do
|
||||||
|
let(:params) { { path: "error" } }
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:not_found) }
|
||||||
|
|
||||||
|
it { expect(response).to have_failed_with("procedure error is not found") }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue