Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed Mar 6, 2025
1 parent f72d018 commit eab0c09
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/services/teacher_training_public_api/sync_courses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion spec/examples/teacher_training_api/course_list_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"subject_codes": [
{
}
]
],
"visa_sponsorship_application_deadline_at": "2020-06-13T10:44:31Z"
},
"relationships": {
"recruitment_cycle": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
25 changes: 24 additions & 1 deletion spec/services/teacher_training_public_api/sync_courses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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' }

Expand Down

0 comments on commit eab0c09

Please sign in to comment.