From 2df3e7c106357ef79169ac111a8d610aa85d4e98 Mon Sep 17 00:00:00 2001 From: Avin Hurry Date: Wed, 22 Jan 2025 18:10:37 +0000 Subject: [PATCH 1/2] [594] Surface if candidate has one login account Via support console --- .../application_summary_component.rb | 12 +++++ .../application_summary_component_spec.rb | 48 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/app/components/support_interface/application_summary_component.rb b/app/components/support_interface/application_summary_component.rb index e2d4f0995ae..66600843d33 100644 --- a/app/components/support_interface/application_summary_component.rb +++ b/app/components/support_interface/application_summary_component.rb @@ -25,6 +25,7 @@ def rows subsequent_application_row, average_distance_row, editable_extension_row, + one_login_account_row, ].compact end @@ -85,6 +86,13 @@ def candidate_id_row } end + def one_login_account_row + { + key: 'Has One Login account', + value: one_login? ? 'Yes' : 'No', + } + end + def state_row { key: 'State', @@ -140,6 +148,10 @@ def formatted_status "#{name}
#{desc}".html_safe end + def one_login? + application_form.candidate.one_login_auth.present? + end + attr_reader :application_form end end diff --git a/spec/components/support_interface/application_summary_component_spec.rb b/spec/components/support_interface/application_summary_component_spec.rb index 7949bdd27a3..5f9c3dfa80e 100644 --- a/spec/components/support_interface/application_summary_component_spec.rb +++ b/spec/components/support_interface/application_summary_component_spec.rb @@ -47,5 +47,53 @@ expect(result.css('.govuk-summary-list__key').text).not_to include('Is this application editable') end end + + context 'when the candidate has a OneLogin account' do + it 'displays "Yes" for the One Login account row' do + candidate = create(:candidate) + candidate.create_one_login_auth!( + token: '123', + email_address: candidate.email_address, + ) + application_form = create(:completed_application_form, candidate:) + + result = render_inline(described_class.new(application_form:)) + + expect(result.css('.govuk-summary-list__key').text).to include('Has One Login account') + expect(result.css('.govuk-summary-list__value').text).to include('Yes') + end + end + + context 'when the candidate does not have a OneLogin account' do + it 'displays "No" for the One Login account row' do + candidate = create(:candidate) + application_form = create(:completed_application_form, candidate:) + + result = render_inline(described_class.new(application_form:)) + + expect(result.css('.govuk-summary-list__key').text).to include('Has One Login account') + expect(result.css('.govuk-summary-list__value').text).to include('No') + end + end + + context 'when the candidate had a OneLogin account but it was deleted' do + it 'displays "No" for the One Login account row' do + candidate = create(:candidate) + one_login_auth = candidate.create_one_login_auth!( + token: '123', + email_address: candidate.email_address, + ) + + one_login_auth.delete + candidate.reload + + application_form = create(:completed_application_form, candidate:) + + result = render_inline(described_class.new(application_form:)) + + expect(result.css('.govuk-summary-list__key').text).to include('Has One Login account') + expect(result.css('.govuk-summary-list__value').text).to include('No') + end + end end end From be6750ead6b69046effddaf1f5c87ae942f7bb8c Mon Sep 17 00:00:00 2001 From: Avin Hurry Date: Thu, 23 Jan 2025 09:52:56 +0000 Subject: [PATCH 2/2] Add one_login_connected? method For candidate --- .../application_summary_component.rb | 3 ++- app/models/candidate.rb | 4 ++++ spec/models/candidate_spec.rb | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/components/support_interface/application_summary_component.rb b/app/components/support_interface/application_summary_component.rb index 66600843d33..a86925ef81c 100644 --- a/app/components/support_interface/application_summary_component.rb +++ b/app/components/support_interface/application_summary_component.rb @@ -7,6 +7,7 @@ class ApplicationSummaryComponent < ViewComponent::Base :submitted_at, :submitted?, :updated_at, + :candidate, to: :application_form def initialize(application_form:) @@ -149,7 +150,7 @@ def formatted_status end def one_login? - application_form.candidate.one_login_auth.present? + candidate.one_login_connected? end attr_reader :application_form diff --git a/app/models/candidate.rb b/app/models/candidate.rb index cfa22929f9e..380b5cd4021 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -121,6 +121,10 @@ def recoverable? !application_choices_submitted? end + def one_login_connected? + one_login_auth.present? + end + private def downcase_email diff --git a/spec/models/candidate_spec.rb b/spec/models/candidate_spec.rb index a7fe7872d72..9e004035e6f 100644 --- a/spec/models/candidate_spec.rb +++ b/spec/models/candidate_spec.rb @@ -404,4 +404,22 @@ end end end + + describe '#one_login_connected?' do + let(:candidate) { create(:candidate) } + + context 'when the candidate has a OneLoginAuth record' do + before { create(:one_login_auth, candidate:) } + + it 'returns true' do + expect(candidate.one_login_connected?).to be true + end + end + + context 'when the candidate does not have a OneLoginAuth record' do + it 'returns false' do + expect(candidate.one_login_connected?).to be false + end + end + end end