Skip to content

Commit

Permalink
Prevent Prodtest from contacting VA Notify Staging (#22629)
Browse files Browse the repository at this point in the history
* APPEALS-54918 Update VA Notify fake service and initializer

* APPEALS-54918 Add CASEFLOW_BASE_URL env var in demo/dev

* APPEALS-54918 Add seed file for API Key and added to main seed execution

* APPEALS-54918 Add missing argument to method definition

* APPEALS-54918 Update "to" params and fix linting issues

* APPEALS-54918 Prevent post requests in test env
  • Loading branch information
msteele96 authored Aug 28, 2024
1 parent af8c273 commit 009007e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/environments/demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
# eFolder Express URL for demo environment used as a mock link
ENV["EFOLDER_EXPRESS_URL"] ||= "http://localhost:4000"

ENV["CASEFLOW_BASE_URL"] ||= "https://www.demo.appeals.va.gov"

# BatchProcess ENVs
# priority_ep_sync
ENV["BATCH_PROCESS_JOB_DURATION"] ||= "1" # Number of hours the job will run for
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
# Time in seconds before the sync lock expires
LOCK_TIMEOUT = ENV["SYNC_LOCK_MAX_DURATION"] ||= "60"

ENV["CASEFLOW_BASE_URL"] ||= "http://localhost:3000"

# Notifications page eFolder link
ENV["CLAIM_EVIDENCE_EFOLDER_BASE_URL"] ||= "https://vefs-claimevidence-ui-uat.stage.bip.va.gov"

Expand Down
7 changes: 6 additions & 1 deletion config/initializers/va_notify.rb
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
VANotifyService = (ApplicationController.dependencies_faked? ? Fakes::VANotifyService : ExternalApi::VANotifyService)
case Rails.deploy_env
when :uat, :prod
VANotifyService = ExternalApi::VANotifyService
else
VANotifyService = Fakes::VANotifyService
end
1 change: 1 addition & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def seed
call_and_log_seed_step Seeds::BgsServiceRecordMaker
call_and_log_seed_step Seeds::PopulateCaseflowFromVacols
call_and_log_seed_step Seeds::IssueModificationRequest
call_and_log_seed_step Seeds::ApiKey
end
end

Expand Down
17 changes: 17 additions & 0 deletions db/seeds/va_notify_api_key.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# create annotation seeds

module Seeds
class ApiKey
def seed!
create_api_key
end

private

def create_api_key
ApiKey.create!(consumer_name: "TestApiKey", key_string: "test")
end
end
end
36 changes: 32 additions & 4 deletions lib/fakes/va_notify_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class Fakes::VANotifyService < ExternalApi::VANotifyService
VA_NOTIFY_ENDPOINT = "/api/v1/va_notify_update"

class << self
# rubocop:disable Metrics/ParameterLists
def send_email_notifications(
Expand All @@ -11,7 +13,20 @@ def send_email_notifications(
docket_number:,
status: ""
)
fake_notification_response(email_template_id, status)

external_id = SecureRandom.uuid

unless Rails.deploy_env == :test
request = HTTPI::Request.new
request.url = "#{ENV['CASEFLOW_BASE_URL']}#{VA_NOTIFY_ENDPOINT}"\
"?id=#{external_id}&status=delivered&to=test@example.com&notification_type=email"
request.headers["Content-Type"] = "application/json"
request.headers["Authorization"] = "Bearer test"

HTTPI.post(request)
end

fake_notification_response(email_template_id, status, external_id)
end

def send_sms_notifications(
Expand All @@ -22,11 +37,24 @@ def send_sms_notifications(
docket_number:,
status: ""
)

external_id = SecureRandom.uuid

unless Rails.deploy_env == :test
request = HTTPI::Request.new
request.url = "#{ENV['CASEFLOW_BASE_URL']}#{VA_NOTIFY_ENDPOINT}"\
"?id=#{external_id}&status=delivered&to=+15555555555&notification_type=sms"
request.headers["Content-Type"] = "application/json"
request.headers["Authorization"] = "Bearer test"

HTTPI.post(request)
end

if participant_id.length.nil?
return bad_participant_id_response
end

fake_notification_response(sms_template_id, status)
fake_notification_response(sms_template_id, status, external_id)
end
# rubocop:enable Metrics/ParameterLists

Expand Down Expand Up @@ -102,12 +130,12 @@ def bad_notification_response
)
end

def fake_notification_response(template_id, status)
def fake_notification_response(template_id, status, external_id)
HTTPI::Response.new(
200,
{},
OpenStruct.new(
"id": SecureRandom.uuid,
"id": external_id,
"reference": "string",
"uri": "string",
"template": {
Expand Down

0 comments on commit 009007e

Please sign in to comment.