diff --git a/app/controllers/assessor_interface/assessment_recommendation_award_controller.rb b/app/controllers/assessor_interface/assessment_recommendation_award_controller.rb index 26a153af3a..3459e7ef4c 100644 --- a/app/controllers/assessor_interface/assessment_recommendation_award_controller.rb +++ b/app/controllers/assessor_interface/assessment_recommendation_award_controller.rb @@ -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] diff --git a/app/jobs/update_dqt_match_job.rb b/app/jobs/update_dqt_match_job.rb index 1b0f3a3993..700c7f68b2 100644 --- a/app/jobs/update_dqt_match_job.rb +++ b/app/jobs/update_dqt_match_job.rb @@ -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 diff --git a/app/jobs/update_dqt_trn_request_job.rb b/app/jobs/update_dqt_trn_request_job.rb index ed167cf935..bd8bdb244a 100644 --- a/app/jobs/update_dqt_trn_request_job.rb +++ b/app/jobs/update_dqt_trn_request_job.rb @@ -29,7 +29,7 @@ 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 @@ -37,12 +37,12 @@ def perform(dqt_trn_request) 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| diff --git a/app/jobs/update_trs_match_job.rb b/app/jobs/update_trs_match_job.rb new file mode 100644 index 0000000000..e73d6f81e5 --- /dev/null +++ b/app/jobs/update_trs_match_job.rb @@ -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 diff --git a/app/jobs/update_trs_trn_request_job.rb b/app/jobs/update_trs_trn_request_job.rb new file mode 100644 index 0000000000..eb44385dd9 --- /dev/null +++ b/app/jobs/update_trs_trn_request_job.rb @@ -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 diff --git a/app/lib/dqt/client/connection.rb b/app/lib/trs/client/connection.rb similarity index 63% rename from app/lib/dqt/client/connection.rb rename to app/lib/trs/client/connection.rb index 8149f65a5f..2c33cce69a 100644 --- a/app/lib/dqt/client/connection.rb +++ b/app/lib/trs/client/connection.rb @@ -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 diff --git a/app/lib/dqt/client/create_trn_request.rb b/app/lib/trs/client/create_trn_request.rb similarity index 76% rename from app/lib/dqt/client/create_trn_request.rb rename to app/lib/trs/client/create_trn_request.rb index aff4386932..020f2e321a 100644 --- a/app/lib/dqt/client/create_trn_request.rb +++ b/app/lib/trs/client/create_trn_request.rb @@ -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 @@ -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 diff --git a/app/lib/dqt/client/find_teachers.rb b/app/lib/trs/client/find_teachers.rb similarity index 80% rename from app/lib/dqt/client/find_teachers.rb rename to app/lib/trs/client/find_teachers.rb index 8ec49d613a..c7a6140f0d 100644 --- a/app/lib/dqt/client/find_teachers.rb +++ b/app/lib/trs/client/find_teachers.rb @@ -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 @@ -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| diff --git a/app/lib/dqt/client/read_trn_request.rb b/app/lib/trs/client/read_trn_request.rb similarity index 81% rename from app/lib/dqt/client/read_trn_request.rb rename to app/lib/trs/client/read_trn_request.rb index 28ecbb33fc..e93ad85b9d 100644 --- a/app/lib/dqt/client/read_trn_request.rb +++ b/app/lib/trs/client/read_trn_request.rb @@ -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 diff --git a/app/lib/dqt/country_code.rb b/app/lib/trs/country_code.rb similarity index 96% rename from app/lib/dqt/country_code.rb rename to app/lib/trs/country_code.rb index 4592970641..a376ba47df 100644 --- a/app/lib/dqt/country_code.rb +++ b/app/lib/trs/country_code.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class DQT::CountryCode +class TRS::CountryCode class << self def for_code(code) # Cyprus (European Union) diff --git a/app/lib/dqt/find_teachers_params.rb b/app/lib/trs/find_teachers_params.rb similarity index 98% rename from app/lib/dqt/find_teachers_params.rb rename to app/lib/trs/find_teachers_params.rb index 73b19854fd..63f17680b3 100644 --- a/app/lib/dqt/find_teachers_params.rb +++ b/app/lib/trs/find_teachers_params.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DQT +module TRS class FindTeachersParams include ServicePattern diff --git a/app/lib/dqt/recognition_route.rb b/app/lib/trs/recognition_route.rb similarity index 94% rename from app/lib/dqt/recognition_route.rb rename to app/lib/trs/recognition_route.rb index 011864e49f..9bfe258307 100644 --- a/app/lib/dqt/recognition_route.rb +++ b/app/lib/trs/recognition_route.rb @@ -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) diff --git a/app/lib/dqt/subject.rb b/app/lib/trs/subject.rb similarity index 98% rename from app/lib/dqt/subject.rb rename to app/lib/trs/subject.rb index f3490e71f0..af05b221cb 100644 --- a/app/lib/dqt/subject.rb +++ b/app/lib/trs/subject.rb @@ -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" diff --git a/app/lib/dqt/trn_request_params.rb b/app/lib/trs/trn_request_params.rb similarity index 99% rename from app/lib/dqt/trn_request_params.rb rename to app/lib/trs/trn_request_params.rb index d3e431fbe2..0f1ea4a5e4 100644 --- a/app/lib/dqt/trn_request_params.rb +++ b/app/lib/trs/trn_request_params.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DQT +module TRS class TRNRequestParams include ServicePattern diff --git a/app/services/create_dqt_trn_request.rb b/app/services/create_trs_trn_request.rb similarity index 83% rename from app/services/create_dqt_trn_request.rb rename to app/services/create_trs_trn_request.rb index c0d5641484..8cac269be9 100644 --- a/app/services/create_dqt_trn_request.rb +++ b/app/services/create_trs_trn_request.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateDQTTRNRequest +class CreateTRSTRNRequest include ServicePattern def initialize(application_form:, user:) @@ -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 diff --git a/app/services/submit_application_form.rb b/app/services/submit_application_form.rb index 14f1ce74af..9a48d2d7c4 100644 --- a/app/services/submit_application_form.rb +++ b/app/services/submit_application_form.rb @@ -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 diff --git a/config/application.rb b/config/application.rb index 22bfa2ecfe..ee141ab5bf 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/dqt.yml b/config/dqt.yml deleted file mode 100644 index f45d133180..0000000000 --- a/config/dqt.yml +++ /dev/null @@ -1,11 +0,0 @@ -development: - url: <%= ENV.fetch("DQT_API_URL", "https://dev.teacher-qualifications-api.education.gov.uk") %> - api_key: <%= ENV["DQT_API_KEY"] %> - -production: - url: <%= ENV.fetch("DQT_API_URL", "https://teacher-qualifications-api.education.gov.uk") %> - api_key: <%= ENV["DQT_API_KEY"] %> - -test: - url: https://test-teacher-qualifications-api.education.gov.uk - api_key: test-api-key diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 7bfd9a9cbd..815b74f83c 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -8,5 +8,6 @@ inflect.acronym "PDF" inflect.acronym "QTS" inflect.acronym "TRN" + inflect.acronym "TRS" inflect.uncountable %w[staff] end diff --git a/config/trs.yml b/config/trs.yml new file mode 100644 index 0000000000..4895a86f7e --- /dev/null +++ b/config/trs.yml @@ -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 diff --git a/docs/application-fixes.md b/docs/application-fixes.md index 5cfcf53f52..c783696536 100644 --- a/docs/application-fixes.md +++ b/docs/application-fixes.md @@ -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. diff --git a/spec/jobs/update_dqt_match_job_spec.rb b/spec/jobs/update_dqt_match_job_spec.rb index 808d4371fa..35ae5cd4c1 100644 --- a/spec/jobs/update_dqt_match_job_spec.rb +++ b/spec/jobs/update_dqt_match_job_spec.rb @@ -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, ) @@ -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) @@ -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 @@ -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 diff --git a/spec/jobs/update_dqttrn_request_job_spec.rb b/spec/jobs/update_dqttrn_request_job_spec.rb index b707004d19..beac387845 100644 --- a/spec/jobs/update_dqttrn_request_job_spec.rb +++ b/spec/jobs/update_dqttrn_request_job_spec.rb @@ -21,7 +21,7 @@ context "with a successful response" do before do - allow(DQT::Client::CreateTRNRequest).to receive(:call).and_return( + allow(TRS::Client::CreateTRNRequest).to receive(:call).and_return( { potential_duplicate: false, trn: "abcdef", @@ -52,13 +52,13 @@ end it "doesn't queue another job" do - expect { perform }.not_to have_enqueued_job(described_class) + expect { perform }.not_to have_enqueued_job(UpdateTRSTRNRequestJob) end end context "with a failure response" do before do - allow(DQT::Client::CreateTRNRequest).to receive(:call).and_raise( + allow(TRS::Client::CreateTRNRequest).to receive(:call).and_raise( Faraday::BadRequestError.new(StandardError.new), ) end @@ -96,7 +96,7 @@ context "with a potential duplicate response" do before do - allow(DQT::Client::CreateTRNRequest).to receive(:call).and_return( + allow(TRS::Client::CreateTRNRequest).to receive(:call).and_return( { potential_duplicate: true }, ) end @@ -124,7 +124,9 @@ end it "queues another job" do - expect { perform }.to have_enqueued_job(described_class) + expect { perform }.to have_enqueued_job(UpdateTRSTRNRequestJob).with( + dqt_trn_request, + ) end end end @@ -134,7 +136,7 @@ context "with a successful response" do before do - allow(DQT::Client::ReadTRNRequest).to receive(:call).and_return( + allow(TRS::Client::ReadTRNRequest).to receive(:call).and_return( { potential_duplicate: false, trn: "abcdef", @@ -165,13 +167,13 @@ end it "doesn't queue another job" do - expect { perform }.not_to have_enqueued_job(described_class) + expect { perform }.not_to have_enqueued_job(UpdateTRSTRNRequestJob) end end context "with a failure response" do before do - allow(DQT::Client::ReadTRNRequest).to receive(:call).and_raise( + allow(TRS::Client::ReadTRNRequest).to receive(:call).and_raise( Faraday::BadRequestError.new(StandardError.new), ) end @@ -209,7 +211,7 @@ context "with a potential duplicate response" do before do - allow(DQT::Client::ReadTRNRequest).to receive(:call).and_return( + allow(TRS::Client::ReadTRNRequest).to receive(:call).and_return( { potential_duplicate: true }, ) end @@ -240,7 +242,9 @@ end it "queues another job" do - expect { perform }.to have_enqueued_job(described_class) + expect { perform }.to have_enqueued_job(UpdateTRSTRNRequestJob).with( + dqt_trn_request, + ) end end end @@ -272,7 +276,7 @@ end it "doesn't queue another job" do - expect { perform }.not_to have_enqueued_job(described_class) + expect { perform }.not_to have_enqueued_job(UpdateTRSTRNRequestJob) end end end diff --git a/spec/jobs/update_trs_match_job_spec.rb b/spec/jobs/update_trs_match_job_spec.rb new file mode 100644 index 0000000000..44f05fab91 --- /dev/null +++ b/spec/jobs/update_trs_match_job_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe UpdateTRSMatchJob do + describe "#perform" do + subject(:perform) { described_class.new.perform(application_form) } + + let(:application_form) do + create(:application_form, :submitted, :with_personal_information) + end + + before { allow(TRS::Client::FindTeachers).to receive(:call).and_return([]) } + + it "searches TRS for teachers" do + expect(TRS::Client::FindTeachers).to receive(:call).with( + application_form:, + ) + + expect(TRS::Client::FindTeachers).to receive(:call).with( + application_form:, + reverse_name: true, + ) + + perform + end + + it "does not update the application form if no results are returned" do + expect { perform }.to change(application_form, :dqt_match).to( + { "teachers" => [] }, + ) + end + + it "updates the application form with the TRN" do + results = [ + { + "date_of_birth" => application_form.date_of_birth.iso8601.to_s, + "first_name" => "Jane", + "last_name" => "Smith", + "trn" => "1234567", + }, + { + "date_of_birth" => "1980-01-01", + "first_name" => "Janet", + "last_name" => "Jones", + "trn" => "7654321", + }, + ] + + allow(TRS::Client::FindTeachers).to receive(:call).with( + application_form:, + ).and_return(results) + + expect { perform }.to change(application_form, :dqt_match).to( + { "teachers" => results }, + ) + end + + context "when draft" do + let(:application_form) { create(:application_form, :draft) } + + it "doesn't search DQT for teachers" do + expect(TRS::Client::FindTeachers).not_to receive(:call) + + perform + end + end + + context "when completed" do + let(:application_form) { create(:application_form, :awarded) } + + it "doesn't search DQT for teachers" do + expect(TRS::Client::FindTeachers).not_to receive(:call) + + perform + end + end + end +end diff --git a/spec/jobs/update_trstrn_request_job_spec.rb b/spec/jobs/update_trstrn_request_job_spec.rb new file mode 100644 index 0000000000..722052df2f --- /dev/null +++ b/spec/jobs/update_trstrn_request_job_spec.rb @@ -0,0 +1,283 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe UpdateTRSTRNRequestJob, type: :job do + describe "#perform" do + subject(:perform) { described_class.new.perform(dqt_trn_request) } + + let(:application_form) { dqt_trn_request.application_form } + let(:teacher) { application_form.teacher } + + # rubocop:disable Lint/SuppressedException + let(:perform_rescue_exception) do + perform + rescue StandardError + end + # rubocop:enable Lint/SuppressedException + + context "with an initial request" do + let(:dqt_trn_request) { create(:dqt_trn_request, :initial) } + + context "with a successful response" do + before do + allow(TRS::Client::CreateTRNRequest).to receive(:call).and_return( + { + potential_duplicate: false, + trn: "abcdef", + access_your_teaching_qualifications_link: "https://aytq.com", + }, + ) + end + + it "marks the request as complete" do + expect { perform }.to change(dqt_trn_request, :complete?).to(true) + end + + it "sets potential duplicate" do + expect { perform }.to change( + dqt_trn_request, + :potential_duplicate, + ).to(false) + end + + it "awards QTS" do + expect(AwardQTS).to receive(:call).with( + application_form:, + user: "DQT", + trn: "abcdef", + access_your_teaching_qualifications_url: "https://aytq.com", + ) + perform + end + + it "doesn't queue another job" do + expect { perform }.not_to have_enqueued_job(described_class) + end + end + + context "with a failure response" do + before do + allow(TRS::Client::CreateTRNRequest).to receive(:call).and_raise( + Faraday::BadRequestError.new(StandardError.new), + ) + end + + it "leaves the request as initial" do + expect { perform_rescue_exception }.not_to change( + dqt_trn_request, + :state, + ) + end + + it "leaves the potential duplicate" do + expect { perform_rescue_exception }.not_to change( + dqt_trn_request, + :potential_duplicate, + ) + end + + it "doesn't award QTS" do + expect(AwardQTS).not_to receive(:call) + perform_rescue_exception + end + + it "doesn't change the stage" do + expect { perform_rescue_exception }.not_to change( + application_form, + :stage, + ) + end + + it "raises the error" do + expect { perform }.to raise_error(Faraday::BadRequestError) + end + end + + context "with a potential duplicate response" do + before do + allow(TRS::Client::CreateTRNRequest).to receive(:call).and_return( + { potential_duplicate: true }, + ) + end + + it "marks the request as pending" do + expect { perform }.to change(dqt_trn_request, :pending?).to(true) + end + + it "sets potential duplicate" do + expect { perform }.to change( + dqt_trn_request, + :potential_duplicate, + ).to(true) + end + + it "doesn't award QTS" do + expect(AwardQTS).not_to receive(:call) + perform + end + + it "changes the state" do + expect { perform }.to change(application_form, :statuses).to( + %w[potential_duplicate_in_dqt], + ) + end + + it "queues another job" do + expect { perform }.to have_enqueued_job(described_class).with( + dqt_trn_request, + ) + end + end + end + + context "with a pending request" do + let(:dqt_trn_request) { create(:dqt_trn_request, :pending) } + + context "with a successful response" do + before do + allow(TRS::Client::ReadTRNRequest).to receive(:call).and_return( + { + potential_duplicate: false, + trn: "abcdef", + access_your_teaching_qualifications_link: "https://aytq.com", + }, + ) + end + + it "marks the request as complete" do + expect { perform }.to change(dqt_trn_request, :complete?).to(true) + end + + it "sets potential duplicate" do + expect { perform }.to change( + dqt_trn_request, + :potential_duplicate, + ).to(false) + end + + it "awards QTS" do + expect(AwardQTS).to receive(:call).with( + application_form:, + user: "DQT", + trn: "abcdef", + access_your_teaching_qualifications_url: "https://aytq.com", + ) + perform + end + + it "doesn't queue another job" do + expect { perform }.not_to have_enqueued_job(described_class) + end + end + + context "with a failure response" do + before do + allow(TRS::Client::ReadTRNRequest).to receive(:call).and_raise( + Faraday::BadRequestError.new(StandardError.new), + ) + end + + it "leaves the request as pending" do + expect { perform_rescue_exception }.not_to change( + dqt_trn_request, + :state, + ) + end + + it "leaves the potential duplicate" do + expect { perform_rescue_exception }.not_to change( + dqt_trn_request, + :potential_duplicate, + ) + end + + it "doesn't award QTS" do + expect(AwardQTS).not_to receive(:call) + perform_rescue_exception + end + + it "doesn't change the stage" do + expect { perform_rescue_exception }.not_to change( + application_form, + :stage, + ) + end + + it "raises the error" do + expect { perform }.to raise_error(Faraday::BadRequestError) + end + end + + context "with a potential duplicate response" do + before do + allow(TRS::Client::ReadTRNRequest).to receive(:call).and_return( + { potential_duplicate: true }, + ) + end + + it "leaves the request as pending" do + expect { perform_rescue_exception }.not_to change( + dqt_trn_request, + :state, + ) + end + + it "sets potential duplicate" do + expect { perform }.to change( + dqt_trn_request, + :potential_duplicate, + ).to(true) + end + + it "doesn't award QTS" do + expect(AwardQTS).not_to receive(:call) + perform + end + + it "changes the state" do + expect { perform }.to change(application_form, :statuses).to( + %w[potential_duplicate_in_dqt], + ) + end + + it "queues another job" do + expect { perform }.to have_enqueued_job(described_class).with( + dqt_trn_request, + ) + end + end + end + + context "with a complete request" do + let(:dqt_trn_request) { create(:dqt_trn_request, :complete) } + + it "leaves the request as pending" do + expect { perform_rescue_exception }.not_to change( + dqt_trn_request, + :state, + ) + end + + it "leaves the potential duplicate" do + expect { perform_rescue_exception }.not_to change( + dqt_trn_request, + :potential_duplicate, + ) + end + + it "doesn't award QTS" do + expect(AwardQTS).not_to receive(:call) + perform + end + + it "doesn't change the stage" do + expect { perform }.not_to change(application_form, :stage) + end + + it "doesn't queue another job" do + expect { perform }.not_to have_enqueued_job(described_class) + end + end + end +end diff --git a/spec/lib/dqt/client/create_trn_request_spec.rb b/spec/lib/trs/client/create_trn_request_spec.rb similarity index 94% rename from spec/lib/dqt/client/create_trn_request_spec.rb rename to spec/lib/trs/client/create_trn_request_spec.rb index 3b94b2ca0b..f7afc090e4 100644 --- a/spec/lib/dqt/client/create_trn_request_spec.rb +++ b/spec/lib/trs/client/create_trn_request_spec.rb @@ -2,14 +2,14 @@ require "rails_helper" -RSpec.describe DQT::Client::CreateTRNRequest do +RSpec.describe TRS::Client::CreateTRNRequest do subject(:call) { described_class.call(request_id:, application_form:) } let(:request_id) { "request-id" } let(:application_form) { create(:application_form) } before do - allow(DQT::TRNRequestParams).to receive(:call).with( + allow(TRS::TRNRequestParams).to receive(:call).with( application_form:, ).and_return("body") end diff --git a/spec/lib/dqt/client/find_teachers_spec.rb b/spec/lib/trs/client/find_teachers_spec.rb similarity index 97% rename from spec/lib/dqt/client/find_teachers_spec.rb rename to spec/lib/trs/client/find_teachers_spec.rb index 253afc6ef5..c5c3921dab 100644 --- a/spec/lib/dqt/client/find_teachers_spec.rb +++ b/spec/lib/trs/client/find_teachers_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe DQT::Client::FindTeachers do +RSpec.describe TRS::Client::FindTeachers do subject(:call) { described_class.call(application_form:) } let(:application_form) do diff --git a/spec/lib/dqt/client/read_trn_request_spec.rb b/spec/lib/trs/client/read_trn_request_spec.rb similarity index 97% rename from spec/lib/dqt/client/read_trn_request_spec.rb rename to spec/lib/trs/client/read_trn_request_spec.rb index 2c8d5ea8b5..6cf2d04279 100644 --- a/spec/lib/dqt/client/read_trn_request_spec.rb +++ b/spec/lib/trs/client/read_trn_request_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe DQT::Client::ReadTRNRequest do +RSpec.describe TRS::Client::ReadTRNRequest do subject(:call) { described_class.call(request_id:) } let(:request_id) { "request-id" } diff --git a/spec/lib/dqt/country_code_spec.rb b/spec/lib/trs/country_code_spec.rb similarity index 97% rename from spec/lib/dqt/country_code_spec.rb rename to spec/lib/trs/country_code_spec.rb index f31077b378..ee3ecdfdc1 100644 --- a/spec/lib/dqt/country_code_spec.rb +++ b/spec/lib/trs/country_code_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe DQT::CountryCode do +RSpec.describe TRS::CountryCode do describe "#for_code" do subject(:dqt_code) { described_class.for_code(code) } diff --git a/spec/lib/dqt/find_teachers_params_spec.rb b/spec/lib/trs/find_teachers_params_spec.rb similarity index 95% rename from spec/lib/dqt/find_teachers_params_spec.rb rename to spec/lib/trs/find_teachers_params_spec.rb index a28d269989..162816ef01 100644 --- a/spec/lib/dqt/find_teachers_params_spec.rb +++ b/spec/lib/trs/find_teachers_params_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe DQT::FindTeachersParams do +RSpec.describe TRS::FindTeachersParams do describe "#call" do subject(:call) { described_class.call(application_form:, reverse_name:) } diff --git a/spec/lib/dqt/recognition_route_spec.rb b/spec/lib/trs/recognition_route_spec.rb similarity index 97% rename from spec/lib/dqt/recognition_route_spec.rb rename to spec/lib/trs/recognition_route_spec.rb index 8b9ea9902f..da3993753c 100644 --- a/spec/lib/dqt/recognition_route_spec.rb +++ b/spec/lib/trs/recognition_route_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe DQT::RecognitionRoute do +RSpec.describe TRS::RecognitionRoute do describe "#for_code" do subject(:recognition_route) do described_class.for_country_code(country_code, under_old_regulations:) diff --git a/spec/lib/dqt/subject_spec.rb b/spec/lib/trs/subject_spec.rb similarity index 91% rename from spec/lib/dqt/subject_spec.rb rename to spec/lib/trs/subject_spec.rb index 6d3f1df090..2f98a9df96 100644 --- a/spec/lib/dqt/subject_spec.rb +++ b/spec/lib/trs/subject_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe DQT::Subject do +RSpec.describe TRS::Subject do describe "#for" do subject(:dqt_code) { described_class.for(value) } diff --git a/spec/lib/dqt/trn_request_params_spec.rb b/spec/lib/trs/trn_request_params_spec.rb similarity index 98% rename from spec/lib/dqt/trn_request_params_spec.rb rename to spec/lib/trs/trn_request_params_spec.rb index b00b71eb5f..a43f6e767b 100644 --- a/spec/lib/dqt/trn_request_params_spec.rb +++ b/spec/lib/trs/trn_request_params_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe DQT::TRNRequestParams do +RSpec.describe TRS::TRNRequestParams do describe "#call" do subject(:call) { described_class.call(application_form:) } diff --git a/spec/services/create_dqttrn_request_spec.rb b/spec/services/create_trstrn_request_spec.rb similarity index 84% rename from spec/services/create_dqttrn_request_spec.rb rename to spec/services/create_trstrn_request_spec.rb index 0cb8a41c78..62f3bfc482 100644 --- a/spec/services/create_dqttrn_request_spec.rb +++ b/spec/services/create_trstrn_request_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe CreateDQTTRNRequest do +RSpec.describe CreateTRSTRNRequest do subject(:call) { described_class.call(application_form:, user:) } let(:application_form) { create(:application_form, :submitted) } @@ -19,7 +19,7 @@ end it "schedules an update job" do - expect { call }.to have_enqueued_job(UpdateDQTTRNRequestJob).with( + expect { call }.to have_enqueued_job(UpdateTRSTRNRequestJob).with( DQTTRNRequest.first, ) end diff --git a/spec/services/submit_application_form_spec.rb b/spec/services/submit_application_form_spec.rb index d9e8106de6..8a96c82a24 100644 --- a/spec/services/submit_application_form_spec.rb +++ b/spec/services/submit_application_form_spec.rb @@ -334,7 +334,7 @@ describe "finding matches in DQT" do it "calls a background job to find matching DQT records" do - expect { call }.to have_enqueued_job(UpdateDQTMatchJob).with( + expect { call }.to have_enqueued_job(UpdateTRSMatchJob).with( application_form, ) end diff --git a/spec/system/teacher_interface/submitting_spec.rb b/spec/system/teacher_interface/submitting_spec.rb index 4867fd479d..950c5b7f2d 100644 --- a/spec/system/teacher_interface/submitting_spec.rb +++ b/spec/system/teacher_interface/submitting_spec.rb @@ -118,7 +118,7 @@ def when_i_click_check_your_answers end def when_i_confirm_i_have_no_sanctions - allow_any_instance_of(UpdateDQTMatchJob).to receive(:perform) + allow_any_instance_of(UpdateTRSMatchJob).to receive(:perform) teacher_check_your_answers_page .submission_declaration diff --git a/terraform/application/config/development/variables.yml b/terraform/application/config/development/variables.yml index 476e614075..946a78095f 100644 --- a/terraform/application/config/development/variables.yml +++ b/terraform/application/config/development/variables.yml @@ -1,2 +1,2 @@ --- -DQT_API_URL: https://dev.teacher-qualifications-api.education.gov.uk +TRS_API_URL: https://dev.teacher-qualifications-api.education.gov.uk diff --git a/terraform/application/config/preproduction/variables.yml b/terraform/application/config/preproduction/variables.yml index 3d82e5c932..48ec9f3879 100644 --- a/terraform/application/config/preproduction/variables.yml +++ b/terraform/application/config/preproduction/variables.yml @@ -1,2 +1,2 @@ --- -DQT_API_URL: https://preprod.teacher-qualifications-api.education.gov.uk +TRS_API_URL: https://preprod.teacher-qualifications-api.education.gov.uk diff --git a/terraform/application/config/production/variables.yml b/terraform/application/config/production/variables.yml index 70d322b238..1d93b6a2b1 100644 --- a/terraform/application/config/production/variables.yml +++ b/terraform/application/config/production/variables.yml @@ -1,2 +1,2 @@ --- -DQT_API_URL: https://teacher-qualifications-api.education.gov.uk +TRS_API_URL: https://teacher-qualifications-api.education.gov.uk diff --git a/terraform/application/config/review/variables.yml b/terraform/application/config/review/variables.yml index 95254f4db8..e6b4187cdf 100644 --- a/terraform/application/config/review/variables.yml +++ b/terraform/application/config/review/variables.yml @@ -1,3 +1,3 @@ --- -DQT_API_URL: https://dev.teacher-qualifications-api.education.gov.uk +TRS_API_URL: https://dev.teacher-qualifications-api.education.gov.uk BIGQUERY_DISABLE: true diff --git a/terraform/application/config/test/variables.yml b/terraform/application/config/test/variables.yml index 4101997984..96372544a0 100644 --- a/terraform/application/config/test/variables.yml +++ b/terraform/application/config/test/variables.yml @@ -1,2 +1,2 @@ --- -DQT_API_URL: https://test.teacher-qualifications-api.education.gov.uk +TRS_API_URL: https://test.teacher-qualifications-api.education.gov.uk