From eab0c09fdfda331c61634fe819f1627df51adf26 Mon Sep 17 00:00:00 2001 From: Lori Bailey <44073106+elceebee@users.noreply.github.com> Date: Thu, 6 Mar 2025 15:09:07 +0000 Subject: [PATCH] wip --- .../sync_courses.rb | 1 + .../course_list_response.json | 3 ++- .../course_single_response.json | 3 ++- .../provider_list_response.json | 3 ++- .../sync_courses_spec.rb | 25 ++++++++++++++++++- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/services/teacher_training_public_api/sync_courses.rb b/app/services/teacher_training_public_api/sync_courses.rb index 73163b8a1e9..e0350565490 100644 --- a/app/services/teacher_training_public_api/sync_courses.rb +++ b/app/services/teacher_training_public_api/sync_courses.rb @@ -98,6 +98,7 @@ def assign_course_attributes(course, course_from_api, recruitment_cycle_year) subject = ::Subject.find_or_initialize_by(code:) course.subjects << subject unless course.course_subjects.exists?(subject_id: subject.id) end + course.visa_sponsorship_application_deadline_at = course_from_api.visa_sponsorship_application_deadline_at end def study_mode(course_from_api) diff --git a/spec/examples/teacher_training_api/course_list_response.json b/spec/examples/teacher_training_api/course_list_response.json index b9089ccb513..474affcfb56 100644 --- a/spec/examples/teacher_training_api/course_list_response.json +++ b/spec/examples/teacher_training_api/course_list_response.json @@ -70,7 +70,8 @@ "state": "published", "study_mode": "both", "summary": "PGCE with QTS full time", - "subject_codes": ["00"] + "subject_codes": ["00"], + "visa_sponsorship_application_deadline_at": "2020-06-13T10:44:31Z" }, "relationships": { "recruitment_cycle": { diff --git a/spec/examples/teacher_training_api/course_single_response.json b/spec/examples/teacher_training_api/course_single_response.json index 564b47d144b..2d282152165 100644 --- a/spec/examples/teacher_training_api/course_single_response.json +++ b/spec/examples/teacher_training_api/course_single_response.json @@ -72,7 +72,8 @@ "subject_codes": [ { } - ] + ], + "visa_sponsorship_application_deadline_at": "2020-06-13T10:44:31Z" }, "relationships": { "recruitment_cycle": { diff --git a/spec/examples/teacher_training_api/provider_list_response.json b/spec/examples/teacher_training_api/provider_list_response.json index 387e03cdd7f..5f25a9b4830 100644 --- a/spec/examples/teacher_training_api/provider_list_response.json +++ b/spec/examples/teacher_training_api/provider_list_response.json @@ -105,7 +105,8 @@ "start_date": "2020-09-01", "state": "published", "study_mode": "both", - "summary": "PGCE with QTS full time" + "summary": "PGCE with QTS full time", + "visa_sponsorship_application_deadline_at": "2020-06-13T10:44:31Z" }, "relationships": { "accredited_body": { diff --git a/spec/services/teacher_training_public_api/sync_courses_spec.rb b/spec/services/teacher_training_public_api/sync_courses_spec.rb index 4d6cb442151..f7cf4348789 100644 --- a/spec/services/teacher_training_public_api/sync_courses_spec.rb +++ b/spec/services/teacher_training_public_api/sync_courses_spec.rb @@ -9,7 +9,8 @@ described_class.new.perform(provider.id, RecruitmentCycle.current_year) end - let(:stubbed_attributes) { [{ accredited_body_code: nil, state: stubbed_api_course_state }] } + let(:stubbed_attributes) { [{ accredited_body_code: nil, state: stubbed_api_course_state, visa_sponsorship_application_deadline_at: stubbed_sponsorship_application_deadline_at }] } + let(:stubbed_sponsorship_application_deadline_at) { nil } before do stub_teacher_training_api_courses(provider_code: provider.code, specified_attributes: stubbed_attributes) @@ -18,12 +19,34 @@ context 'when the API course has a published state' do let(:stubbed_api_course_state) { 'published' } + let(:stubbed_sponsorship_application_deadline_at) { nil } it 'creates the course' do expect { perform_job }.to change(provider.courses, :count) end end + context 'when the sponsorship deadline is not provided' do + let(:stubbed_api_course_state) { 'published' } + + it 'does not add visa_sponsorship_application_deadline_at value to course' do + perform_job + expect(provider.courses.where.not(visa_sponsorship_application_deadline_at: nil).count).to eq 0 + end + end + + context 'when the sponsorship deadline is provided' do + let(:stubbed_api_course_state) { 'published' } + let(:stubbed_sponsorship_application_deadline_at) { 2.days.from_now } + + it 'saves the visa_sponsorship_application_deadline_at value to course' do + perform_job + expect(provider.courses.where.not(visa_sponsorship_application_deadline_at: nil).first.visa_sponsorship_application_deadline_at) + .to be_within(1.second) + .of(stubbed_sponsorship_application_deadline_at) + end + end + context 'when the API course has a withdrawn state' do let(:stubbed_api_course_state) { 'withdrawn' }