Skip to content

Commit

Permalink
API-42025-update-v2-poa-schema-to-allow-empty-string-email (#19438)
Browse files Browse the repository at this point in the history
* Updates REGEX pattern in V2 2122.json and 2122a.json so that an empty string can also pass the validation
	modified:   modules/claims_api/config/schemas/v2/2122.json
	modified:   modules/claims_api/config/schemas/v2/2122a.json
	modified:   modules/claims_api/spec/requests/v2/veterans/power_of_attorney/2122_spec.rb
  • Loading branch information
rockwellwindsor-va authored Nov 18, 2024
1 parent d67b694 commit 87b432d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
6 changes: 3 additions & 3 deletions modules/claims_api/config/schemas/v2/2122.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"email": {
"description": "Email address of the veteran.",
"type": "string",
"pattern": ".@.",
"pattern": "^(?!.*\\s).+@.+\\..+|^$",
"maxLength": 61,
"example": "veteran@example.com"
},
Expand Down Expand Up @@ -194,7 +194,7 @@
"email": {
"description": "Email address of the claimant.",
"type": "string",
"pattern": ".@.",
"pattern": "^(?!.*\\s).+@.+\\..+|^$",
"maxLength": 61,
"example": "claimant@example.com"
},
Expand Down Expand Up @@ -232,7 +232,7 @@
"email": {
"description": "Email address of the service organization or representative.",
"type": "string",
"pattern": ".@.",
"pattern": "^(?!.*\\s).+@.+\\..+|^$",
"maxLength": 61,
"example": "veteran_representative@example.com"
}
Expand Down
4 changes: 2 additions & 2 deletions modules/claims_api/config/schemas/v2/2122a.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"email": {
"description": "Email address of the veteran.",
"type": "string",
"pattern": ".@.",
"pattern": "^(?!.*\\s).+@.+\\..+|^$",
"maxLength": 61,
"example": "veteran@example.com"
}
Expand Down Expand Up @@ -204,7 +204,7 @@
"email": {
"description": "Email address of the claimant.",
"type": "string",
"pattern": ".@.",
"pattern": "^(?!.*\\s).+@.+\\..+|^$",
"maxLength": 61,
"example": "claimant@example.com"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,74 @@
end
end
end

context 'when validating email values' do
context 'when the email is valid' do
it 'allows an empty string' do
data[:data][:attributes][:veteran][:email] = ''
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

post appoint_organization_path, params: data.to_json, headers: auth_header

expect(response).to have_http_status(:accepted)
end
end

it "allows a valid 'normal' looking email" do
data[:data][:attributes][:veteran][:email] = 'valid@email.com'
mock_ccg(scopes) do |auth_header|
expect_any_instance_of(local_bgs).to receive(:find_poa_by_participant_id)
.and_return(bgs_poa)
allow_any_instance_of(local_bgs).to receive(:find_poa_history_by_ptcpnt_id)
.and_return({ person_poa_history: nil })

post appoint_organization_path, params: data.to_json, headers: auth_header

expect(response).to have_http_status(:accepted)
end
end
end

context 'when the email is invalid' do
it 'denies an invalid value' do
data[:data][:attributes][:veteran][:email] = 'thisisnotavalidemailatall'
mock_ccg(scopes) do |auth_header|
post appoint_organization_path, params: data.to_json, headers: auth_header

json_response = JSON.parse(response.body)

expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['errors'][0]['detail']).to eq(
'The property /veteran/email did not match the following requirements: ' \
'{"description"=>"Email address of the veteran.", "type"=>"string", ' \
'"pattern"=>"^(?!.*\\\\s).+@.+\\\\..+|^$", "maxLength"=>61, "example"=>' \
'"veteran@example.com"}'
)
end
end

it 'denies an empty string' do
data[:data][:attributes][:veteran][:email] = ' '
mock_ccg(scopes) do |auth_header|
post appoint_organization_path, params: data.to_json, headers: auth_header

json_response = JSON.parse(response.body)

expect(response).to have_http_status(:unprocessable_entity)
expect(json_response['errors'][0]['detail']).to eq(
'The property /veteran/email did not match the following requirements: ' \
'{"description"=>"Email address of the veteran.", "type"=>"string", ' \
'"pattern"=>"^(?!.*\\\\s).+@.+\\\\..+|^$", "maxLength"=>61, "example"=>' \
'"veteran@example.com"}'
)
end
end
end
end
end
end

Expand Down

0 comments on commit 87b432d

Please sign in to comment.