Skip to content

Commit

Permalink
Break MHV user account cache when user/mhv_user_account endpoint is c…
Browse files Browse the repository at this point in the history
…alled
  • Loading branch information
rileyanderson committed Oct 25, 2024
1 parent 4dc4da3 commit 857349c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
3 changes: 2 additions & 1 deletion app/controllers/v0/user/mhv_user_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def show
private

def set_mhv_user_account
@mhv_user_account = current_user.mhv_user_account
@mhv_user_account = MHV::UserAccount::Creator.new(user_verification: current_user.user_verification,
break_cache: true).perform
end

def render_errors(error_message, status: :unprocessable_entity)
Expand Down
19 changes: 6 additions & 13 deletions spec/controllers/v0/user/mhv_user_accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
require 'mhv/account_creation/service'

describe V0::User::MHVUserAccountsController, type: :controller do
let(:user) { build(:user, :loa3, vha_facility_ids:, icn:) }
let(:vha_facility_ids) { %w[450MH] }
let(:user) { build(:user, :loa3, icn:) }
let(:icn) { '10101V964144' }

let!(:user_verification) do
Expand Down Expand Up @@ -42,21 +41,15 @@
allow(mhv_client).to receive(:create_account).and_return(mhv_response)
end

it 'returns the MHV account' do
it 'breaks the cache and returns the MHV account' do
get :show

expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)['data']['attributes']).to eq(mhv_response.with_indifferent_access)
end
end

context 'when the user does not have an MHV account' do
let(:vha_facility_ids) { [] }

it 'returns a 404' do
get :show

expect(response).to have_http_status(:not_found)
expect(mhv_client).to have_received(:create_account).with(icn:,
email: user_credential_email.credential_email,
tou_occurred_at: terms_of_use_agreement.created_at,
break_cache: true)
end
end

Expand Down

0 comments on commit 857349c

Please sign in to comment.