-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding default mailer endpoint
- Loading branch information
1 parent
877968f
commit 6da7a8d
Showing
14 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
GCS_CREDENTIALS_FILE= | ||
GCS_BUCKET= | ||
MQ_BETA_ENABLED=true | ||
|
||
# SMTP API | ||
SMTP_API_KEY= | ||
SMTP_API_SECRET= | ||
SMTP_DEFAULT_FROM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: '[email protected]' | ||
default from: ENV['SMTP_DEFAULT_FROM'] | ||
layout 'mailer' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class DataDownloadMailer < ApplicationMailer | ||
def send_download_file_info_email(data) | ||
@data = data | ||
mail(to: '[email protected]', subject: 'TPI data has been downloaded') | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
app/views/data_download_mailer/send_download_file_info_email.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<h1>Following user downloaded data from TPI website</h1> | ||
|
||
<p><strong>Email:</strong> <%= @data[:email] %></p> | ||
<p><strong>Job Title:</strong> <%= @data[:job_title] %></p> | ||
<p><strong>Forename:</strong> <%= @data[:forename] %></p> | ||
<p><strong>Surname:</strong> <%= @data[:surname] %></p> | ||
<p><strong>Location:</strong> <%= @data[:location] %></p> | ||
<p><strong>Organisation:</strong> <%= @data[:organisation] %></p> | ||
|
||
<h2>Purposes</h2> | ||
<ul> | ||
<% Array.wrap(@data[:purposes]).each do |purpose| %> | ||
<li><%= purpose %></li> | ||
<% end %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# kindly generated by appropriated Rails generator | ||
Mailjet.configure do |config| | ||
config.api_key = ENV['SMTP_API_KEY'] | ||
config.secret_key = ENV['SMTP_API_SECRET'] | ||
config.default_from = ENV['SMTP_DEFAULT_FROM'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,4 +254,28 @@ | |
end | ||
end | ||
end | ||
|
||
describe 'POST send_download_file_info_email' do | ||
subject { post :send_download_file_info_email, params: data } | ||
let(:data) do | ||
{ | ||
email: '[email protected]', | ||
job_title: 'job_title', | ||
forename: 'forename', | ||
surname: 'surname', | ||
location: 'location', | ||
organisation: 'organisation', | ||
purposes: %w[purposes1 purposes2] | ||
} | ||
end | ||
|
||
it 'returns ok status' do | ||
subject | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'sends email' do | ||
expect { subject }.to change { ActionMailer::Base.deliveries.count }.by(1) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe DataDownloadMailer, type: :mailer do | ||
describe 'send_download_file_info_email' do | ||
let(:data) { | ||
{ | ||
email: '[email protected]', | ||
job_title: 'job_title', | ||
forename: 'forename', | ||
surname: 'surname', | ||
location: 'location', | ||
organisation: 'organisation', | ||
purposes: ['purpose1', 'purpose2'] | ||
} | ||
} | ||
let(:mail) { DataDownloadMailer.send_download_file_info_email data } | ||
|
||
it 'renders the headers' do | ||
expect(mail.subject).to eq('TPI data has been downloaded') | ||
expect(mail.to).to eq(['[email protected]']) | ||
expect(mail.from).to eq([ENV['SMTP_DEFAULT_FROM']].reject(&:blank?)) | ||
|
||
expect(mail.body.encoded).to include('[email protected]') | ||
expect(mail.body.encoded).to include('job_title') | ||
expect(mail.body.encoded).to include('forename') | ||
expect(mail.body.encoded).to include('surname') | ||
expect(mail.body.encoded).to include('location') | ||
expect(mail.body.encoded).to include('organisation') | ||
expect(mail.body.encoded).to include('purpose1') | ||
expect(mail.body.encoded).to include('purpose2') | ||
end | ||
end | ||
end |