Skip to content

Commit

Permalink
Add copy authorization request event
Browse files Browse the repository at this point in the history
Mostly for data migration from v1
  • Loading branch information
skelz0r committed Apr 24, 2024
1 parent 086b338 commit 034f4d7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/decorators/authorization_request_event_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def text
end
alias comment text # see WebhookEventSerializer

def copied_from_authorization_request_id
return unless name == 'copy'

entity.copied_from_request.id
end

private

def humanized_changelog
Expand Down
2 changes: 2 additions & 0 deletions app/models/authorization_request_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class AuthorizationRequestEvent < ApplicationRecord
submit
update

copy

applicant_message
instructor_message

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
**{
user_full_name: authorization_request_event.user_full_name,
text: simple_format(authorization_request_event.text),
copied_from_authorization_request_id: authorization_request_event.copied_from_authorization_request_id,
}.compact
).html_safe
%>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ fr:
icon: close-circle-line
color: error

copy:
text: |
<strong>%{user_full_name}</strong> a copié la demande %{copied_from_authorization_request_id}
reopen:
text: "<strong>%{user_full_name}</strong> a réouvert l'habilitation"

Expand Down
18 changes: 17 additions & 1 deletion spec/factories/authorization_request_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
factory :authorization_request_event do
name { 'create' }
user
entity factory: %i[authorization_request]
entity factory: %i[authorization_request api_entreprise]

transient do
authorization_request { nil }
Expand Down Expand Up @@ -104,6 +104,22 @@
end
end

trait :copy do
entity factory: %i[authorization_request api_entreprise]
entity_is_authorization_request

name { 'copy' }

after(:build) do |authorization_request_event|
authorization_request = authorization_request_event.entity
authorization_request_trait = authorization_request.type.split('::').last.underscore.to_sym

copied_from_authorization_request = create(:authorization_request, :validated, authorization_request_trait, applicant: authorization_request.applicant)

authorization_request_event.entity.copied_from_request = copied_from_authorization_request
end
end

trait :applicant_message do
name { 'applicant_message' }

Expand Down
2 changes: 1 addition & 1 deletion spec/features/instruction/events_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe 'Instruction: habilitation events' do
let(:user) { create(:user, :instructor) }
let(:authorization_request) { create(:authorization_request, applicant: user) }
let(:authorization_request) { create(:authorization_request, :api_entreprise, applicant: user) }

before do
sign_in(user)
Expand Down
2 changes: 1 addition & 1 deletion spec/queries/authorization_request_events_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
describe '#perform' do
subject(:events) { described_class.new(authorization_request).perform }

let(:authorization_request) { create(:authorization_request).reload }
let(:authorization_request) { create(:authorization_request, :api_entreprise).reload }

before do
AuthorizationRequestEvent::NAMES.each_with_index do |event_name, index|
Expand Down

0 comments on commit 034f4d7

Please sign in to comment.