Skip to content

Commit

Permalink
vi-35 ToU check agreement changed (#18534)
Browse files Browse the repository at this point in the history
* vi-35 ToU check agreement changed

* add test for nil case

* address rubocop

* address rubocop for job

* rspec for decline/accept conditions

* update rspec to not test private methods

* change sec_id to missing_sec_id

* clean up code

* rubocop

* working specs

* add test for changed agreement

* add test for agreement call when not changed

* rephrase spec descriptions

* rehprase description

* rubocop

* refactor code

* remove map_accepted/declined and fix rubocop

* remove double use in context

* move status instance up

* refactor rspec file

* refactor icn context

---------

Co-authored-by: Trevor Bosaw <[email protected]>
  • Loading branch information
emilykim13 and bosawt authored Oct 10, 2024
1 parent d05e2cb commit 680ec4a
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 63 deletions.
31 changes: 25 additions & 6 deletions app/sidekiq/terms_of_use/sign_up_service_updater_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def perform(user_account_uuid, version)
@user_account_uuid = user_account_uuid
@version = version

return unless sec_id?
return if missing_sec_id? || agreement_unchanged?

log_updated_icn
terms_of_use_agreement.accepted? ? accept : decline
Expand All @@ -48,23 +48,42 @@ def log_updated_icn
end
end

def map_client
@map_client ||= MAP::SignUp::Service.new
end

def map_status
@map_status ||= map_client.status(icn: mpi_profile.icn)
end

def agreement_unchanged?
if terms_of_use_agreement.declined? != map_status[:opt_out] ||
terms_of_use_agreement.accepted? != map_status[:agreement_signed]
return false
end

Rails.logger.info("#{LOG_TITLE} Not updating Sign Up Service due to unchanged agreement",
{ icn: user_account.icn })
true
end

def accept
MAP::SignUp::Service.new.agreements_accept(icn: mpi_profile.icn, signature_name:, version:)
map_client.agreements_accept(icn: mpi_profile.icn, signature_name:, version:)
end

def decline
MAP::SignUp::Service.new.agreements_decline(icn: mpi_profile.icn)
map_client.agreements_decline(icn: mpi_profile.icn)
end

def sec_id?
def missing_sec_id?
if mpi_profile.sec_id.present?
validate_multiple_sec_ids
return true
return false
end

Rails.logger.info("#{LOG_TITLE} Sign Up Service not updated due to user missing sec_id",
{ icn: user_account.icn })
false
true
end

def validate_multiple_sec_ids
Expand Down
138 changes: 81 additions & 57 deletions spec/sidekiq/terms_of_use/sign_up_service_updater_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,106 +80,130 @@
end

context 'when sec_id is present' do
context 'sec_id validation' do
let(:status) { { opt_out: false, agreement_signed: false } }

before do
allow(service_instance).to receive(:agreements_accept)
allow(service_instance).to receive(:status).and_return(status)
allow(Rails.logger).to receive(:info)
end

shared_examples 'logs an unchanged agreement' do
let(:expected_log) do
'[TermsOfUse][SignUpServiceUpdaterJob] Not updating Sign Up Service due to unchanged agreement'
end

before do
allow(service_instance).to receive(:agreements_accept)
allow(Rails.logger).to receive(:info)
end

context 'when a single sec_id value is detected' do
it 'does not log a warning message' do
job.perform(user_account_uuid, version)
it 'logs that the agreement is not changed' do
job.perform(user_account_uuid, version)

expect(Rails.logger).not_to have_received(:info)
end
expect(Rails.logger).to have_received(:info).with(expected_log, icn:)
end
end

context 'when multiple sec_id values are detected' do
let(:sec_ids) { [sec_id, 'other-sec-id'] }
let(:expected_log) { '[TermsOfUse][SignUpServiceUpdaterJob] Multiple sec_id values detected' }
shared_examples 'logs an icn mismatch warning' do
let(:expected_log) do
'[TermsOfUse][SignUpServiceUpdaterJob] Detected changed ICN for user'
end
let(:mpi_profile) { build(:mpi_profile, icn: mpi_icn, sec_id:, given_names:, family_name:) }
let(:mpi_icn) { 'some-mpi-icn' }

it 'logs a warning message' do
job.perform(user_account_uuid, version)
before do
allow(Rails.logger).to receive(:info)
end

expect(Rails.logger).to have_received(:info).with(expected_log, icn:)
end
it 'logs a detected changed ICN message' do
job.perform(user_account_uuid, version)

it 'updates the terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)
expect(MAP::SignUp::Service).to have_received(:new)
expect(Rails.logger).to have_received(:info).with(expected_log, { icn:, mpi_icn: })
end
end

expect(MAP::SignUp::Service).to have_received(:new)
expect(service_instance).to have_received(:agreements_accept).with(icn: user_account.icn,
signature_name: common_name,
version:)
end
context 'when multiple sec_id values are detected' do
let(:sec_ids) { [sec_id, 'other-sec-id'] }

let(:expected_log) { '[TermsOfUse][SignUpServiceUpdaterJob] Multiple sec_id values detected' }

it 'logs a warning message' do
job.perform(user_account_uuid, version)

expect(Rails.logger).to have_received(:info).with(expected_log, icn:)
end
end

context 'when the terms of use agreement is accepted' do
context 'and terms of use agreement is accepted' do
let(:response) { 'accepted' }

before do
allow(service_instance).to receive(:status).and_return(status)
allow(service_instance).to receive(:agreements_accept)
end

context 'and user account icn does not equal the mpi profile icn' do
let(:expected_log) do
'[TermsOfUse][SignUpServiceUpdaterJob] Detected changed ICN for user'
end
let(:mpi_profile) { build(:mpi_profile, icn: mpi_icn, sec_id:, given_names:, family_name:) }
let(:mpi_icn) { 'some-mpi-icn' }
context 'when sign up service status agreement response is true' do
let(:status) { { opt_out: false, agreement_signed: true } }

before do
allow(Rails.logger).to receive(:info)
end
it_behaves_like 'logs an unchanged agreement'

it 'logs a detected changed ICN message' do
it 'does not update terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)

expect(MAP::SignUp::Service).to have_received(:new)
expect(Rails.logger).to have_received(:info).with(expected_log, { icn:, mpi_icn: })
expect(service_instance).not_to have_received(:agreements_accept)
end
end

it 'updates the terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)
context 'when sign up service status agreement response is false' do
let(:status) { { opt_out: false, agreement_signed: false } }

expect(MAP::SignUp::Service).to have_received(:new)
expect(service_instance).to have_received(:agreements_accept).with(icn: mpi_profile.icn,
signature_name: common_name,
version:)
it 'updates the terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)

expect(service_instance).to have_received(:agreements_accept).with(icn: user_account.icn,
signature_name: common_name,
version:)
end

context 'and user account icn does not equal the mpi profile icn' do
it_behaves_like 'logs an icn mismatch warning'
end
end
end

context 'when the terms of use agreement is declined' do
context 'and terms of use agreement is declined' do
let(:response) { 'declined' }

before do
allow(service_instance).to receive(:status).and_return(status)
allow(service_instance).to receive(:agreements_decline)
end

context 'and user account icn does not equal the mpi profile icn' do
let(:expected_log) do
'[TermsOfUse][SignUpServiceUpdaterJob] Detected changed ICN for user'
end
let(:mpi_profile) { build(:mpi_profile, icn: mpi_icn, sec_id:, given_names:, family_name:) }
let(:mpi_icn) { 'some-mpi-icn' }
context 'when sign up service status opt out response is true' do
let(:status) { { opt_out: true, agreement_signed: false } }

before do
allow(Rails.logger).to receive(:info)
end
it_behaves_like 'logs an unchanged agreement'

it 'logs a detected changed ICN message' do
it 'does not update terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)

expect(MAP::SignUp::Service).to have_received(:new)
expect(Rails.logger).to have_received(:info).with(expected_log, { icn:, mpi_icn: })
expect(service_instance).not_to have_received(:agreements_decline)
end
end

it 'updates the terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)
context 'when sign up service status opt out response is false' do
let(:status) { { opt_out: false, agreement_signed: false } }

expect(MAP::SignUp::Service).to have_received(:new)
expect(service_instance).to have_received(:agreements_decline).with(icn: mpi_profile.icn)
it 'updates the terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)

expect(service_instance).to have_received(:agreements_decline).with(icn: user_account.icn)
end

context 'and user account icn does not equal the mpi profile icn' do
it_behaves_like 'logs an icn mismatch warning'
end
end
end
end
Expand Down

0 comments on commit 680ec4a

Please sign in to comment.