From 68f0a0d4768c35f93d3c1fff4abe0ab34e69e9fd Mon Sep 17 00:00:00 2001 From: Andrew Herzberg Date: Tue, 6 Jun 2023 13:57:35 -0700 Subject: [PATCH] mobile - lighthouse claims request decision (#12896) --- .../v0/claims_and_appeals_controller.rb | 10 ++- .../mobile/v0/lighthouse_claims/proxy.rb | 4 + .../request/claims_decision_request_spec.rb | 27 ++++-- .../legacy_claims_decision_request_spec.rb | 25 ++++++ .../request_decision/200_response.yml | 82 +++++++++++++++++++ .../request_decision/404_response.yml | 78 ++++++++++++++++++ 6 files changed, 214 insertions(+), 12 deletions(-) create mode 100644 modules/mobile/spec/request/legacy_claims_decision_request_spec.rb create mode 100644 spec/support/vcr_cassettes/mobile/lighthouse_claims/request_decision/200_response.yml create mode 100644 spec/support/vcr_cassettes/mobile/lighthouse_claims/request_decision/404_response.yml diff --git a/modules/mobile/app/controllers/mobile/v0/claims_and_appeals_controller.rb b/modules/mobile/app/controllers/mobile/v0/claims_and_appeals_controller.rb index 7f339e990d7..5bac6b138fd 100644 --- a/modules/mobile/app/controllers/mobile/v0/claims_and_appeals_controller.rb +++ b/modules/mobile/app/controllers/mobile/v0/claims_and_appeals_controller.rb @@ -12,7 +12,7 @@ module Mobile module V0 class ClaimsAndAppealsController < ApplicationController include IgnoreNotFound - before_action(only: %i[index get_claim]) do + before_action(only: %i[index get_claim request_decision]) do if Flipper.enabled?(:mobile_lighthouse_claims, @current_user) authorize :lighthouse, :access? else @@ -20,7 +20,7 @@ class ClaimsAndAppealsController < ApplicationController end end - before_action(except: %i[index get_claim]) do + before_action(except: %i[index get_claim request_decision]) do authorize :evss, :access? end @@ -50,7 +50,11 @@ def get_appeal end def request_decision - jid = evss_claims_proxy.request_decision(params[:id]) + jid = if Flipper.enabled?(:mobile_lighthouse_claims, @current_user) + lighthouse_claims_proxy.request_decision(params[:id]) + else + evss_claims_proxy.request_decision(params[:id]) + end render json: { data: { job_id: jid } }, status: :accepted end 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 0e587b22ca7..481006597a9 100644 --- a/modules/mobile/app/services/mobile/v0/lighthouse_claims/proxy.rb +++ b/modules/mobile/app/services/mobile/v0/lighthouse_claims/proxy.rb @@ -24,6 +24,10 @@ def get_claims_and_appeals [data, errors] end + def request_decision(id) + claims_service.submit5103(id) + end + private def claims_adapter diff --git a/modules/mobile/spec/request/claims_decision_request_spec.rb b/modules/mobile/spec/request/claims_decision_request_spec.rb index 9f5219a414f..999a7394d4e 100644 --- a/modules/mobile/spec/request/claims_decision_request_spec.rb +++ b/modules/mobile/spec/request/claims_decision_request_spec.rb @@ -3,22 +3,31 @@ require 'rails_helper' require_relative '../support/helpers/iam_session_helper' -RSpec.describe 'claims decision request', type: :request do +RSpec.describe 'lighthouse claims decision request', type: :request do describe 'GET /v0/claim/:id/request-decision' do before do - iam_sign_in - FactoryBot.create(:evss_claim, id: 1, evss_id: 600_117_255, user_uuid: '3097e489-ad75-5746-ab1a-e0aabc1b426a') + token = 'abcdefghijklmnop' + allow_any_instance_of(BenefitsClaims::Configuration).to receive(:access_token).and_return(token) + user = build(:iam_user) + iam_sign_in(user) + Flipper.enable(:mobile_lighthouse_claims, user) end + after { Flipper.disable(:mobile_lighthouse_claims) } + it 'returns jid with 202 status' do - post '/mobile/v0/claim/600117255/request-decision', headers: iam_headers - expect(response.status).to eq(202) - expect(response.parsed_body.dig('data', 'jobId')).to eq(EVSS::RequestDecision.jobs.first['jid']) + VCR.use_cassette('mobile/lighthouse_claims/request_decision/200_response') do + post '/mobile/v0/claim/600397108/request-decision', headers: iam_headers + end + expect(response).to have_http_status(:accepted) + expect(response.parsed_body.dig('data', 'jobId')).to eq({ 'success' => true }) end - it 'returns 500 for non-existent record' do - post '/mobile/v0/claim/3242233/request-decision', headers: iam_headers - expect(response.status).to eq(500) + it 'returns 404 for non-existent record' do + VCR.use_cassette('mobile/lighthouse_claims/request_decision/404_response') do + post '/mobile/v0/claim/600397108/request-decision', headers: iam_headers + end + expect(response).to have_http_status(:not_found) end end end diff --git a/modules/mobile/spec/request/legacy_claims_decision_request_spec.rb b/modules/mobile/spec/request/legacy_claims_decision_request_spec.rb new file mode 100644 index 00000000000..3e5c32da92b --- /dev/null +++ b/modules/mobile/spec/request/legacy_claims_decision_request_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'rails_helper' +require_relative '../support/helpers/iam_session_helper' + +RSpec.describe 'claims decision request', type: :request do + describe 'GET /v0/claim/:id/request-decision' do + before do + iam_sign_in + FactoryBot.create(:evss_claim, id: 1, evss_id: 600_117_255, user_uuid: '3097e489-ad75-5746-ab1a-e0aabc1b426a') + Flipper.disable(:mobile_lighthouse_claims) + end + + it 'returns jid with 202 status' do + post '/mobile/v0/claim/600117255/request-decision', headers: iam_headers + expect(response).to have_http_status(:accepted) + expect(response.parsed_body.dig('data', 'jobId')).to eq(EVSS::RequestDecision.jobs.first['jid']) + end + + it 'returns 500 for non-existent record' do + post '/mobile/v0/claim/3242233/request-decision', headers: iam_headers + expect(response).to have_http_status(:internal_server_error) + end + end +end diff --git a/spec/support/vcr_cassettes/mobile/lighthouse_claims/request_decision/200_response.yml b/spec/support/vcr_cassettes/mobile/lighthouse_claims/request_decision/200_response.yml new file mode 100644 index 00000000000..e1ee1d198a2 --- /dev/null +++ b/spec/support/vcr_cassettes/mobile/lighthouse_claims/request_decision/200_response.yml @@ -0,0 +1,82 @@ +--- +http_interactions: +- request: + method: post + uri: https://sandbox-api.va.gov/services/claims/v2/veterans/1008596379V859838/claims/600397108/5103 + body: + encoding: UTF-8 + string: "{}" + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - Bearer fake_access_token + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 01 Jun 2023 18:09:39 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '16' + Connection: + - keep-alive + X-Ratelimit-Remaining-Minute: + - '59' + X-Ratelimit-Limit-Minute: + - '60' + Ratelimit-Remaining: + - '59' + Ratelimit-Limit: + - '60' + Ratelimit-Reset: + - '22' + Etag: + - W/"c955e57777ec0d73639dca6748560d00" + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Custom-Response-Header: + - eks-staging + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Git-Sha: + - 6e7211ba39afc48551d417bbfeb8a6a251585bda + X-Github-Repository: + - https://github.com/department-of-veterans-affairs/vets-api + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - 39011c07-f65a-4a88-820e-49e862c62275 + X-Runtime: + - '1.210936' + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Cache-Control: + - no-cache, no-store + Pragma: + - no-cache + body: + encoding: UTF-8 + string: '{"success":true}' + recorded_at: Thu, 01 Jun 2023 18:09:39 GMT +recorded_with: VCR 6.1.0 diff --git a/spec/support/vcr_cassettes/mobile/lighthouse_claims/request_decision/404_response.yml b/spec/support/vcr_cassettes/mobile/lighthouse_claims/request_decision/404_response.yml new file mode 100644 index 00000000000..93e310b0816 --- /dev/null +++ b/spec/support/vcr_cassettes/mobile/lighthouse_claims/request_decision/404_response.yml @@ -0,0 +1,78 @@ +--- +http_interactions: +- request: + method: post + uri: https://sandbox-api.va.gov/services/claims/v2/veterans/1008596379V859838/claims/600397108/5103 + body: + encoding: UTF-8 + string: "{}" + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - Bearer fake_access_token + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Thu, 01 Jun 2023 18:20:52 GMT + Content-Type: + - application/json; charset=utf-8 + Connection: + - keep-alive + X-Ratelimit-Remaining-Minute: + - '58' + X-Ratelimit-Limit-Minute: + - '60' + Ratelimit-Remaining: + - '58' + Ratelimit-Limit: + - '60' + Ratelimit-Reset: + - '8' + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Custom-Response-Header: + - eks-staging + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Git-Sha: + - 6e7211ba39afc48551d417bbfeb8a6a251585bda + X-Github-Repository: + - https://github.com/department-of-veterans-affairs/vets-api + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - 05134f3f-0a86-49ac-be5f-a3d23ed786aa + X-Runtime: + - '0.034137' + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: '{"errors":[{"title":"Resource not found","detail":"Unable to locate + Veteran''s ID/ICN in Master Person Index (MPI). Please submit an issue at + ask.va.gov or call 1-800-MyVA411 (800-698-2411) for assistance."}]}' + recorded_at: Thu, 01 Jun 2023 18:20:52 GMT +recorded_with: VCR 6.1.0