Skip to content

Commit

Permalink
Merge pull request #2509 from DFE-Digital/AQTS-670-build-client-to-ma…
Browse files Browse the repository at this point in the history
…ke-post-and-get-requests-for-trn-allocation

Updating class names and secret names to move away from using DQT and instead refer to the teaching record system as TRS
  • Loading branch information
Hassanmir92 authored Nov 18, 2024
2 parents d471422 + b5a6879 commit 6602b8a
Show file tree
Hide file tree
Showing 41 changed files with 525 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def update_confirm
if @form.confirmation
ActiveRecord::Base.transaction do
assessment.award!
CreateDQTTRNRequest.call(application_form:, user: current_staff)
CreateTRSTRNRequest.call(application_form:, user: current_staff)
end

redirect_to [:status, :assessor_interface, application_form]
Expand Down
6 changes: 3 additions & 3 deletions app/jobs/update_dqt_match_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def perform(application_form)
return
end

teachers = DQT::Client::FindTeachers.call(application_form:)
teachers = TRS::Client::FindTeachers.call(application_form:)

if teachers.empty?
teachers =
DQT::Client::FindTeachers.call(application_form:, reverse_name: true)
TRS::Client::FindTeachers.call(application_form:, reverse_name: true)
end

application_form.update!(dqt_match: { teachers: })

UpdateDQTMatchJob.set(wait: 24.hours).perform_later(application_form)
UpdateTRSMatchJob.set(wait: 24.hours).perform_later(application_form)
end
end
6 changes: 3 additions & 3 deletions app/jobs/update_dqt_trn_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ def perform(dqt_trn_request)
end

if dqt_trn_request.pending?
UpdateDQTTRNRequestJob.set(wait: 1.hour).perform_later(dqt_trn_request)
UpdateTRSTRNRequestJob.set(wait: 1.hour).perform_later(dqt_trn_request)
end
end

private

def fetch_response(dqt_trn_request)
if dqt_trn_request.initial?
DQT::Client::CreateTRNRequest.call(
TRS::Client::CreateTRNRequest.call(
request_id: dqt_trn_request.request_id,
application_form: dqt_trn_request.application_form,
)
else
DQT::Client::ReadTRNRequest.call(request_id: dqt_trn_request.request_id)
TRS::Client::ReadTRNRequest.call(request_id: dqt_trn_request.request_id)
end
rescue Faraday::Error => e
Sentry.configure_scope do |scope|
Expand Down
22 changes: 22 additions & 0 deletions app/jobs/update_trs_match_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

class UpdateTRSMatchJob < ApplicationJob
def perform(application_form)
unless application_form.submitted? && application_form.awarded_at.nil? &&
application_form.declined_at.nil? &&
application_form.withdrawn_at.nil?
return
end

teachers = TRS::Client::FindTeachers.call(application_form:)

if teachers.empty?
teachers =
TRS::Client::FindTeachers.call(application_form:, reverse_name: true)
end

application_form.update!(dqt_match: { teachers: })

UpdateTRSMatchJob.set(wait: 24.hours).perform_later(application_form)
end
end
61 changes: 61 additions & 0 deletions app/jobs/update_trs_trn_request_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

class UpdateTRSTRNRequestJob < ApplicationJob
def perform(dqt_trn_request)
return if dqt_trn_request.complete?

application_form = dqt_trn_request.application_form

response = fetch_response(dqt_trn_request)

dqt_trn_request.pending! if dqt_trn_request.initial?

potential_duplicate = response[:potential_duplicate]
if potential_duplicate != dqt_trn_request.potential_duplicate
dqt_trn_request.update!(potential_duplicate:)
end

ApplicationFormStatusUpdater.call(application_form:, user: "DQT")

unless potential_duplicate
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

if dqt_trn_request.pending?
UpdateTRSTRNRequestJob.set(wait: 1.hour).perform_later(dqt_trn_request)
end
end

private

def fetch_response(dqt_trn_request)
if dqt_trn_request.initial?
TRS::Client::CreateTRNRequest.call(
request_id: dqt_trn_request.request_id,
application_form: dqt_trn_request.application_form,
)
else
TRS::Client::ReadTRNRequest.call(request_id: dqt_trn_request.request_id)
end
rescue Faraday::Error => e
Sentry.configure_scope do |scope|
scope.set_context(
"response",
{
status: e.response_status,
headers: e.response_headers,
body: e.response_body,
},
)
end

raise
end
end
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

module DQT::Client::Connection
module TRS::Client::Connection
def connection
@connection ||=
Faraday.new(url: Rails.configuration.dqt.url) do |faraday|
Faraday.new(url: Rails.configuration.trs.url) do |faraday|
faraday.request :authorization,
"Bearer",
Rails.configuration.dqt.api_key
Rails.configuration.trs.api_key
faraday.request :json
faraday.response :json
faraday.response :raise_error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class DQT::Client::CreateTRNRequest
class TRS::Client::CreateTRNRequest
include ServicePattern
include DQT::Client::Connection
include TRS::Client::Connection

def initialize(request_id:, application_form:)
@request_id = request_id
Expand All @@ -11,7 +11,7 @@ def initialize(request_id:, application_form:)

def call
path = "/v2/trn-requests/#{request_id}"
body = DQT::TRNRequestParams.call(application_form:)
body = TRS::TRNRequestParams.call(application_form:)
connection
.put(path, body)
.body
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class DQT::Client::FindTeachers
class TRS::Client::FindTeachers
include ServicePattern
include DQT::Client::Connection
include TRS::Client::Connection

attr_reader :application_form, :reverse_name

Expand All @@ -16,7 +16,7 @@ def call
response =
connection.get(
path,
DQT::FindTeachersParams.call(application_form:, reverse_name:),
TRS::FindTeachersParams.call(application_form:, reverse_name:),
)
if response.success?
response.body["results"].map do |r|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class DQT::Client::ReadTRNRequest
class TRS::Client::ReadTRNRequest
include ServicePattern
include DQT::Client::Connection
include TRS::Client::Connection

def initialize(request_id:)
@request_id = request_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class DQT::CountryCode
class TRS::CountryCode
class << self
def for_code(code)
# Cyprus (European Union)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module DQT
module TRS
class FindTeachersParams
include ServicePattern

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class DQT::RecognitionRoute
class TRS::RecognitionRoute
class << self
def for_country_code(country_code, under_old_regulations:)
if CountryCode.scotland?(country_code)
Expand Down
4 changes: 2 additions & 2 deletions app/lib/dqt/subject.rb → app/lib/trs/subject.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

class DQT::Subject
class TRS::Subject
class << self
def for(value)
# these three subjects are not coded by HESA so we've agreed these encodings with the DQT team
# these three subjects are not coded by HESA so we've agreed these encodings with the TRS team
return "999001" if value == "citizenship"
return "999002" if value == "physical_education"
return "999003" if value == "design_and_technology"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module DQT
module TRS
class TRNRequestParams
include ServicePattern

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateDQTTRNRequest
class CreateTRSTRNRequest
include ServicePattern

def initialize(application_form:, user:)
Expand All @@ -12,7 +12,7 @@ def call
request_id = SecureRandom.uuid
dqt_trn_request = DQTTRNRequest.create!(request_id:, application_form:)
ApplicationFormStatusUpdater.call(application_form:, user:)
UpdateDQTTRNRequestJob.perform_later(dqt_trn_request)
UpdateTRSTRNRequestJob.perform_later(dqt_trn_request)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/services/submit_application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def call
)
end

