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 6 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
34 changes: 31 additions & 3 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 !sec_id? || agreement_unchanged?
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved

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

def client
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
@client ||= MAP::SignUp::Service.new
end

def status
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
@status ||= client.status(icn: mpi_profile.icn)
end

def declined?
status[:opt_out] == true
end

def accepted?
status[:agreement_signed] == true
end
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved

def agreement_unchanged?
return false unless terms_of_use_agreement

unchanged = (terms_of_use_agreement.declined? == declined?) && (terms_of_use_agreement.accepted? == accepted?)
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved

if unchanged == true
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
Rails.logger.info("#{LOG_TITLE} Agreement not changed",
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
{ icn: user_account.icn })
end
unchanged
end

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

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

def sec_id?
Expand Down
57 changes: 57 additions & 0 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 @@ -184,6 +184,63 @@
end
end

context 'when agreement is changed by ToU acceptance' do
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
let(:response) { 'accepted' }
let(:status) { { opt_out: true, agreement_signed: false } }

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

it 'agreement_unchanged returns false' do
job.perform(user_account_uuid, version)

expect(MAP::SignUp::Service).to have_received(:new)
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
expect(service_instance).to have_received(:agreements_accept).with(icn: user_account.icn,
signature_name: common_name,
version:)
end
end

context 'when agreement is changed by ToU being declined' do
let(:response) { 'declined' }
let(:status) { { opt_out: false, agreement_signed: true } }

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

it 'agreement_unchanged returns false' do
job.perform(user_account_uuid, version)

expect(MAP::SignUp::Service).to have_received(:new)
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
expect(service_instance).to have_received(:agreements_accept).with(icn: user_account.icn,
signature_name: common_name,
version:)
end
end

context 'when agreement is unchanged' do
let(:expected_log) do
'[TermsOfUse][SignUpServiceUpdaterJob] Agreement not changed'
end
let(:status) { { opt_out: false, agreement_signed: true } }

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

emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
it 'logs that the agreement is not changed' do
job.perform(user_account_uuid, version)

expect(MAP::SignUp::Service).to have_received(:new)
emilykim13 marked this conversation as resolved.
Show resolved Hide resolved
expect(Rails.logger).to have_received(:info).with(expected_log, icn:)
end
end

context 'when sec_id is not present' do
let(:sec_id) { nil }
let(:expected_log) do
Expand Down
Loading