Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelfaure committed Dec 17, 2024
1 parent a8a698b commit d96341d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/facades/new_authorization_request/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def editors_index
}.sort
end

def public_available_forms
AuthorizationRequestFormDecorator.decorate_collection(authorization_definition.public_available_forms)
def public_available_forms(for_sandbox: false)
AuthorizationRequestFormDecorator.decorate_collection(authorization_definition.public_available_forms(for_sandbox:))
end

private
Expand Down
11 changes: 9 additions & 2 deletions app/models/authorization_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ def instructors_or_reporters
(instructors + reporters).uniq
end

def public_available_forms
# REVIEW: TODO can do better here
def public_available_forms(for_sandbox: false)
@for_sandbox = for_sandbox

available_forms.select do |form|
form.public &&
form.startable_by_applicant
end
end

def available_forms
def available_forms(for_sandbox: false)
@for_sandbox = for_sandbox

AuthorizationRequestForm.where(authorization_request_class:).sort do |form|
form.default ? 1 : 0
end
Expand All @@ -89,6 +94,8 @@ def startable_by_applicant
delegate :next_stage_form, :next_stage_definition, :next_stage?, to: :stage

def authorization_request_class
id = @for_sandbox ? "#{self.id}_sandbox" : self.id

@authorization_request_class ||= AuthorizationRequest.const_get(id.classify)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
id="forms"
class="fr-background-alt--blue-france fr-py-4w fr-hidden"
>
<%# TODO: Adapt facade to sandbox %>
<div class="fr-grid-row">
<div class="fr-col-md-10 fr-col-offset-1">
<p class="center fr-px-5w fr-py-1w">
Expand All @@ -111,7 +110,7 @@
</p>

<div class="fr-grid-row fr-grid-row--center">
<% @facade.public_available_forms.each do |authorization_request_form| %>
<% @facade.public_available_forms(for_sandbox: true).each do |authorization_request_form| %>
<div
data-choose-authorization-request-form-target="form"
data-choose-authorization-request-form-tags="<%= authorization_request_form.tags.to_json %>"
Expand All @@ -133,7 +132,6 @@
id="forms"
class="fr-background-alt--blue-france fr-py-4w fr-hidden"
>
<%# TODO: Adapt facade to editor %>
<div class="fr-grid-row">
<div class="fr-col-md-10 fr-col-offset-1">
<p class="center fr-px-5w fr-py-1w">
Expand All @@ -145,7 +143,7 @@
) %>
</p>
<div class="fr-grid-row fr-grid-row--center">
<% @facade.public_available_forms.each do |authorization_request_form| %>
<% @facade.public_available_forms(for_sandbox: false).each do |authorization_request_form| %>
<div
data-choose-authorization-request-form-target="form"
data-choose-authorization-request-form-tags="<%= authorization_request_form.tags.to_json %>"
Expand Down
15 changes: 15 additions & 0 deletions spec/models/authorization_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
form.authorization_request_class == AuthorizationRequest::APIEntreprise
end
end

context 'when for sandbox' do
subject(:available_forms_sandbox) { instance.available_forms(for_sandbox: true) }

let(:instance) { described_class.find('api_impot_particulier_sandbox') }

it 'returns a list of all forms' do
expect(available_forms.count).to be > 0

expect(available_forms).to be_all do |form|
form.is_a?(AuthorizationRequestForm) &&
form.authorization_request_class == AuthorizationRequest::APIImpotParticulierSandbox
end
end
end
end

describe '#editors' do
Expand Down

0 comments on commit d96341d

Please sign in to comment.