Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vi-35 ToU check agreement changed #18534

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved

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
163 changes: 109 additions & 54 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,161 @@
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' }

it 'logs a warning message' do
job.perform(user_account_uuid, version)
context 'when multiple sec_id values are detected' do
let(:sec_ids) { [sec_id, 'other-sec-id'] }

expect(Rails.logger).to have_received(:info).with(expected_log, icn:)
end
let(:expected_log) { '[TermsOfUse][SignUpServiceUpdaterJob] Multiple sec_id values detected' }

it 'updates the terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)
it 'logs a warning message' do
job.perform(user_account_uuid, version)

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
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
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' }

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

it 'logs a detected changed ICN message' 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
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 } }

it_behaves_like 'logs an unchanged agreement'

before do
allow(Rails.logger).to receive(:info)
it 'does not update terms of use agreement in sign up service' do
job.perform(user_account_uuid, version)

expect(service_instance).not_to have_received(:agreements_decline)
end
end

it 'logs a detected changed ICN message' do
context 'when sign up service status opt out response is false' do
let(:status) { { opt_out: false, agreement_signed: false } }

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: })
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
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' }
let(:status) { { opt_out: false, agreement_signed: false } }

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

it 'logs a detected changed ICN message' 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
end
end

context 'and user account icn does not equal the mpi profile icn' do
let(:mpi_profile) { build(:mpi_profile, icn: mpi_icn, sec_id:, given_names:, family_name:) }
let(:mpi_icn) { 'some-mpi-icn' }
let(:status) { { opt_out: false, agreement_signed: false } }
let(:response) { 'declined' }

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

emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
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(service_instance).to have_received(:agreements_decline).with(icn: mpi_profile.icn)
expect(service_instance).to have_received(:agreements_decline).with(icn: mpi_icn)
end
end
end
Expand Down
Loading