diff --git a/.env.sample b/.env.sample
index 9df289ce7..75211a527 100644
--- a/.env.sample
+++ b/.env.sample
@@ -1,3 +1,8 @@
GCS_CREDENTIALS_FILE=
GCS_BUCKET=
MQ_BETA_ENABLED=true
+
+# SMTP API
+SMTP_API_KEY=
+SMTP_API_SECRET=
+SMTP_DEFAULT_FROM=
diff --git a/Gemfile b/Gemfile
index 9c0436d25..22c6bc915 100644
--- a/Gemfile
+++ b/Gemfile
@@ -44,6 +44,7 @@ gem 'react-rails'
gem 'appsignal'
gem 'roo'
gem 'caxlsx'
+gem 'mailjet'
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
diff --git a/Gemfile.lock b/Gemfile.lock
index bd1c07330..397d68a14 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -291,6 +291,11 @@ GEM
net-imap
net-pop
net-smtp
+ mailjet (1.8.0)
+ activesupport (>= 5.0.0)
+ faraday (~> 2.1)
+ rack (>= 1.4.0)
+ yajl-ruby
marcel (1.0.4)
matrix (0.4.2)
memoist (0.16.2)
@@ -547,6 +552,7 @@ GEM
rails (>= 3.2.16)
xpath (3.2.0)
nokogiri (~> 1.8)
+ yajl-ruby (1.4.3)
zeitwerk (2.6.18)
PLATFORMS
@@ -589,6 +595,7 @@ DEPENDENCIES
image_processing
language_list
listen (>= 3.0.5, < 3.2)
+ mailjet
pg (>= 0.18, < 2.0)
pg_search (= 2.3.2)
pry
diff --git a/app/assets/stylesheets/tpi/_mq_beta_scores.scss b/app/assets/stylesheets/tpi/_mq_beta_scores.scss
index d7078a942..b550309c9 100644
--- a/app/assets/stylesheets/tpi/_mq_beta_scores.scss
+++ b/app/assets/stylesheets/tpi/_mq_beta_scores.scss
@@ -64,6 +64,9 @@
&__download-button {
flex-grow: 4;
text-align: right;
+ display: flex;
+ gap: 5px;
+ justify-content: end;
.button {
background-color: $blue;
@@ -73,4 +76,4 @@
margin-bottom: 10px;
}
}
-}
\ No newline at end of file
+}
diff --git a/app/assets/stylesheets/tpi/pages/company.scss b/app/assets/stylesheets/tpi/pages/company.scss
index b985cf308..b5615106f 100644
--- a/app/assets/stylesheets/tpi/pages/company.scss
+++ b/app/assets/stylesheets/tpi/pages/company.scss
@@ -243,10 +243,6 @@
border-left: 2px solid $hawkes-blue;
- &.level5 {
- background-color: rgba($tpi-level5-background-color, 0.15);
- }
-
&__header {
font-size: 16px;
font-weight: bold;
diff --git a/app/controllers/concerns/tpi/user_download.rb b/app/controllers/concerns/tpi/user_download.rb
index 72bfb1089..61cd878de 100644
--- a/app/controllers/concerns/tpi/user_download.rb
+++ b/app/controllers/concerns/tpi/user_download.rb
@@ -12,10 +12,8 @@ def send_tpi_user_file(mq_assessments:, cp_assessments:, filename:)
.includes(sector: [:cp_units])
mq_assessments_files = mq_assessments_by_methodology.map do |methodology, assessments|
- is_beta_methodology = MQ::Assessment::BETA_METHODOLOGIES.include? methodology
- name = is_beta_methodology ? "#{methodology}_BETA_#{timestamp}" : "#{methodology}_#{timestamp}"
{
- "MQ_Assessments_Methodology_#{name}.csv" => CSVExport::User::MQAssessments.new(assessments).call
+ "MQ_Assessments_Methodology_#{methodology}_#{timestamp}.csv" => CSVExport::User::MQAssessments.new(assessments).call
}
end.reduce(&:merge)
@@ -28,17 +26,15 @@ def send_tpi_user_file(mq_assessments:, cp_assessments:, filename:)
cp_assessments_csv = CSVExport::User::CompanyCPAssessments.new(cp_assessments).call
cp_assessments_regional_csv = CSVExport::User::CompanyCPAssessmentsRegional.new(cp_assessments).call
sector_benchmarks_csv = CSVExport::User::CPBenchmarks.new(cp_benchmarks).call
- user_guide = File.binread(Rails.root.join('public', 'tpi', 'export_support', 'User guide TPI files.xlsx'))
files = (mq_assessments_files || {}).merge(
'Company_Latest_Assessments.csv' => latest_cp_assessments_csv,
"CP_Assessments_#{timestamp}.csv" => cp_assessments_csv,
"CP_Assessments_Regional_#{timestamp}.csv" => cp_assessments_regional_csv,
- "Sector_Benchmarks_#{timestamp}.csv" => sector_benchmarks_csv,
- 'User guide TPI files.xlsx' => user_guide
+ "Sector_Benchmarks_#{timestamp}.csv" => sector_benchmarks_csv
)
if ENV['MQ_BETA_ENABLED'].to_s == 'true'
- files = files.merge 'Company_Latest_Assessments_BETA_5.0.csv' => latest_cp_assessments_beta_csv
+ files = files.merge 'Company_Latest_Assessments_5.0.csv' => latest_cp_assessments_beta_csv
end
render zip: files.compact, filename: "#{filename} - #{timestamp}"
end
diff --git a/app/controllers/tpi/companies_controller.rb b/app/controllers/tpi/companies_controller.rb
index d2724d22b..0d6b53856 100644
--- a/app/controllers/tpi/companies_controller.rb
+++ b/app/controllers/tpi/companies_controller.rb
@@ -2,6 +2,7 @@ module TPI
class CompaniesController < TPIController
include UserDownload
+ before_action :enable_beta_mq_assessments
before_action :fetch_company
before_action :redirect_if_numeric_or_historic_slug, only: [:show]
before_action :fetch_cp_assessment, only: [:show, :cp_assessment, :emissions_chart_data]
diff --git a/app/controllers/tpi/sectors_controller.rb b/app/controllers/tpi/sectors_controller.rb
index 2e6cd22c5..086105b29 100644
--- a/app/controllers/tpi/sectors_controller.rb
+++ b/app/controllers/tpi/sectors_controller.rb
@@ -2,6 +2,7 @@ module TPI
class SectorsController < TPIController
include UserDownload
+ before_action :enable_beta_mq_assessments
before_action :fetch_companies, only: [:show, :index]
before_action :fetch_sectors, only: [:show, :index, :user_download_all]
before_action :fetch_sector, only: [:show, :user_download]
@@ -77,6 +78,11 @@ def cp_performance_chart_data
render json: data.chart_json
end
+ def send_download_file_info_email
+ DataDownloadMailer.send_download_file_info_email(permitted_email_params).deliver_now
+ head :ok
+ end
+
def user_download_all
send_user_download_file(
Company.published.select(:id).where(sector_id: @sectors.pluck(:id)),
@@ -91,6 +97,13 @@ def user_download
)
end
+ def user_download_methodology
+ user_guide = File.binread(Rails.root.join('public', 'tpi', 'export_support', 'User guide TPI files.xlsx'))
+ render zip: {
+ 'User guide TPI files.xlsx' => user_guide
+ }, filename: "TPI Methodology - #{Time.now.strftime('%d%m%Y')}"
+ end
+
private
def any_cp_assessment?
@@ -155,5 +168,9 @@ def companies_scope(params)
Company.published.active
end
end
+
+ def permitted_email_params
+ params.permit(:email, :job_title, :forename, :surname, :location, :organisation, purposes: [])
+ end
end
end
diff --git a/app/controllers/tpi/tpi_controller.rb b/app/controllers/tpi/tpi_controller.rb
index c0893c6ec..d4add55b1 100644
--- a/app/controllers/tpi/tpi_controller.rb
+++ b/app/controllers/tpi/tpi_controller.rb
@@ -6,6 +6,10 @@ class TPIController < ApplicationController
protected
+ def enable_beta_mq_assessments
+ session[:enable_beta_mq_assessments] = true unless session.key?(:enable_beta_mq_assessments)
+ end
+
def fixed_navbar(admin_panel_section_title, admin_panel_link)
@admin_panel_section_title = admin_panel_section_title
@link = admin_panel_link
diff --git a/app/javascript/components/tpi/charts/mq-level/options.js b/app/javascript/components/tpi/charts/mq-level/options.js
index a76a505dd..ea28b5fb6 100644
--- a/app/javascript/components/tpi/charts/mq-level/options.js
+++ b/app/javascript/components/tpi/charts/mq-level/options.js
@@ -58,10 +58,7 @@ export function getOptions({ chartData }) {
fontSize: '12px'
},
useHTML: true,
- stagger: 0,
- formatter() {
- return this.value === 5 ? '5 [BETA]' : this.value;
- }
+ stagger: 0
},
title: {
text: 'Level',
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index 286b2239d..4ca5b1428 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
- default from: 'from@example.com'
+ default from: ENV.fetch('SMTP_DEFAULT_FROM', 'from@example.com')
layout 'mailer'
end
diff --git a/app/mailers/data_download_mailer.rb b/app/mailers/data_download_mailer.rb
new file mode 100644
index 000000000..ce03a868f
--- /dev/null
+++ b/app/mailers/data_download_mailer.rb
@@ -0,0 +1,6 @@
+class DataDownloadMailer < ApplicationMailer
+ def send_download_file_info_email(data)
+ @data = data
+ mail(to: 'tpi@lse.ac.uk', subject: 'TPI data has been downloaded')
+ end
+end
diff --git a/app/models/mq/assessment.rb b/app/models/mq/assessment.rb
index 2e3b46082..291ddd2aa 100644
--- a/app/models/mq/assessment.rb
+++ b/app/models/mq/assessment.rb
@@ -22,7 +22,7 @@ class Assessment < ApplicationRecord
LEVELS = %w[0 1 2 3 4 4STAR 5 5STAR].freeze
BETA_METHODOLOGIES = { # taken into account only when beta is enabled
- 5 => {levels: %w[5], highlight_questions: %w[18]}
+ 5 => {levels: %w[5], highlight_questions: %w[]}
}.freeze
BETA_LEVELS = BETA_METHODOLOGIES.map { |_k, v| v[:levels] }.flatten.freeze
diff --git a/app/views/data_download_mailer/send_download_file_info_email.html.erb b/app/views/data_download_mailer/send_download_file_info_email.html.erb
new file mode 100644
index 000000000..3fd2a9a18
--- /dev/null
+++ b/app/views/data_download_mailer/send_download_file_info_email.html.erb
@@ -0,0 +1,15 @@
+
Following user downloaded data from TPI website
+
+Email: <%= @data[:email] %>
+Job Title: <%= @data[:job_title] %>
+Forename: <%= @data[:forename] %>
+Surname: <%= @data[:surname] %>
+Location: <%= @data[:location] %>
+Organisation: <%= @data[:organisation] %>
+
+Purposes
+
+ <% Array.wrap(@data[:purposes]).each do |purpose| %>
+ - <%= purpose %>
+ <% end %>
+
diff --git a/app/views/tpi/companies/_mq_assessment.html.erb b/app/views/tpi/companies/_mq_assessment.html.erb
index 11ef814f4..b0855b95a 100644
--- a/app/views/tpi/companies/_mq_assessment.html.erb
+++ b/app/views/tpi/companies/_mq_assessment.html.erb
@@ -31,7 +31,7 @@
<% assessment.questions_by_level.each do |level, questions| %>
diff --git a/app/views/tpi/companies/show.html.erb b/app/views/tpi/companies/show.html.erb
index 88b4e7a9b..af7c13109 100644
--- a/app/views/tpi/companies/show.html.erb
+++ b/app/views/tpi/companies/show.html.erb
@@ -1,11 +1,6 @@
<% content_for :page_title, "#{@company.name} - Transition Pathway Initiative" %>
<% content_for :page_description, "Assess how prepared #{@company.name} is for the transition to a low-carbon economy – its Management Quality and Carbon Performance." %>
-<%= react_component('MqBetaModal', {
- enabled: session[:enable_beta_mq_assessments],
- page: "companies"
-}) %>
-
<% regional_view = @company.cp_alignment_region.present? && params[:view] == 'regional' %>
@@ -16,22 +11,14 @@
<%= render 'tpi/shared/mq_beta_scores', has_data: @company.beta_mq_assessments? %>
-
@@ -39,16 +26,6 @@
<%= render 'tpi/shared/mq_beta_scores', has_data: @company.beta_mq_assessments? %>
-
@@ -242,6 +219,7 @@
<% end %>
+
<% if @company.latest_information.present? %>
<%= react_component("LatestInformation", { name: @company.name, latestInformation: @company.latest_information }) %>
<% end %>
diff --git a/app/views/tpi/sectors/index.html.erb b/app/views/tpi/sectors/index.html.erb
index 1fb91630f..0d07715c9 100644
--- a/app/views/tpi/sectors/index.html.erb
+++ b/app/views/tpi/sectors/index.html.erb
@@ -1,11 +1,6 @@
<% content_for :page_title, "Tool - Transition Pathway Initiative" %>
<% content_for :page_description, "The TPI tool is a corporate climate action benchmark which assesses how prepared companies are for the transition to a low-carbon economy." %>
-<%= react_component('MqBetaModal', {
- enabled: session[:enable_beta_mq_assessments],
- page: "company"
-}) %>
-
<%= react_component("DropdownSelector", {
@@ -19,30 +14,14 @@
<%= render 'tpi/shared/mq_beta_scores', has_data: true %>
-
@@ -80,36 +59,4 @@
sectors: TPI::CPPerformanceSectorDecorator.decorate_collection(@sectors).map(&:to_h)
}) %>
-
- <% if @methodology_publication.present? %>
-
-
-
-
Methodology
-
-
- <%= @methodology_description&.text&.html_safe %>
-
-
-
- <%= render 'tpi/publications/list', publications_and_articles: [@methodology_publication] %>
-
-
-
- <% end %>
-
-
-
-
diff --git a/app/views/tpi/sectors/show.html.erb b/app/views/tpi/sectors/show.html.erb
index 89ea493e3..88e2140e7 100644
--- a/app/views/tpi/sectors/show.html.erb
+++ b/app/views/tpi/sectors/show.html.erb
@@ -1,11 +1,6 @@
<% content_for :page_title, "#{@sector.name} - Transition Pathway Initiative" %>
<% content_for :page_description, "Description: Compare and assess how prepared the world’s top companies in the #{@sector.name} sector are for the transition to a low-carbon economy." %>
-<%= react_component('MqBetaModal', {
- enabled: session[:enable_beta_mq_assessments],
- page: "sector"
-}) %>
-
<%= react_component("DropdownSelector", {
@@ -19,22 +14,14 @@
<%= render 'tpi/shared/mq_beta_scores', has_data: true %>
-
@@ -90,23 +77,4 @@
}) %>
<% end %>
-
- <% if @publications_and_articles.present? %>
-
-
-
- <% end %>
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 444e6b0a1..fff936694 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -33,10 +33,8 @@
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
- # Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
-
- config.action_mailer.perform_caching = false
+ config.action_mailer.perform_deliveries = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 99067f050..db8701407 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -62,11 +62,9 @@
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "laws_and_pathways_production"
- config.action_mailer.perform_caching = false
-
- # Ignore bad email addresses and do not raise email delivery errors.
- # Set this to true and configure the email server for immediate delivery to raise delivery errors.
- # config.action_mailer.raise_delivery_errors = false
+ config.action_mailer.raise_delivery_errors = true
+ config.action_mailer.delivery_method = :mailjet
+ config.action_mailer.perform_deliveries = true
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
diff --git a/config/environments/staging.rb b/config/environments/staging.rb
index 3a1b12b98..273b0b6f7 100644
--- a/config/environments/staging.rb
+++ b/config/environments/staging.rb
@@ -65,11 +65,9 @@
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "laws_and_pathways_#{Rails.env}"
- config.action_mailer.perform_caching = false
-
- # Ignore bad email addresses and do not raise email delivery errors.
- # Set this to true and configure the email server for immediate delivery to raise delivery errors.
- # config.action_mailer.raise_delivery_errors = false
+ config.action_mailer.raise_delivery_errors = true
+ config.action_mailer.delivery_method = :mailjet
+ config.action_mailer.perform_deliveries = true
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
diff --git a/config/initializers/mailjet.rb b/config/initializers/mailjet.rb
new file mode 100644
index 000000000..01c67dbd0
--- /dev/null
+++ b/config/initializers/mailjet.rb
@@ -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.fetch('SMTP_DEFAULT_FROM', 'from@example.com')
+end
diff --git a/config/routes.rb b/config/routes.rb
index 856d9837b..ab6986f29 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -23,6 +23,8 @@
get :levels_chart_data
get :cp_performance_chart_data
get :user_download_all
+ get :user_download_methodology
+ post :send_download_file_info_email
end
member do
get :levels_chart_data
diff --git a/spec/controllers/tpi/sectors_controller_spec.rb b/spec/controllers/tpi/sectors_controller_spec.rb
index ea660ed38..ffbce90de 100644
--- a/spec/controllers/tpi/sectors_controller_spec.rb
+++ b/spec/controllers/tpi/sectors_controller_spec.rb
@@ -155,10 +155,9 @@
expect(entries_names).to include("CP_Assessments_#{timestamp}.csv")
expect(entries_names).to include("CP_Assessments_Regional_#{timestamp}.csv")
expect(entries_names).to include('Company_Latest_Assessments.csv')
- expect(entries_names).to include('Company_Latest_Assessments_BETA_5.0.csv')
+ expect(entries_names).to include('Company_Latest_Assessments_5.0.csv')
expect(entries_names).to include("MQ_Assessments_Methodology_1_#{timestamp}.csv")
- expect(entries_names).to include("MQ_Assessments_Methodology_5_BETA_#{timestamp}.csv")
- expect(entries_names).to include('User guide TPI files.xlsx')
+ expect(entries_names).to include("MQ_Assessments_Methodology_5_#{timestamp}.csv")
expect(entries_csv_json["Sector_Benchmarks_#{timestamp}.csv"])
.to match_snapshot('tpi_single_sector_user_download_zip_sector_benchmarks_csv')
@@ -168,11 +167,11 @@
.to match_snapshot('tpi_single_sector_user_download_cp_assessments_regional_csv')
expect(entries_csv_json['Company_Latest_Assessments.csv'])
.to match_snapshot('tpi_single_sector_user_company_latest_assessments_csv')
- expect(entries_csv_json['Company_Latest_Assessments_BETA_5.0.csv'])
+ expect(entries_csv_json['Company_Latest_Assessments_5.0.csv'])
.to match_snapshot('tpi_single_sector_user_company_latest_assessments_beta_5.0_csv')
expect(entries_csv_json["MQ_Assessments_Methodology_1_#{timestamp}.csv"])
.to match_snapshot('tpi_single_sector_user_mq_assessments_methodology_1_csv')
- expect(entries_csv_json["MQ_Assessments_Methodology_5_BETA_#{timestamp}.csv"])
+ expect(entries_csv_json["MQ_Assessments_Methodology_5_#{timestamp}.csv"])
.to match_snapshot('tpi_single_sector_user_mq_assessments_methodology_5_beta_csv')
end
end
@@ -207,10 +206,9 @@
expect(entries_names).to include("Sector_Benchmarks_#{timestamp}.csv")
expect(entries_names).to include("CP_Assessments_#{timestamp}.csv")
expect(entries_names).to include('Company_Latest_Assessments.csv')
- expect(entries_names).to include('Company_Latest_Assessments_BETA_5.0.csv')
+ expect(entries_names).to include('Company_Latest_Assessments_5.0.csv')
expect(entries_names).to include("MQ_Assessments_Methodology_1_#{timestamp}.csv")
- expect(entries_names).to include("MQ_Assessments_Methodology_5_BETA_#{timestamp}.csv")
- expect(entries_names).to include('User guide TPI files.xlsx')
+ expect(entries_names).to include("MQ_Assessments_Methodology_5_#{timestamp}.csv")
expect(entries_csv_json["Sector_Benchmarks_#{timestamp}.csv"])
.to match_snapshot('tpi_all_sectors_user_download_zip_sector_benchmarks_csv')
@@ -218,13 +216,66 @@
.to match_snapshot('tpi_all_sectors_user_download_cp_assessments_csv')
expect(entries_csv_json['Company_Latest_Assessments.csv'])
.to match_snapshot('tpi_all_sectors_user_company_latest_assessments_csv')
- expect(entries_csv_json['Company_Latest_Assessments_BETA_5.0.csv'])
+ expect(entries_csv_json['Company_Latest_Assessments_5.0.csv'])
.to match_snapshot('tpi_all_sectors_user_company_latest_assessments_beta_5.0_csv')
expect(entries_csv_json["MQ_Assessments_Methodology_1_#{timestamp}.csv"])
.to match_snapshot('tpi_all_sectors_user_mq_assessments_methodology_1_csv')
- expect(entries_csv_json["MQ_Assessments_Methodology_5_BETA_#{timestamp}.csv"])
+ expect(entries_csv_json["MQ_Assessments_Methodology_5_#{timestamp}.csv"])
.to match_snapshot('tpi_all_sectors_user_mq_assessments_methodology_5_beta_csv')
end
end
end
+
+ describe 'GET user download methodology' do
+ subject { get :user_download_methodology }
+
+ it { is_expected.to be_successful }
+
+ it 'returns zip file' do
+ subject
+ expect(response.content_type).to eq('application/zip')
+ end
+
+ describe 'zip file' do
+ it 'has proper content' do
+ subject
+
+ entries_names = []
+ entries_csv_json = {}
+ zip_io = StringIO.new(response.body)
+ Zip::File.open_buffer(zip_io) do |zipfile|
+ zipfile.each do |entry|
+ entries_names << entry.name
+ entries_csv_json[entry.name] = parse_csv_to_json(entry.get_input_stream.read) if entry.name.ends_with?('.csv')
+ end
+ end
+
+ expect(entries_names).to include('User guide TPI files.xlsx')
+ end
+ end
+ end
+
+ describe 'POST send_download_file_info_email' do
+ subject { post :send_download_file_info_email, params: data }
+ let(:data) do
+ {
+ email: 'test@test.test',
+ 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
diff --git a/spec/mailers/data_download_mailer_spec.rb b/spec/mailers/data_download_mailer_spec.rb
new file mode 100644
index 000000000..357f3fa74
--- /dev/null
+++ b/spec/mailers/data_download_mailer_spec.rb
@@ -0,0 +1,33 @@
+require 'rails_helper'
+
+RSpec.describe DataDownloadMailer, type: :mailer do
+ describe 'send_download_file_info_email' do
+ let(:data) {
+ {
+ email: 'test@test.test',
+ job_title: 'job_title',
+ forename: 'forename',
+ surname: 'surname',
+ location: 'location',
+ organisation: 'organisation',
+ purposes: %w[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(['tpi@lse.ac.uk'])
+ expect(mail.from).to eq([ENV.fetch('SMTP_DEFAULT_FROM', 'from@example.com')])
+
+ expect(mail.body.encoded).to include('test@test.test')
+ 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
diff --git a/spec/support/capybara_helpers.rb b/spec/support/capybara_helpers.rb
index 2489ca44c..97d7e6a30 100644
--- a/spec/support/capybara_helpers.rb
+++ b/spec/support/capybara_helpers.rb
@@ -30,16 +30,13 @@ def within_ascor_pillar(header_text)
end
end
- def with_mq_beta_scores
+ def with_older_mq_scores
within '.mq-beta-scores' do
- click_on 'Current V5.0'
- end
- within '.modal-content' do
- click_on 'Proceed'
+ click_on 'V4.0'
end
yield
within '.mq-beta-scores' do
- click_on 'V4.0'
+ click_on 'Current V5.0'
end
end
diff --git a/spec/system/public/tpi/company_spec.rb b/spec/system/public/tpi/company_spec.rb
index 66e783c9c..ec8b53575 100644
--- a/spec/system/public/tpi/company_spec.rb
+++ b/spec/system/public/tpi/company_spec.rb
@@ -9,13 +9,13 @@
expect(page).to have_text('Japan Airlines')
end
- it 'does not show BETA scores by default' do
- expect(page).not_to have_text('Level 5')
+ it 'show BETA scores by default' do
+ expect(page).to have_text('Level 5')
end
- it 'allows to show BETA scores' do
- with_mq_beta_scores do
- expect(page).to have_text('Level 5')
+ it 'allow to see older methodology' do
+ with_older_mq_scores do
+ expect(page).not_to have_text('Level 5')
end
end
diff --git a/spec/system/public/tpi/sectors_spec.rb b/spec/system/public/tpi/sectors_spec.rb
index d8ea6b39e..8a714baf6 100644
--- a/spec/system/public/tpi/sectors_spec.rb
+++ b/spec/system/public/tpi/sectors_spec.rb
@@ -11,26 +11,26 @@
# pie chart
within '.chart--mq-sector-pie-chart' do
- expect(page).not_to have_text('Level 5')
+ expect(page).to have_text('Level 5')
expect(page).to have_selector('.companies-size', text: '111')
end
# bubble chart loads
within '.bubble-chart__container' do
- expect(page).not_to have_text('Level 5')
+ expect(page).to have_text('Level 5')
expect(page).to have_text('Autos')
expect(page).to have_text('Airlines')
end
end
- it 'loads also beta scores' do
- with_mq_beta_scores do
+ it 'load old mq scores' do
+ with_older_mq_scores do
within '.chart--mq-sector-pie-chart' do
- expect(page).to have_text('Level 5')
+ expect(page).not_to have_text('Level 5')
end
within '.bubble-chart__container' do
- expect(page).to have_text('Level 5')
+ expect(page).not_to have_text('Level 5')
end
end
end
@@ -49,15 +49,15 @@
expect(page).to have_text('Level 2 ? 0 companies', normalize_ws: true) # Level 2 0 companies
expect(page).to have_text('Level 3 ? 2 companies', normalize_ws: true) # Level 3 2 companies
expect(page).to have_text('Level 4 ? 1 company', normalize_ws: true) # Level 4 1 company
- expect(page).not_to have_text('Level 5') # BETA level that is disabled by default
+ expect(page).to have_text('Level 5')
expect(page).to have_selector('.companies-size', text: '5')
end
end
- it 'loads also beta scores' do
- with_mq_beta_scores do
+ it 'switch to older level scores' do
+ with_older_mq_scores do
within '.chart--mq-sector-pie-chart' do
- expect(page).to have_text('Level 5')
+ expect(page).not_to have_text('Level 5')
end
end
end