add default values to meta_data

fix specs
This commit is contained in:
Karol
2022-09-26 20:46:40 +02:00
parent b866221353
commit d6cd06550d
3 changed files with 68 additions and 27 deletions

View File

@ -21,11 +21,11 @@ module ProformaService
user: @user,
title: @task.title,
description: @task.description,
public: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:public)),
hide_file_tree: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:hide_file_tree)),
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)),
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)),
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty),
public: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:public)) || false,
hide_file_tree: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:hide_file_tree)) || false,
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)) || false,
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)) || false,
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty) || 1,
execution_environment_id: execution_environment_id,
files: files

View File

@ -49,6 +49,34 @@ describe ProformaService::ConvertTaskToExercise do
let(:model_solutions) { [] }
let(:exercise) { nil }
let(:meta_data) { {} }
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) }
it 'creates an exercise with the correct attributes' do
expect(convert_to_exercise_service).to have_attributes(
title: 'title',
description: 'description',
uuid: be_blank,
unpublished: true,
user: user,
files: be_empty,
public: false,
hide_file_tree: false,
allow_file_creation: false,
allow_auto_completion: false,
expected_difficulty: 1,
execution_environment_id: nil
)
end
it { is_expected.to be_valid }
context 'when meta_data is set' do
let(:meta_data) do
{
CodeOcean: {
@ -62,12 +90,6 @@ describe ProformaService::ConvertTaskToExercise do
},
}
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
@ -86,6 +108,7 @@ describe ProformaService::ConvertTaskToExercise do
execution_environment_id: execution_environment.id
)
end
end
context 'when execution environment is not set in meta_data' do
let(:execution_environment) { nil }
@ -135,6 +158,13 @@ describe ProformaService::ConvertTaskToExercise do
end
context 'when file is a main_file' do
let(:meta_data) do
{
CodeOcean: {
files: files_meta_data,
},
}
end
let(:files_meta_data) { {"CO-#{file.id}".to_sym => {role: 'main_file'}} }
it 'creates an exercise with a file that has the correct attributes' do
@ -309,6 +339,13 @@ describe ProformaService::ConvertTaskToExercise do
end
context 'when test file is a teacher_defined_linter' do
let(:meta_data) do
{
CodeOcean: {
files: files_meta_data,
},
}
end
let(:files_meta_data) { {"CO-#{test_file.id}".to_sym => {role: 'teacher_defined_linter'}} }
it 'creates an exercise with a test' do
@ -365,8 +402,8 @@ describe ProformaService::ConvertTaskToExercise do
convert_to_exercise_service.save
expect(exercise.reload).to have_attributes(
id: exercise.id,
title: task.title,
description: task.description,
title: exercise.title,
description: exercise.description,
execution_environment: exercise.execution_environment,
uuid: exercise.uuid,
user: exercise.user,

View File

@ -29,6 +29,10 @@ describe ProformaService::Import do
instructions: 'instruction',
execution_environment: execution_environment,
files: files + tests,
hide_file_tree: true,
allow_file_creation: false,
allow_auto_completion: true,
expected_difficulty: 7,
uuid: uuid,
user: user)
end