Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/jobs/salesforce/lesson_sync_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def perform(lesson_id:)
def sf_lesson_attributes(lesson:)
mapped_attributes(lesson:).merge(
teacherprojecttitle__c: lesson.project&.name,
teacherprojecttype__c: lesson.project&.project_type,
teacherprojecttype__c: project_type_attribute(lesson),
numberofassignedprojects__c: assigned_projects_count(lesson),
# Sum of the two completion paths: state-machine `:submitted` (Code Editor flow)
# and `school_projects.finished` (Experience CS flow). They are mutually exclusive
Expand All @@ -49,6 +49,12 @@ def mapped_attributes(lesson:)
end
end

def project_type_attribute(lesson)
return Project::Types::SCRATCH if lesson.project&.origin == Project::Origins::EXPERIENCE_CS

lesson.project&.project_type
end

# A lesson is "assigned" to every student in its class iff it's visible to them
# (visibility == 'students'). Other visibilities aren't assigned to students at all.
def assigned_projects_count(lesson)
Expand Down
11 changes: 11 additions & 0 deletions spec/jobs/salesforce/lesson_sync_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
end
end

context 'when the lesson project originates from Experience CS' do
Project::EXPERIENCE_CS_PROJECT_TYPES.each do |project_type|
it "syncs teacherprojecttype__c as scratch when the underlying project_type is #{project_type}" do
lesson.project.update!(origin: Project::Origins::EXPERIENCE_CS, project_type:)
perform_job
sf_lesson = Salesforce::Lesson.find_by(lesson_uuid__c: lesson.id)
expect(sf_lesson.teacherprojecttype__c).to eq(Project::Types::SCRATCH)
end
end
end

describe 'numberofassignedprojects__c' do
let(:students) { Array.new(3) { create(:student, school:) } }

Expand Down
Loading