don't raise validation error if the message is empty
This commit is contained in:
committed by
Pete Matsyburka
parent
15d06f4fb0
commit
bb552d13d4
@@ -89,12 +89,13 @@ module Params
|
|||||||
raise_error(message || "#{key} must be unique")
|
raise_error(message || "#{key} must be unique")
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_path(params, path = [])
|
def in_path(params, path = [], skip_blank: false)
|
||||||
old_path = @current_path
|
old_path = @current_path
|
||||||
|
|
||||||
@current_path = [old_path, *path].compact_blank.map(&:to_s).join('.')
|
@current_path = [old_path, *path].compact_blank.map(&:to_s).join('.')
|
||||||
|
|
||||||
param = params.dig(*path)
|
param = params.dig(*path)
|
||||||
|
param = nil if skip_blank && param.blank?
|
||||||
|
|
||||||
yield params.dig(*path) if param
|
yield params.dig(*path) if param
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ module Params
|
|||||||
type(params, :message, Hash)
|
type(params, :message, Hash)
|
||||||
type(params, :submitters, Array)
|
type(params, :submitters, Array)
|
||||||
|
|
||||||
in_path(params, :message) do |message_params|
|
in_path(params, :message, skip_blank: true) do |message_params|
|
||||||
type(message_params, :subject, String)
|
type(message_params, :subject, String)
|
||||||
type(message_params, :body, String)
|
type(message_params, :body, String)
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,21 @@ describe 'Submission API', type: :request do
|
|||||||
expect(response.parsed_body).to eq(JSON.parse(create_submission_body(submission).to_json))
|
expect(response.parsed_body).to eq(JSON.parse(create_submission_body(submission).to_json))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates a submission when the message is empty' do
|
||||||
|
post '/api/submissions', headers: { 'x-auth-token': author.access_token.token }, params: {
|
||||||
|
template_id: templates[0].id,
|
||||||
|
send_email: true,
|
||||||
|
submitters: [{ role: 'First Party', email: 'john.doe@example.com' }],
|
||||||
|
message: {}
|
||||||
|
}.to_json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:ok)
|
||||||
|
|
||||||
|
submission = Submission.last
|
||||||
|
|
||||||
|
expect(response.parsed_body).to eq(JSON.parse(create_submission_body(submission).to_json))
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates a submission when some submitter roles are not provided' do
|
it 'creates a submission when some submitter roles are not provided' do
|
||||||
post '/api/submissions', headers: { 'x-auth-token': author.access_token.token }, params: {
|
post '/api/submissions', headers: { 'x-auth-token': author.access_token.token }, params: {
|
||||||
template_id: multiple_submitters_template.id,
|
template_id: multiple_submitters_template.id,
|
||||||
@@ -168,6 +183,22 @@ describe 'Submission API', type: :request do
|
|||||||
expect(response).to have_http_status(:unprocessable_entity)
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
expect(response.parsed_body).to eq({ 'error' => 'Defined more signing parties than in template' })
|
expect(response.parsed_body).to eq({ 'error' => 'Defined more signing parties than in template' })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns an error if the message has no body value' do
|
||||||
|
post '/api/submissions', headers: { 'x-auth-token': author.access_token.token }, params: {
|
||||||
|
template_id: templates[0].id,
|
||||||
|
send_email: true,
|
||||||
|
submitters: [
|
||||||
|
{ role: 'First Party', email: 'john.doe@example.com' }
|
||||||
|
],
|
||||||
|
message: {
|
||||||
|
subject: 'Custom Email Subject'
|
||||||
|
}
|
||||||
|
}.to_json
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
|
expect(response.parsed_body).to eq({ 'error' => 'body is required in `message`.' })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST /api/submissions/emails' do
|
describe 'POST /api/submissions/emails' do
|
||||||
|
|||||||
Reference in New Issue
Block a user