Skip to content

Commit

Permalink
Konstantin/appeals 48306 (#21998)
Browse files Browse the repository at this point in the history
* ama_eventing_enabled feature check added

* toggle renamed

* rspec tests added

* 2 comments added

* toggle renamed, logic trasferred into controller, tests updated

* empty line removed

---------

Co-authored-by: Matt Ray <108031363+mattray-gov@users.noreply.github.com>
  • Loading branch information
KonstantinShevtsov and mattray-gov authored Jul 1, 2024
1 parent 2099b27 commit 66cf311
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# frozen_string_literal: true

class Api::Events::V1::DecisionReviewCreatedController < Api::ApplicationController
# Checks if API is disabled
before_action do
if FeatureToggle.enabled?(:disable_ama_eventing)
render json: {
errors: [
{
status: "501",
title: "API is disabled",
detail: "This endpoint is not supported."
}
]
},
status: :not_implemented
end
end

# rubocop:disable Layout/LineLength
def decision_review_created
consumer_event_id = drc_params[:event_id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,62 @@
end
end
end
end

def json_payload
JSON.parse(File.read(Rails.root.join("app",
"services",
"events",
"decision_review_created",
"decision_review_created_example.json")))
end
describe "POST #decision_review_created_api disabled" do
let(:api_key) { ApiKey.create!(consumer_name: "Appeals-Consumer") }
let!(:payload) { Events::DecisionReviewCreated::DecisionReviewCreatedParser.example_response }
let!(:appeals_consumer_paylod) { { "event_id": 3333, "errored_claim_id": 1345, "error": "this was an error" } }
context "#contestable_issues with future ratings" do
before { FeatureToggle.enable!(:disable_ama_eventing) }
after { FeatureToggle.disable!(:disable_ama_eventing) }

it "returns success response" do
request.headers["Authorization"] = "Token token=#{api_key.key_string}"
load_headers
post :decision_review_created, params: JSON.parse(payload)
expect(response).to have_http_status(:not_implemented)
expect(response.body).to eq(
'{"errors":[{"status":"501","title":"API is disabled","detail":"This endpoint is not supported."}]}'
)
end

it "raises not_implemented status instead of process request with Redis error" do
allow(Events::DecisionReviewCreatedError).to receive(:handle_service_error)
.and_raise(Caseflow::Error::RedisLockFailed.new("Lock Failure"))
request.headers["Authorization"] = "Token #{api_key.key_string}"
post :decision_review_created_error, params: appeals_consumer_paylod
expect(response).to have_http_status(:not_implemented)
expect(response.body).to eq(
'{"errors":[{"status":"501","title":"API is disabled","detail":"This endpoint is not supported."}]}'
)
end

it "raises not_implemented status instead of process request with standart error" do
allow(Events::DecisionReviewCreatedError).to receive(:handle_service_error)
.and_raise(StandardError.new("Standard Failure"))
request.headers["Authorization"] = "Token #{api_key.key_string}"
post :decision_review_created_error, params: appeals_consumer_paylod
expect(response).to have_http_status(:not_implemented)
expect(response.body).to eq(
'{"errors":[{"status":"501","title":"API is disabled","detail":"This endpoint is not supported."}]}'
)
end
end
end

def load_headers
request.headers["X-VA-Vet-SSN"] = "123456789"
request.headers["X-VA-File-Number"] = "77799777"
request.headers["X-VA-Vet-First-Name"] = "John"
request.headers["X-VA-Vet-Last-Name"] = "Smith"
request.headers["X-VA-Vet-Middle-Name"] = "Alexander"
def json_payload
JSON.parse(File.read(Rails.root.join("app",
"services",
"events",
"decision_review_created",
"decision_review_created_example.json")))
end

def load_headers
request.headers["X-VA-Vet-SSN"] = "123456789"
request.headers["X-VA-File-Number"] = "77799777"
request.headers["X-VA-Vet-First-Name"] = "John"
request.headers["X-VA-Vet-Last-Name"] = "Smith"
request.headers["X-VA-Vet-Middle-Name"] = "Alexander"
end
end

0 comments on commit 66cf311

Please sign in to comment.