Skip to content

Commit

Permalink
[Automated] Merged master into target k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
va-vsp-bot authored Apr 17, 2024
2 parents bdd6a82 + 5142d07 commit e5bc24c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modules/check_in/app/services/v2/lorota/redis_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ def session_id_prefix(uuid:)
def retry_attempt_prefix(uuid:)
"authentication_retry_limit_#{uuid}"
end

def icn(uuid:)
fetch_attribute(uuid:, attribute: :icn)
end

def fetch_attribute(uuid:, attribute:)
identifiers = appointment_identifiers(uuid:)
return nil if identifiers.nil?

parsed_identifiers = Oj.load(identifiers).with_indifferent_access
parsed_identifiers.dig(:data, :attributes, attribute)
end

private

def appointment_identifiers(uuid:)
@appointment_identifiers ||= Hash.new do |h, key|
h[key] = Rails.cache.read(
"#{redis_session_prefix}_appointment_identifiers_#{key}",
namespace: 'check-in-lorota-v2-cache'
)
end
@appointment_identifiers[uuid]
end
end
end
end
58 changes: 58 additions & 0 deletions modules/check_in/spec/services/v2/lorota/redis_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@
let(:redis_expiry_time) { 12.hours }
let(:retry_attempt_expiry) { 7.days }

let(:uuid) { '755f64db-336f-4614-a3eb-15f732d48de1' }
let(:patient_icn) { '2113957154V785237' }
let(:mobile_phone) { '7141234567' }
let(:station_number) { '500' }
let(:patient_cell_phone) { '1234567890' }
let(:facility_type) { 'abc' }

let(:appointment_identifiers) do
{
data: {
id: uuid,
type: :appointment_identifier,
attributes: { patientDFN: '123', stationNo: station_number, icn: patient_icn, mobilePhone: mobile_phone,
patientCellPhone: patient_cell_phone, facilityType: facility_type }
}
}
end

before do
allow(Rails).to receive(:cache).and_return(memory_store)

Expand Down Expand Up @@ -172,4 +190,44 @@
expect(val).to eq(retry_count)
end
end

describe '#icn' do
context 'when cache does not exist' do
it 'returns nil' do
expect(redis_client.icn(uuid:)).to eq(nil)
end
end

context 'when cache exists' do
before do
Rails.cache.write(
"check_in_lorota_v2_appointment_identifiers_#{uuid}",
appointment_identifiers.to_json,
namespace: 'check-in-lorota-v2-cache',
expires_in: redis_expiry_time
)
end

it 'returns the cached value' do
expect(redis_client.icn(uuid:)).to eq(patient_icn)
end
end

context 'when cache has expired' do
before do
Rails.cache.write(
"check_in_lorota_v2_appointment_identifiers_#{uuid}",
appointment_identifiers.to_json,
namespace: 'check-in-lorota-v2-cache',
expires_in: redis_expiry_time
)
end

it 'returns nil' do
Timecop.travel(redis_expiry_time.from_now) do
expect(redis_client.icn(uuid:)).to eq(nil)
end
end
end
end
end

0 comments on commit e5bc24c

Please sign in to comment.