Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API-42025-update-v2-poa-schema-to-allow-empty-string-email #19438

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading