Skip to content

Commit

Permalink
Merge pull request #9749 from DFE-Digital/cv/fix-audits
Browse files Browse the repository at this point in the history
Fix provider audit logs
  • Loading branch information
CatalinVoineag authored Aug 23, 2024
2 parents a3836e7 + 65a52ee commit 5264989
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/views/provider_interface/activity_log/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% ignored_audits = %w[ApplicationWorkHistoryBreak ApplicationExperience] %>
<% content_for :browser_title, 'Activity log' %>

<div class="govuk-grid-row">
Expand All @@ -7,6 +8,7 @@
<div class="govuk-!-margin-top-0">
<% previous_date = '' %>
<% @events.each do |event| %>
<% next if ignored_audits.include?(event.try(:auditable_type)) %>
<% current_date = event.created_at.to_fs(:govuk_date) %>
<% if current_date != previous_date %>
</div>
Expand Down
44 changes: 44 additions & 0 deletions spec/factories/audit.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
FactoryBot.define do
factory :application_experience_audit, class: 'Audited::Audit' do
action { 'create' }
user { create(:support_user) }
version { 1 }
request_uuid { SecureRandom.uuid }
created_at { Time.zone.now }

transient do
application_experience { build_stubbed(:application_experience) }
application_choice { build_stubbed(:application_choice, :awaiting_provider_decision) }
changes { {} }
end

after(:build) do |audit, evaluator|
audit.auditable_type = 'ApplicationExperience'
audit.auditable_id = evaluator.application_experience.id
audit.associated = evaluator.application_choice
audit.user_type = evaluator.user.class.to_s
audit.audited_changes = evaluator.changes
end
end

factory :application_work_history_break_audit, class: 'Audited::Audit' do
action { 'create' }
user { create(:support_user) }
version { 1 }
request_uuid { SecureRandom.uuid }
created_at { Time.zone.now }

transient do
application_work_history_break { build_stubbed(:application_work_history_break) }
application_choice { build_stubbed(:application_choice, :awaiting_provider_decision) }
changes { {} }
end

after(:build) do |audit, evaluator|
audit.auditable_type = 'ApplicationWorkHistoryBreak'
audit.auditable_id = evaluator.application_work_history_break.id
audit.associated = evaluator.application_choice
audit.user_type = evaluator.user.class.to_s
audit.audited_changes = evaluator.changes
end
end

factory :withdrawn_at_candidates_request_audit, class: 'Audited::Audit' do
action { 'update' }
user { create(:provider_user) }
Expand Down
12 changes: 12 additions & 0 deletions spec/system/provider_interface/see_activity_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def and_my_organisation_has_applications

@choice2 = create(:application_choice, :rejected, course_option: course_option2)
create(:application_choice_audit, :with_rejection, application_choice: @choice2)
work_experience = create(:application_work_experience, experienceable: @choice2)
work_history_break = create(:application_work_history_break, breakable: @choice2)
create(
:application_experience_audit,
application_experience: work_experience,
application_choice: @choice2,
)
create(
:application_work_history_break_audit,
application_work_history_break: work_history_break,
application_choice: @choice2,
)

@choice3 = create(:application_choice, :offered, course_option: course_option3)
create(:application_choice_audit, :with_offer, application_choice: @choice3)
Expand Down

0 comments on commit 5264989

Please sign in to comment.