Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Jan 8, 2025
1 parent e8787e5 commit 14764da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/seek/isa_templates/template_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def self.extract_templates(user)
current_template_attributes = []
item['data'].each_with_index do |attribute, j|
is_cv = attribute['dataType'].include? 'Controlled Vocabulary'
allow_cv_free_text = false
if is_cv
is_ontology = attribute['ontology'].present?
cv_exists = !SampleControlledVocab.find_by(title: attribute['name']).nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dataType": "String",
"required": true,
"ontology": null,
"allowCVFreeText": null,
"CVList": null,
"isaTag": "source_characteristic"
},
Expand Down Expand Up @@ -82,7 +83,7 @@
},
{
"iri": null,
"name": "New ontology",
"name": "New ontology List",
"description": "",
"dataType": "Controlled Vocabulary List",
"required": false,
Expand Down
34 changes: 32 additions & 2 deletions test/functional/templates_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ class TemplatesControllerTest < ActionController::TestCase
# 2. Source Characteristic 1 (String) => New
# 3. apples controlled (CV) vocab for template => Reuse
# 4. physics ontology (CV, ontology) => Reuse
# 5. New CV (CV) List => New
# 6. New ontology (CV, ontology) => New
# 5. New CV (CV List) List => New
# 6. New ontology List (CV List, ontology) => New
# New template attributes should be 6
# New sample controlled vocabs should be 2
####################################################################################################################
Expand All @@ -687,6 +687,36 @@ class TemplatesControllerTest < ActionController::TestCase
assert_equal registered_template.template_attributes.detect { |ta| ta.title == 'physics ontology' }.sample_controlled_vocab, physics_ontology
end

test 'should allow controlled vocab attributes to have free text in instance-wide templates' do
login_as(@admin)
####################################################################################################################
# This file contains the JSON definition for 1 template with 6 template attribute:
# 1. Source Name (Sting) => allowCVFreeText: null (not present)
# 2. Source Characteristic 1 (String) => allowCVFreeText: null
# 3. apples controlled vocab for template => allowCVFreeText: true
# 4. physics ontology (CV, ontology) => allowCVFreeText: false
# 5. New CV List (CV List) => allowCVFreeText: null => Should resolve to false
# 6. New ontology (CV List, ontology) => allowCVFreeText: null => Should resolve to false
####################################################################################################################
template_json = fixture_file_upload('upload_json_sample_type_template/test_apple_cv_template.json', 'application/json')
assert_enqueued_jobs 1, only: PopulateTemplatesJob do
post :populate_template, params: { template_json_file: template_json }
end
assert_difference('Template.count', 1) do
assert_difference('TemplateAttribute.count', 6) do
perform_enqueued_jobs(only: PopulateTemplatesJob)
end
end

registered_template = Template.last
refute registered_template.template_attributes.detect { |ta| ta.title == 'Source Name' }.allow_cv_free_text
refute registered_template.template_attributes.detect { |ta| ta.title == 'Source Characteristic 1' }.allow_cv_free_text
assert registered_template.template_attributes.detect { |ta| ta.title == 'apples controlled vocab for template' }.allow_cv_free_text
refute registered_template.template_attributes.detect { |ta| ta.title == 'physics ontology' }.allow_cv_free_text
refute registered_template.template_attributes.detect { |ta| ta.title == 'New CV List' }.allow_cv_free_text
refute registered_template.template_attributes.detect { |ta| ta.title == 'New ontology List' }.allow_cv_free_text
end

def create_template_from_parent_template(parent_template, person= @person, linked_sample_type= nil)
child_template_attributes = parent_template.template_attributes.map do |ta|
FactoryBot.create(:template_attribute, parent_attribute_id: ta.id, title: ta.title, isa_tag_id: ta.isa_tag_id, sample_attribute_type: ta.sample_attribute_type, is_title: ta.is_title, required: ta.required, sample_controlled_vocab: ta.sample_controlled_vocab, pos: ta.pos)
Expand Down

0 comments on commit 14764da

Please sign in to comment.