Skip to content

Commit

Permalink
fix account show presenter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdembe committed Jan 16, 2025
1 parent ff437fc commit 031baec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/presenters/account_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ def connected_apps
user.connected_apps.includes([:service_provider_record, :email_address])
end

def show_change_option
def hide_change_option
binding.pry
if requested_attributes
requested_attributes.include?('all_emails') ||
!requested_attributes.include?('email')
requested_attributes.include?('email')
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/accounts/_connected_app.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
timestamp_html: render(TimeComponent.new(time: identity.created_at)),
) %>
<br />
<% if !@presenter.show_change_option %>
<% if !@presenter.hide_change_option %>
<strong>
<%= identity.email_address&.email || t('account.connected_apps.email_not_selected') %>
</strong>
Expand Down
23 changes: 19 additions & 4 deletions spec/presenters/account_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@
end
end

describe '#hide_change_option' do
describe '#show_change_option' do
let(:view_context) { ActionController::Base.new.view_context }
let(:service_provider) { create(:service_provider) }
let(:view_context) { ActionController::Base.new.view_context }
Expand All @@ -693,7 +693,7 @@
)
end

it 'returns false if option is not available' do
it 'returns false when option should be shown' do
user = User.new
account_show = AccountShowPresenter.new(
decrypted_pii: {},
Expand All @@ -702,10 +702,25 @@
sp_name: nil,
user: user,
locked_for_session: false,
requested_attributes: false,
requested_attributes: ['ssn'],
)

expect(account_show.hide_change_option).to eq(false)
end

it 'returns true when option should be hidden' do
user = User.new
account_show = AccountShowPresenter.new(
decrypted_pii: {},
sp_session_request_url: nil,
authn_context: nil,
sp_name: nil,
user: user,
locked_for_session: false,
requested_attributes: ['all_emails'],
)

expect(account_show.requested_attributes).to eq(false)
expect(account_show.hide_change_option).to eq(true)
end
end
end

0 comments on commit 031baec

Please sign in to comment.