Skip to content

Commit f544157

Browse files
authored
[ARP - lower camel responses - 3] handle camel params in ARP IPF controller (#20623)
* [ARP] handle camel params in ARP IPF controller * [ARP - lower camel responses - 4] camel response in ARP users controller (#20624) * [ARP] camel response in ARP users controller * [ARP - lower camel responses - 5] bypass olive branch (#20625) * [ARP] bypass olive branch * lint fixes
1 parent e406275 commit f544157

File tree

7 files changed

+120
-38
lines changed

7 files changed

+120
-38
lines changed

modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/in_progress_forms_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class InProgressFormsController < ApplicationController
88
def update
99
form = find_form || build_form
1010
form.update!(
11-
form_data: params[:form_data],
11+
form_data: params[:formData],
1212
metadata: params[:metadata]
1313
)
1414

modules/accredited_representative_portal/app/controllers/accredited_representative_portal/v0/representative_users_controller.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ def show
1111
# serialization layer.
1212
render json: {
1313
account: {
14-
account_uuid: @current_user.user_account_uuid
14+
accountUuid: @current_user.user_account_uuid
1515
},
1616
profile: {
17-
first_name: @current_user.first_name,
18-
last_name: @current_user.last_name,
17+
firstName: @current_user.first_name,
18+
lastName: @current_user.last_name,
1919
verified: @current_user.user_account.verified?,
20-
sign_in: {
21-
service_name: @current_user.sign_in[:service_name]
20+
signIn: {
21+
serviceName: @current_user.sign_in[:service_name]
2222
}
2323
},
24-
prefills_available: [],
25-
in_progress_forms:
24+
prefillsAvailable: [],
25+
inProgressForms: in_progress_forms
2626
}
2727
end
2828

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
module AccreditedRepresentativePortal
4+
##
5+
# `olive_branch` transforms (a) request and (b) response payloads.
6+
#
7+
# (a) It deeply transforms request and query param keys.
8+
# At times it is convenient for params to act as snake-cased setters at a Ruby
9+
# interface, but not always. Form resources are a possible example where not.
10+
#
11+
# For now, let's wait to encounter the cases where we really want this
12+
# convenience. If we do encounter some, we may discover that we want a more
13+
# explicit and collocated way to opt in.
14+
#
15+
# (b) It reloads the response from JSON, deeply transforms keys, and dumps
16+
# back to JSON.
17+
# This is superfluous because our serialization layer `jsonapi-serializer`
18+
# already has a configuration option for key casing. This realizes our desired
19+
# casing the one and only time it is visiting an object during serialization.
20+
#
21+
module BypassOliveBranch
22+
def call(env)
23+
exclude_arp_route?(env) ? @app.call(env) : super
24+
end
25+
26+
private
27+
28+
ARP_PATH_INFO_PREFIX = '/accredited_representative_portal'
29+
30+
def exclude_arp_route?(env)
31+
env['PATH_INFO'].to_s.start_with?(ARP_PATH_INFO_PREFIX)
32+
end
33+
end
34+
end
35+
36+
module OliveBranch
37+
class Middleware
38+
prepend AccreditedRepresentativePortal::BypassOliveBranch
39+
end
40+
end

modules/accredited_representative_portal/spec/factories/representative_user.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
{
4040
form_id: evaluator.in_progress_form_id,
4141
user_account: user.user_account,
42-
user_uuid: user.uuid
42+
user_uuid: user.uuid,
43+
metadata: {
44+
version: 1,
45+
returnUrl: 'foo.com'
46+
}
4347
}
4448
)
4549
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
class BypassOliveBranchTestController < ActionController::API
6+
def arp = render json: {}
7+
def normal = render json: {}
8+
end
9+
10+
RSpec.describe AccreditedRepresentativePortal::BypassOliveBranch, type: :request do
11+
subject do
12+
get "#{path_prefix}/bypass_olive_branch_test", headers: {
13+
'X-Key-Inflection' => 'camel',
14+
'Content-Type' => 'application/json'
15+
}
16+
end
17+
18+
before(:all) do
19+
Rails.application.routes.draw do
20+
get '/accredited_representative_portal/bypass_olive_branch_test', to: 'bypass_olive_branch_test#arp'
21+
get '/bypass_olive_branch_test', to: 'bypass_olive_branch_test#normal'
22+
end
23+
end
24+
25+
after(:all) do
26+
Rails.application.reload_routes!
27+
end
28+
29+
context 'when the request is for an accredited representative portal route' do
30+
let(:path_prefix) { '/accredited_representative_portal' }
31+
32+
it 'bypasses OliveBranch processing' do
33+
expect(OliveBranch::Transformations).not_to receive(:underscore_params)
34+
expect(OliveBranch::Transformations).not_to receive(:transform)
35+
subject
36+
end
37+
end
38+
39+
context 'when the request is for a normal route' do
40+
let(:path_prefix) { '' }
41+
42+
it 'applies OliveBranch processing' do
43+
expect(OliveBranch::Transformations).to receive(:underscore_params)
44+
expect(OliveBranch::Transformations).to receive(:transform)
45+
subject
46+
end
47+
end
48+
end

modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/in_progress_forms_spec.rb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
:in_progress_form,
2323
user_uuid: representative_user.uuid,
2424
form_data: { field: 'value' },
25-
form_id:
25+
form_id:,
26+
metadata: {
27+
version: 1,
28+
returnUrl: 'foo.com'
29+
}
2630
)
2731

2832
get("/accredited_representative_portal/v0/in_progress_forms/#{form_id}")
@@ -33,14 +37,7 @@
3337
},
3438
'metadata' => {
3539
'version' => 1,
36-
'return_url' => 'foo.com',
37-
'submission' => {
38-
'status' => false,
39-
'error_message' => false,
40-
'id' => false,
41-
'timestamp' => false,
42-
'has_attempted_submit' => false
43-
},
40+
'returnUrl' => 'foo.com',
4441
'createdAt' => 1_646_370_367,
4542
'expiresAt' => 1_651_554_367,
4643
'lastUpdated' => 1_646_370_367,
@@ -57,7 +54,7 @@
5754

5855
put(
5956
"/accredited_representative_portal/v0/in_progress_forms/#{form_id}",
60-
params: { 'form_data' => { another_field: 'foo' } }.to_json,
57+
params: { 'formData' => { anotherField: 'foo' } }.to_json,
6158
headers:
6259
)
6360

@@ -85,7 +82,7 @@
8582
expect(parsed_response).to eq(
8683
{
8784
'formData' => {
88-
'another_field' => 'foo'
85+
'anotherField' => 'foo'
8986
},
9087
'metadata' => {
9188
'createdAt' => 1_646_456_767,
@@ -101,7 +98,7 @@
10198

10299
put(
103100
"/accredited_representative_portal/v0/in_progress_forms/#{form_id}",
104-
params: { 'form_data' => { another_field: 'foo', sample_field: 'sample' } }.to_json,
101+
params: { 'formData' => { anotherField: 'foo', sampleField: 'sample' } }.to_json,
105102
headers:
106103
)
107104

@@ -129,8 +126,8 @@
129126
expect(parsed_response).to eq(
130127
{
131128
'formData' => {
132-
'another_field' => 'foo',
133-
'sample_field' => 'sample'
129+
'anotherField' => 'foo',
130+
'sampleField' => 'sample'
134131
},
135132
'metadata' => {
136133
'createdAt' => 1_646_456_767,

modules/accredited_representative_portal/spec/requests/accredited_representative_portal/v0/user_spec.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,23 @@
4646
expect(parsed_response).to eq(
4747
{
4848
'account' => {
49-
'account_uuid' => user.user_account.id
49+
'accountUuid' => user.user_account.id
5050
},
5151
'profile' => {
52-
'first_name' => first_name,
53-
'last_name' => last_name,
52+
'firstName' => first_name,
53+
'lastName' => last_name,
5454
'verified' => true,
55-
'sign_in' => {
56-
'service_name' => sign_in_service_name
55+
'signIn' => {
56+
'serviceName' => sign_in_service_name
5757
}
5858
},
59-
'prefills_available' => [],
60-
'in_progress_forms' => [
59+
'prefillsAvailable' => [],
60+
'inProgressForms' => [
6161
{
6262
'form' => in_progress_form_id,
6363
'metadata' => {
6464
'version' => 1,
65-
'return_url' => 'foo.com',
66-
'submission' => {
67-
'status' => false,
68-
'error_message' => false,
69-
'id' => false,
70-
'timestamp' => false,
71-
'has_attempted_submit' => false
72-
},
65+
'returnUrl' => 'foo.com',
7366
'createdAt' => Time.current.to_i,
7467
'expiresAt' => 60.days.from_now.to_i,
7568
'lastUpdated' => Time.current.to_i,

0 commit comments

Comments
 (0)