Skip to content
Snippets Groups Projects
Commit ffef01d3 authored by Per 29 mei 2024 gedeeld account, daarvoor marten's avatar Per 29 mei 2024 gedeeld account, daarvoor marten
Browse files

Merge branch 'mv-validate-unique-export-keys' into 'main'

Validate uniqueness of export keys

See merge request !16
parents 60b01a12 138b0b5c
Branches
Tags
1 merge request!16Validate uniqueness of export keys
Pipeline #82070 passed
...@@ -25,7 +25,6 @@ module Quby ...@@ -25,7 +25,6 @@ module Quby
validate_outcome_tables(questionnaire) validate_outcome_tables(questionnaire)
validate_markdown_fields(questionnaire) if questionnaire.validate_html validate_markdown_fields(questionnaire) if questionnaire.validate_html
validate_raw_content_items(questionnaire) if questionnaire.validate_html validate_raw_content_items(questionnaire) if questionnaire.validate_html
validate_scores(questionnaire)
# Some compilation errors are Exceptions (pure syntax errors) and some StandardErrors (NameErrors) # Some compilation errors are Exceptions (pure syntax errors) and some StandardErrors (NameErrors)
rescue Exception => exception # rubocop:disable Lint/RescueException rescue Exception => exception # rubocop:disable Lint/RescueException
definition.errors.add(:sourcecode, {message: "Questionnaire error: #{definition.key}\n" \ definition.errors.add(:sourcecode, {message: "Questionnaire error: #{definition.key}\n" \
...@@ -81,6 +80,13 @@ module Quby ...@@ -81,6 +80,13 @@ module Quby
fail "Score #{score.key} does not have a score schema" unless score_schema fail "Score #{score.key} does not have a score schema" unless score_schema
fail "Score label langer dan 100 tekens (geeft problemen oru accare)\n #{score_schema.label}" if score_schema.label&.length > 100 fail "Score label langer dan 100 tekens (geeft problemen oru accare)\n #{score_schema.label}" if score_schema.label&.length > 100
end end
export_keys = questionnaire.score_schemas.flat_map { |_key, score_schema|
score_schema.subscore_schemas.map(&:export_key)
}
duplicate_export_keys = export_keys.tally.select { |key, count| count > 1 }.keys
fail "Score export keys not unique, duplicates: #{duplicate_export_keys}" if duplicate_export_keys.present?
end end
def validate_question_options(questionnaire, question) def validate_question_options(questionnaire, question)
...@@ -241,8 +247,6 @@ scores_schema tables to the resulting seed." ...@@ -241,8 +247,6 @@ scores_schema tables to the resulting seed."
def validate_score_label_present(score) def validate_score_label_present(score)
fail "Score #{score.key} label must be passed in as an option." unless score.label.present? fail "Score #{score.key} label must be passed in as an option." unless score.label.present?
end end
def validate_subquestion_absence_in_select(question) def validate_subquestion_absence_in_select(question)
......
...@@ -821,5 +821,23 @@ module Quby::Compiler::Services ...@@ -821,5 +821,23 @@ module Quby::Compiler::Services
expect(definition.valid?).to be true expect(definition.valid?).to be true
end end
end end
describe '#validate_scores' do
it 'fails on duplicate export keys' do
definition = make_definition(<<-END)
title "Test"
score :tot, label: "Totaalscore", schema: [{:export_key=>:tot, :label=>"Score", :key=>:value}] do
{}
end
score :tot2, label: "Totaalscore", schema: [{:export_key=>:tot, :label=>"Score", :key=>:value}] do
{}
end
END
expect(definition.valid?).to be false
expect(definition.errors.full_messages.first).to \
include('Score export keys not unique, duplicates: [:tot]')
end
end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment