Skip to content

Commit

Permalink
Store access_your_teaching_qualifications_url
Browse files Browse the repository at this point in the history
This updates the UpdateDQTTRNRequestJob and AwardQTS service to retrieve
the URL from DQT and store it with the teacher, so we can choose to
start presenting it to users in the future.
  • Loading branch information
thomasleese committed Sep 13, 2023
1 parent ee537f3 commit 9cd1c15
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 9 deletions.
8 changes: 7 additions & 1 deletion app/jobs/update_dqt_trn_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ def perform(dqt_trn_request)
ApplicationFormStatusUpdater.call(application_form:, user: "DQT")

unless potential_duplicate
AwardQTS.call(application_form:, user: "DQT", trn: response[:trn])
AwardQTS.call(
application_form:,
user: "DQT",
trn: response[:trn],
access_your_teaching_qualifications_url:
response[:access_your_teaching_qualifications_link],
)
dqt_trn_request.complete!
end

Expand Down
16 changes: 13 additions & 3 deletions app/services/award_qts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
class AwardQTS
include ServicePattern

def initialize(application_form:, user:, trn:)
def initialize(
application_form:,
user:,
trn:,
access_your_teaching_qualifications_url:
)
@application_form = application_form
@user = user
@trn = trn
@access_your_teaching_qualifications_url =
access_your_teaching_qualifications_url
end

def call
Expand All @@ -20,7 +27,7 @@ def call
raise MissingTRN if trn.blank?

ActiveRecord::Base.transaction do
teacher.update!(trn:)
teacher.update!(trn:, access_your_teaching_qualifications_url:)
application_form.update!(awarded_at: Time.zone.now)
ApplicationFormStatusUpdater.call(application_form:, user:)
end
Expand All @@ -36,7 +43,10 @@ class MissingTRN < StandardError

private

attr_reader :application_form, :user, :trn
attr_reader :application_form,
:user,
:trn,
:access_your_teaching_qualifications_url

delegate :teacher, to: :application_form
end
14 changes: 12 additions & 2 deletions spec/jobs/update_dqt_trn_request_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
context "with a successful response" do
before do
expect(DQT::Client::CreateTRNRequest).to receive(:call).and_return(
{ potential_duplicate: false, trn: "abcdef" },
{
potential_duplicate: false,
trn: "abcdef",
access_your_teaching_qualifications_link: "https://aytq.com",
},
)
end

Expand All @@ -40,6 +44,7 @@
application_form:,
user: "DQT",
trn: "abcdef",
access_your_teaching_qualifications_url: "https://aytq.com",
)
perform
end
Expand Down Expand Up @@ -128,7 +133,11 @@
context "with a successful response" do
before do
expect(DQT::Client::ReadTRNRequest).to receive(:call).and_return(
{ potential_duplicate: false, trn: "abcdef" },
{
potential_duplicate: false,
trn: "abcdef",
access_your_teaching_qualifications_link: "https://aytq.com",
},
)
end

Expand All @@ -148,6 +157,7 @@
application_form:,
user: "DQT",
trn: "abcdef",
access_your_teaching_qualifications_url: "https://aytq.com",
)
perform
end
Expand Down
35 changes: 32 additions & 3 deletions spec/services/award_qts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
let(:teacher) { create(:teacher) }
let(:user) { create(:staff, :confirmed) }
let(:trn) { "abcdef" }

subject(:call) { described_class.call(application_form:, user:, trn:) }
let(:access_your_teaching_qualifications_url) { "https://aytq.com" }

subject(:call) do
described_class.call(
application_form:,
user:,
trn:,
access_your_teaching_qualifications_url:,
)
end

context "with a submitted application form" do
let(:application_form) { create(:application_form, :submitted, teacher:) }
Expand All @@ -26,6 +34,13 @@
expect { call }.to change(teacher, :trn).to("abcdef")
end

it "sets the access your teaching qualifications URL" do
expect { call }.to change(
teacher,
:access_your_teaching_qualifications_url,
).to("https://aytq.com")
end

it "sends an email" do
expect { call }.to have_enqueued_mail(
TeacherMailer,
Expand Down Expand Up @@ -63,6 +78,13 @@
expect { call }.to change(teacher, :trn).to("abcdef")
end

it "sets the access your teaching qualifications URL" do
expect { call }.to change(
teacher,
:access_your_teaching_qualifications_url,
).to("https://aytq.com")
end

it "sends an email" do
expect { call }.to have_enqueued_mail(
TeacherMailer,
Expand Down Expand Up @@ -94,10 +116,17 @@
context "with an awarded application form" do
let(:application_form) { create(:application_form, :awarded, teacher:) }

it "doesn't set the TRN" do
it "doesn't change the TRN" do
expect { call }.to_not change(teacher, :trn)
end

it "doesn't change the access your teaching qualifications URL" do
expect { call }.to_not change(
teacher,
:access_your_teaching_qualifications_url,
)
end

it "doesn't send an email" do
expect { call }.to_not have_enqueued_mail(
TeacherMailer,
Expand Down

0 comments on commit 9cd1c15

Please sign in to comment.