From 1567da6296ce470c61daa4bded644b9046d28b6a Mon Sep 17 00:00:00 2001 From: Jason C Date: Tue, 16 Apr 2024 10:00:40 -0700 Subject: [PATCH] Mobile: Create EVSSClaim even when using lighthouse (#16337) * Create EVSSClaim even when using lighthouse * We don't need to return the claim * Update tests to be better --------- Co-authored-by: Tonksthebear --- .../mobile/v0/lighthouse_claims/proxy.rb | 21 +++++++++++-- ...laims_and_appeals_overview_request_spec.rb | 30 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/modules/mobile/app/services/mobile/v0/lighthouse_claims/proxy.rb b/modules/mobile/app/services/mobile/v0/lighthouse_claims/proxy.rb index 62ffba0da04..ebaec5b2ba5 100644 --- a/modules/mobile/app/services/mobile/v0/lighthouse_claims/proxy.rb +++ b/modules/mobile/app/services/mobile/v0/lighthouse_claims/proxy.rb @@ -14,12 +14,14 @@ def request_decision(id) claims_service.submit5103(@user, id) end + # Temporary: We're adding the claims to the EVSSClaim table until decision letters switch over to lighthouse def get_all_claims lambda { begin - claims_list = claims_service.get_claims + claims_list = claims_service.get_claims['data'] + claims_list.each { |claim| create_or_update_claim(claim) } { - list: claims_list['data'], + list: claims_list, errors: nil } rescue => e @@ -33,6 +35,21 @@ def get_all_claims def claims_service @claims_service ||= BenefitsClaims::Service.new(@user.icn) end + + def claims_scope + @claims_scope ||= EVSSClaim.for_user(@user) + end + + def create_or_update_claim(raw_claim) + claim = claims_scope.where(evss_id: raw_claim['id']).first + if claim.blank? + claim = EVSSClaim.new(user_uuid: @user.uuid, + user_account: @user.user_account, + evss_id: raw_claim['id'], + data: {}) + end + claim.update(list_data: raw_claim) + end end end end diff --git a/modules/mobile/spec/request/claims_and_appeals_overview_request_spec.rb b/modules/mobile/spec/request/claims_and_appeals_overview_request_spec.rb index 843ade084d9..6bcf8c46bf1 100644 --- a/modules/mobile/spec/request/claims_and_appeals_overview_request_spec.rb +++ b/modules/mobile/spec/request/claims_and_appeals_overview_request_spec.rb @@ -485,6 +485,36 @@ end end end + + describe 'EVSSClaim count' do + it 'creates record if it does not exist' do + VCR.use_cassette(good_claims_response_vcr_path) do + VCR.use_cassette('mobile/appeals/appeals') do + expect do + get('/mobile/v0/claims-and-appeals-overview', headers: sis_headers, params:) + end.to change(EVSSClaim, :count) + end + end + end + + it 'updates record if it does exist' do + VCR.use_cassette(good_claims_response_vcr_path) do + VCR.use_cassette('mobile/appeals/appeals') do + evss_id = lighthouse_flag ? 600_383_363 : 600_114_693 + claim = EVSSClaim.create(user_uuid: sis_user.uuid, + user_account: sis_user.user_account, + evss_id:, + created_at: 1.week.ago, + updated_at: 1.week.ago, + data: {}) + expect do + get('/mobile/v0/claims-and-appeals-overview', headers: sis_headers, params:) + claim.reload + end.to change(claim, :updated_at) + end + end + end + end end end