diff --git a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb index 2625edcdf93..91e9e84b347 100644 --- a/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb +++ b/modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb @@ -11,18 +11,18 @@ def show # serialization layer. render json: { account: { - account_uuid: @current_user.user_account_uuid + accountUuid: @current_user.user_account_uuid }, profile: { - first_name: @current_user.first_name, - last_name: @current_user.last_name, + firstName: @current_user.first_name, + lastName: @current_user.last_name, verified: @current_user.user_account.verified?, - sign_in: { - service_name: @current_user.sign_in[:service_name] + signIn: { + serviceName: @current_user.sign_in[:service_name] } }, - prefills_available: [], - in_progress_forms: + prefillsAvailable: [], + inProgressForms: in_progress_forms } end diff --git a/modules/accredited_representative_portal/config/initializers/bypass_olive_branch.rb b/modules/accredited_representative_portal/config/initializers/bypass_olive_branch.rb new file mode 100644 index 00000000000..67e859e78d0 --- /dev/null +++ b/modules/accredited_representative_portal/config/initializers/bypass_olive_branch.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module AccreditedRepresentativePortal + ## + # `olive_branch` transforms (a) request and (b) response payloads. + # + # (a) It deeply transforms request and query param keys. + # At times it is convenient for params to act as snake-cased setters at a Ruby + # interface, but not always. Form resources are a possible example where not. + # + # For now, let's wait to encounter the cases where we really want this + # convenience. If we do encounter some, we may discover that we want a more + # explicit and collocated way to opt in. + # + # (b) It reloads the response from JSON, deeply transforms keys, and dumps + # back to JSON. + # This is superfluous because our serialization layer `jsonapi-serializer` + # already has a configuration option for key casing. This realizes our desired + # casing the one and only time it is visiting an object during serialization. + # + module BypassOliveBranch + def call(env) + exclude_arp_route?(env) ? @app.call(env) : super + end + + private + + ARP_PATH_INFO_PREFIX = '/accredited_representative_portal' + + def exclude_arp_route?(env) + env['PATH_INFO'].to_s.start_with?(ARP_PATH_INFO_PREFIX) + end + end +end + +module OliveBranch + class Middleware + prepend AccreditedRepresentativePortal::BypassOliveBranch + end +end diff --git a/modules/accredited_representative_portal/spec/factories/representative_user.rb b/modules/accredited_representative_portal/spec/factories/representative_user.rb index d948597b038..eef4eeb1d5e 100644 --- a/modules/accredited_representative_portal/spec/factories/representative_user.rb +++ b/modules/accredited_representative_portal/spec/factories/representative_user.rb @@ -39,7 +39,11 @@ { form_id: evaluator.in_progress_form_id, user_account: user.user_account, - user_uuid: user.uuid + user_uuid: user.uuid, + metadata: { + version: 1, + returnUrl: 'foo.com' + } } ) end diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/bypass_olive_branch_spec.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/bypass_olive_branch_spec.rb new file mode 100644 index 00000000000..edaddc15cfe --- /dev/null +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/bypass_olive_branch_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'rails_helper' + +class BypassOliveBranchTestController < ActionController::API + def arp = render json: {} + def normal = render json: {} +end + +RSpec.describe AccreditedRepresentativePortal::BypassOliveBranch, type: :request do + subject do + get "#{path_prefix}/bypass_olive_branch_test", headers: { + 'X-Key-Inflection' => 'camel', + 'Content-Type' => 'application/json' + } + end + + before(:all) do + Rails.application.routes.draw do + get '/accredited_representative_portal/bypass_olive_branch_test', to: 'bypass_olive_branch_test#arp' + get '/bypass_olive_branch_test', to: 'bypass_olive_branch_test#normal' + end + end + + after(:all) do + Rails.application.reload_routes! + end + + context 'when the request is for an accredited representative portal route' do + let(:path_prefix) { '/accredited_representative_portal' } + + it 'bypasses OliveBranch processing' do + expect(OliveBranch::Transformations).not_to receive(:underscore_params) + expect(OliveBranch::Transformations).not_to receive(:transform) + subject + end + end + + context 'when the request is for a normal route' do + let(:path_prefix) { '' } + + it 'applies OliveBranch processing' do + expect(OliveBranch::Transformations).to receive(:underscore_params) + expect(OliveBranch::Transformations).to receive(:transform) + subject + end + end +end diff --git a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb index 1afe74794f0..2b966b3dc59 100644 --- a/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb +++ b/modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb @@ -46,30 +46,23 @@ expect(parsed_response).to eq( { 'account' => { - 'account_uuid' => user.user_account.id + 'accountUuid' => user.user_account.id }, 'profile' => { - 'first_name' => first_name, - 'last_name' => last_name, + 'firstName' => first_name, + 'lastName' => last_name, 'verified' => true, - 'sign_in' => { - 'service_name' => sign_in_service_name + 'signIn' => { + 'serviceName' => sign_in_service_name } }, - 'prefills_available' => [], - 'in_progress_forms' => [ + 'prefillsAvailable' => [], + 'inProgressForms' => [ { 'form' => in_progress_form_id, 'metadata' => { 'version' => 1, - 'return_url' => 'foo.com', - 'submission' => { - 'status' => false, - 'error_message' => false, - 'id' => false, - 'timestamp' => false, - 'has_attempted_submit' => false - }, + 'returnUrl' => 'foo.com', 'createdAt' => Time.current.to_i, 'expiresAt' => 60.days.from_now.to_i, 'lastUpdated' => Time.current.to_i,