UpdateDQTMatchJob.set(wait: 5.minutes).perform_later(application_form)
UpdateTRSMatchJob.set(wait: 5.minutes).perform_later(application_form)
end

private
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Application < Rails::Application
] = :forbidden
config.action_mailer.deliver_later_queue_name = "mailer"

config.dqt = config_for(:dqt)
config.trs = config_for(:trs)
config.gov_one = config_for(:gov_one)
end
end
11 changes: 0 additions & 11 deletions config/dqt.yml

This file was deleted.

1 change: 1 addition & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
inflect.acronym "PDF"
inflect.acronym "QTS"
inflect.acronym "TRN"
inflect.acronym "TRS"
inflect.uncountable %w[staff]
end
11 changes: 11 additions & 0 deletions config/trs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
development:
url: <%= ENV.fetch("TRS_API_URL", "https://dev.teacher-qualifications-api.education.gov.uk") %>
api_key: <%= ENV["TRS_API_KEY"] %>

production:
url: <%= ENV.fetch("TRS_API_URL", "https://teacher-qualifications-api.education.gov.uk") %>
api_key: <%= ENV["TRS_API_KEY"] %>

test:
url: https://test-teacher-qualifications-api.education.gov.uk
api_key: test-api-key
2 changes: 1 addition & 1 deletion docs/application-fixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ application_form.awarded_pending_checks!

# process the award

CreateDQTTRNRequest.call(application_form:, user:)
CreateTRSTRNRequest.call(application_form:, user:)
```

Check the application is in awarded state in the UI and that the sidekiq jobs have gone through.
Expand Down
12 changes: 6 additions & 6 deletions spec/jobs/update_dqt_match_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
create(:application_form, :submitted, :with_personal_information)
end

before { allow(DQT::Client::FindTeachers).to receive(:call).and_return([]) }
before { allow(TRS::Client::FindTeachers).to receive(:call).and_return([]) }

it "searches DQT for teachers" do
expect(DQT::Client::FindTeachers).to receive(:call).with(
expect(TRS::Client::FindTeachers).to receive(:call).with(
application_form:,
)

expect(DQT::Client::FindTeachers).to receive(:call).with(
expect(TRS::Client::FindTeachers).to receive(:call).with(
application_form:,
reverse_name: true,
)
Expand Down Expand Up @@ -47,7 +47,7 @@
},
]

allow(DQT::Client::FindTeachers).to receive(:call).with(
allow(TRS::Client::FindTeachers).to receive(:call).with(
application_form:,
).and_return(results)

Expand All @@ -60,7 +60,7 @@
let(:application_form) { create(:application_form, :draft) }

it "doesn't search DQT for teachers" do
expect(DQT::Client::FindTeachers).not_to receive(:call)
expect(TRS::Client::FindTeachers).not_to receive(:call)

perform
end
Expand All @@ -70,7 +70,7 @@
let(:application_form) { create(:application_form, :awarded) }

it "doesn't search DQT for teachers" do
expect(DQT::Client::FindTeachers).not_to receive(:call)
expect(TRS::Client::FindTeachers).not_to receive(:call)

perform
end
Expand Down
Loading

0 comments on commit 6602b8a

Please sign in to comment.