-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2130 from unboxed/consultee-expiredlink
Resend magic link for consultees
- Loading branch information
Showing
13 changed files
with
177 additions
and
15 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
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
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
6 changes: 6 additions & 0 deletions
6
engines/bops_core/app/jobs/concerns/bops_core/application_job.rb
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 @@ | ||
# frozen_string_literal: true | ||
|
||
module BopsCore | ||
class ApplicationJob < ActiveJob::Base | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
engines/bops_core/app/jobs/concerns/bops_core/magic_link_mailer_job.rb
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 @@ | ||
# frozen_string_literal: true | ||
|
||
module BopsCore | ||
class MagicLinkMailerJob < ApplicationJob | ||
queue_as :low_priority | ||
|
||
def perform(resource:, planning_application:, subdomain:) | ||
MagicLinkMailer.magic_link_mail( | ||
resource: resource, | ||
planning_application: planning_application, | ||
subdomain: subdomain | ||
).deliver_now | ||
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
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module BopsCore | ||
module Presentable | ||
extend ActiveSupport::Concern | ||
include Rails.application.routes.url_helpers | ||
|
||
attr_reader :template, :planning_application | ||
|
||
delegate :tag, :concat, :link_to, :truncate, :link_to_if, to: :template | ||
delegate :to_param, to: :presented | ||
|
||
class_methods do | ||
def presents(presented) | ||
define_method(:presented) do | ||
@presented ||= send(presented) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def method_missing(method_name, *, **kwargs, &) | ||
if presented.respond_to?(method_name) | ||
kwargs.any? ? presented.send(method_name, **kwargs, &) : presented.send(method_name, *, &) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def respond_to_missing?(method_name, *args) | ||
presented.respond_to?(method_name) || super | ||
end | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
engines/bops_core/app/views/bops_core/magic_link_mailer/magic_link_mail.text.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Hello <%= @resource.name %> | ||
|
||
Click the link below to access your dashboard: | ||
This is your magic link. | ||
|
||
<%= link_to "Access Dashboard", @url %> | ||
<%= link_to "View BOPS application: #{@planning_application.reference_in_full}", @url %> | ||
|
||
This link will expire in 48 hours. |
23 changes: 23 additions & 0 deletions
23
engines/bops_core/spec/jobs/bops_core/magic_link_mailer_job_spec.rb
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bops_core_helper" | ||
|
||
RSpec.describe BopsCore::MagicLinkMailerJob, type: :job do | ||
let(:consultation) { create(:consultation) } | ||
let(:consultee) { create(:consultee, consultation:) } | ||
let(:planning_application) { create(:planning_application, consultation:) } | ||
|
||
it "enqueues the job" do | ||
expect { | ||
BopsCore::MagicLinkMailerJob.perform_later(resource: consultee, planning_application:, subdomain: "southwark") | ||
}.to have_enqueued_job(BopsCore::MagicLinkMailerJob).with(resource: consultee, planning_application:, subdomain: "southwark") | ||
end | ||
|
||
it "sends the email" do | ||
expect { | ||
perform_enqueued_jobs do | ||
BopsCore::MagicLinkMailerJob.perform_now(resource: consultee, planning_application:, subdomain: "southwark") | ||
end | ||
}.to change { ActionMailer::Base.deliveries.count }.by(1) | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
engines/bops_core/spec/mailers/bops_core/magic_link_mailer_spec.rb
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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bops_core_helper" | ||
|
||
RSpec.describe BopsCore::MagicLinkMailer, type: :mailer do | ||
describe "magic_link_mail" do | ||
let(:consultation) { create(:consultation) } | ||
let(:consultee) { create(:consultee, consultation:, email_address: "[email protected]", name: "Bops Consultee") } | ||
let(:planning_application) { consultation.planning_application } | ||
let(:mail) { described_class.magic_link_mail(resource: consultee, planning_application:, subdomain: "southwark", subject: "Your magic link") } | ||
|
||
before do | ||
allow(consultee).to receive(:sgid).and_return("123456789") | ||
end | ||
|
||
it "renders the subject" do | ||
expect(mail.subject).to eq("Your magic link") | ||
end | ||
|
||
it "sends to the correct email address" do | ||
expect(mail.to).to eq([consultee.email_address]) | ||
end | ||
|
||
it "assigns the correct magic link URL" do | ||
expect(mail.body.encoded).to include("http://southwark.bops.services/consultees/planning_applications/25-00100-LDCE?sgid=123456789") | ||
end | ||
|
||
it "includes the planning application reference in the email body" do | ||
expect(mail.body.encoded).to include("View BOPS application: #{planning_application.reference_in_full}") | ||
end | ||
|
||
it "includes the link expiration information" do | ||
expect(mail.body.encoded).to include("This link will expire in 48 hours.") | ||
end | ||
end | ||
end |