fix and add specs

This commit is contained in:
Karol
2022-08-31 20:51:58 +02:00
parent 76c9dfa4e5
commit 5ace779d0c
8 changed files with 104 additions and 47 deletions

View File

@ -42,25 +42,25 @@ describe ExerciseService::CheckExternal do
end
context 'when response contains a JSON with expected keys' do
let(:response) { {task_found: true, update_right: true}.to_json }
let(:response) { {uuid_found: true, update_right: true}.to_json }
it 'returns the correct hash' do
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.task_found'), task_found: true, update_right: true)
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.task_found'), uuid_found: true, update_right: true)
end
context 'with task_found: false and no update_right' do
let(:response) { {task_found: false}.to_json }
context 'with uuid_found: false and no update_right' do
let(:response) { {uuid_found: false}.to_json }
it 'returns the correct hash' do
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.no_task'), task_found: false)
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.no_task'), uuid_found: false)
end
end
context 'with task_found: true and update_right: false' do
let(:response) { {task_found: true, update_right: false}.to_json }
context 'with uuid_found: true and update_right: false' do
let(:response) { {uuid_found: true, update_right: false}.to_json }
it 'returns the correct hash' do
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.task_found_no_right'), task_found: true, update_right: false)
expect(check_external_service).to eql(error: false, message: I18n.t('exercises.export_codeharbor.check.task_found_no_right'), uuid_found: true, update_right: false)
end
end
end

View File

@ -39,7 +39,13 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
language: described_class::DEFAULT_LANGUAGE,
meta_data: {
CodeOcean: {
instructions: exercise.instructions,
allow_auto_completion: exercise.allow_auto_completion,
allow_file_creation: exercise.allow_file_creation,
execution_environment_id: exercise.execution_environment_id,
expected_difficulty: exercise.expected_difficulty,
hide_file_tree: exercise.hide_file_tree,
public: exercise.public,
files: {},
},
},
# parent_uuid: exercise.clone_relations.first&.origin&.uuid,
@ -62,7 +68,15 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
usage_by_lms: 'edit',
visible: 'yes',
binary: false,
internal_description: 'main_file'
internal_description: nil
)
end
it 'adds the file\'s role to the file hash in task-meta_data' do
expect(task).to have_attributes(
meta_data: {
CodeOcean: a_hash_including(files: {"CO-#{file.id}" => {role: 'main_file'}}),
}
)
end
end
@ -82,7 +96,15 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
usage_by_lms: 'display',
visible: 'no',
binary: false,
internal_description: 'regular_file'
internal_description: nil
)
end
it 'adds the file\'s role to the file hash in task-meta_data' do
expect(task).to have_attributes(
meta_data: {
CodeOcean: a_hash_including(files: {"CO-#{file.id}" => {role: 'regular_file'}}),
}
)
end
@ -139,7 +161,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
usage_by_lms: 'display',
visible: 'yes',
binary: false,
internal_description: 'reference_implementation'
internal_description: nil
)
end
end
@ -168,8 +190,8 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
files: have(1).item,
meta_data: {
CodeOcean: {
'entry-point': test_file.filepath,
'feedback-message': 'feedback_message',
weight: test_file.weight,
},
}
)
@ -183,7 +205,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
used_by_grader: true,
visible: 'no',
binary: false,
internal_description: 'teacher_defined_test'
internal_description: nil
)
end

View File

@ -38,32 +38,54 @@ describe ProformaService::ConvertTaskToExercise do
uuid: 'uuid',
parent_uuid: 'parent_uuid',
language: 'language',
meta_data: {
CodeOcean: {
instructions: 'instructions',
},
},
meta_data: meta_data,
model_solutions: model_solutions,
files: files,
tests: tests
)
end
let(:user) { create(:teacher) }
let(:files) { [] }
let(:tests) { [] }
let(:model_solutions) { [] }
let(:exercise) { nil }
let(:meta_data) do
{
CodeOcean: {
public: public,
hide_file_tree: hide_file_tree,
allow_file_creation: allow_file_creation,
allow_auto_completion: allow_auto_completion,
expected_difficulty: expected_difficulty,
execution_environment_id: execution_environment.id,
files: files_meta_data,
},
}
end
let(:public) { 'true' }
let(:hide_file_tree) { 'true' }
let(:allow_file_creation) { 'true' }
let(:allow_auto_completion) { 'true' }
let(:expected_difficulty) { 7 }
let!(:execution_environment) { create(:java) }
let(:files_meta_data) { {} }
it 'creates an exercise with the correct attributes' do
expect(convert_to_exercise_service).to have_attributes(
title: 'title',
description: 'description',
instructions: 'instructions',
execution_environment: be_blank,
uuid: be_blank,
unpublished: true,
user: user,
files: be_empty
files: be_empty,
public: true,
hide_file_tree: true,
allow_file_creation: true,
allow_auto_completion: true,
expected_difficulty: 7,
execution_environment_id: execution_environment.id
)
end
@ -311,8 +333,7 @@ describe ProformaService::ConvertTaskToExercise do
create(
:files,
title: 'exercise-title',
description: 'exercise-description',
instructions: 'exercise-instruction'
description: 'exercise-description'
)
end
@ -324,7 +345,6 @@ describe ProformaService::ConvertTaskToExercise do
id: exercise.id,
title: task.title,
description: task.description,
instructions: task.meta_data[:CodeOcean][:instructions],
execution_environment: exercise.execution_environment,
uuid: exercise.uuid,
user: exercise.user,