Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Validate email addresses #14

Merged
merged 2 commits into from
Jan 4, 2024
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: 5 additions & 1 deletion app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ class ApiController < ApplicationController
def notify
return head 400 if params[:to]&.match(/psnator/)

@notification = Notification.from_params(params)
begin
@notification = Notification.from_params(params)
rescue => e
return render json: {error: e.message}, status: 400
end
render json: @notification
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/api/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
}
expect(response.code).to eq('400')
end
it 'handles invalid email addresses' do
post :notify, params:
{
to: 'not a valid email address',
subject: 'hello',
body: 'goodbye'
}
expect(response.code).to eq('400')
expect(response.body).to match('email(.*)invalid')
end
it 'supports multiple recipients' do
stub_request(:post, 'https://api.sendgrid.com/v3/mail/send')
.with(
Expand Down
Loading