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

Api 35595 registration numbers #16469

Closed
wants to merge 5 commits into from
Closed
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
24 changes: 20 additions & 4 deletions modules/check_in/app/services/check_in/vaos/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@ class BaseService < Common::Client::Base
include SentryLogging
include Common::Client::Concerns::Monitoring

attr_reader :patient_icn, :token_service
attr_reader :check_in_session, :patient_icn

STATSD_KEY_PREFIX = 'api.check_in.vaos'

def initialize(patient_icn:)
@patient_icn = patient_icn
@token_service = CheckIn::Map::TokenService.build({ patient_icn: })
##
# Builds a Service instance
#
# @param opts [Hash] options to create the object
#
# @return [Service] an instance of this class
#
def self.build(opts = {})
new(opts)
end

def initialize(opts)
@check_in_session = opts[:check_in_session]
@patient_icn = ::V2::Lorota::RedisClient.build.icn(uuid: check_in_session.uuid)

super()
end

Expand All @@ -35,6 +47,10 @@ def headers
}
end

def token_service
@token_service ||= Map::TokenService.build(patient_icn:)
end

def referrer
if Settings.hostname.ends_with?('.gov')
"https://#{Settings.hostname}".gsub('vets', 'va')
Expand Down
21 changes: 10 additions & 11 deletions modules/check_in/spec/services/check_in/map/token_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
require 'rails_helper'

describe CheckIn::Map::TokenService do
subject { described_class }
subject { described_class.build(opts) }

let(:patient_icn) { '123' }
let(:opts) do
{
patient_icn:
}
end
let(:opts) { { patient_icn: } }
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }

before do
Expand All @@ -21,13 +17,13 @@

describe '.build' do
it 'returns an instance of Service' do
expect(subject.build(opts)).to be_an_instance_of(described_class)
expect(subject).to be_an_instance_of(described_class)
end
end

describe '#initialize' do
it 'has a redis client' do
expect(subject.build(opts).redis_client).to be_a(CheckIn::Map::RedisClient)
expect(subject.redis_client).to be_a(CheckIn::Map::RedisClient)
end
end

Expand All @@ -41,7 +37,7 @@
end

it 'returns token from redis' do
expect(subject.build(opts).token).to eq(access_token)
expect(subject.token).to eq(access_token)
end
end

Expand All @@ -51,8 +47,11 @@
.and_return({ access_token:, expiration: })
end

it 'returns token by calling client' do
expect(subject.build(opts).token).to eq(access_token)
it 'returns token by calling client and saves it in redis' do
redis_client = subject.redis_client
expect(redis_client).to receive(:save_token)

expect(subject.token).to eq(access_token)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
require 'rails_helper'

describe CheckIn::VAOS::AppointmentService do
subject { described_class.new(patient_icn:) }
subject { described_class }

let(:uuid) { 'd602d9eb-9a31-484f-9637-13ab0b507e0d' }
let(:check_in_session) { CheckIn::V2::Session.build(data: { uuid: }) }
let(:patient_icn) { '123' }
let(:token) { 'test_token' }
let(:request_id) { SecureRandom.uuid }

describe '#initialize' do
it 'returns an instance of service' do
service_obj = subject
expect(service_obj).to be_an_instance_of(CheckIn::VAOS::AppointmentService)
expect(service_obj.token_service).to be_an_instance_of(CheckIn::Map::TokenService)
describe '.build' do
it 'returns an instance of Service' do
expect(subject.build(check_in_session:)).to be_an_instance_of(described_class)
end
end

Expand Down Expand Up @@ -42,21 +42,27 @@
let(:faraday_response) { double('Faraday::Response') }
let(:faraday_env) { double('Faraday::Env', status: 200, body: appointments_response.to_json) }

before do
allow_any_instance_of(V2::Lorota::RedisClient).to receive(:icn).with(uuid:)
.and_return(patient_icn)
allow_any_instance_of(CheckIn::Map::TokenService).to receive(:token)
.and_return(token)
end

context 'when vaos returns successful response' do
before do
allow_any_instance_of(CheckIn::Map::TokenService).to receive(:token)
.and_return(token)
allow_any_instance_of(Faraday::Connection).to receive(:get).with('/vaos/v1/patients/123/appointments',
{ start: start_date, end: end_date,
statuses: })
.and_return(faraday_response)
allow_any_instance_of(Faraday::Connection).to receive(:get)
.with("/vaos/v1/patients/#{patient_icn}/appointments",
{ start: start_date, end: end_date, statuses: })
.and_return(faraday_response)
allow(faraday_response).to receive(:env).and_return(faraday_env)
end

it 'returns appointments' do
response = subject.get_appointments(DateTime.parse(start_date).in_time_zone,
DateTime.parse(end_date).in_time_zone,
statuses)
svc = subject.build(check_in_session:)
response = svc.get_appointments(DateTime.parse(start_date).in_time_zone,
DateTime.parse(end_date).in_time_zone,
statuses)
expect(response).to eq(appointments_response)
end
end
Expand All @@ -66,19 +72,18 @@
let(:exception) { Common::Exceptions::BackendServiceException.new(nil, {}, resp.status, resp.body) }

before do
allow_any_instance_of(CheckIn::Map::TokenService).to receive(:token)
.and_return(token)
allow_any_instance_of(Faraday::Connection).to receive(:get).with('/vaos/v1/patients/123/appointments',
{ start: start_date, end: end_date,
statuses: })
.and_raise(exception)
end

it 'throws exception' do
svc = subject.build(check_in_session:)
expect do
subject.get_appointments(DateTime.parse(start_date).in_time_zone,
DateTime.parse(end_date).in_time_zone,
statuses)
svc.get_appointments(DateTime.parse(start_date).in_time_zone,
DateTime.parse(end_date).in_time_zone,
statuses)
end.to(raise_error do |error|
expect(error).to be_a(Common::Exceptions::BackendServiceException)
end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,35 @@
require 'rails_helper'

describe CheckIn::VAOS::BaseService do
subject { described_class.new(patient_icn:) }
subject { described_class.build(check_in_session:) }

let(:uuid) { 'd602d9eb-9a31-484f-9637-13ab0b507e0d' }
let(:check_in_session) { CheckIn::V2::Session.build(data: { uuid: }) }
let(:patient_icn) { '123' }
let(:token) { 'test_token' }
let(:request_id) { SecureRandom.uuid }

describe '.build' do
it 'returns an instance of Service' do
expect(subject).to be_an_instance_of(described_class)
end
end

describe '#initialize' do
before do
allow_any_instance_of(V2::Lorota::RedisClient).to receive(:icn).with(uuid:)
.and_return(patient_icn)
end

it 'has a check_in_session object' do
expect(subject.check_in_session).to be_a(CheckIn::V2::Session)
end

it 'has a patient icn' do
expect(subject.patient_icn).to eq(patient_icn)
end
end

describe '#config' do
it 'returns an instance of Configuration' do
expect(subject.config).to be_an_instance_of(CheckIn::VAOS::Configuration)
Expand All @@ -17,8 +40,9 @@

describe '#headers' do
before do
allow_any_instance_of(CheckIn::Map::TokenService).to receive(:token).and_return(token)
RequestStore.store['request_id'] = request_id

allow_any_instance_of(CheckIn::Map::TokenService).to receive(:token).and_return(token)
end

it 'returns correct headers' do
Expand Down
Loading
Loading