Skip to content

Commit

Permalink
Add test for finding segment klasses by ontology
Browse files Browse the repository at this point in the history
  • Loading branch information
beque committed Apr 12, 2024
1 parent e6d298b commit de51b5c
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 2 deletions.
39 changes: 38 additions & 1 deletion spec/api/chemotion/device_description_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

let(:user) { create(:user) }
let(:collection) { create(:collection, user_id: user.id, devicedescription_detail_level: 10) }
let(:device_description) { create(:device_description, collection_id: collection.id, created_by: collection.user_id) }
let(:device_description) do
create(:device_description, :with_ontologies, collection_id: collection.id, created_by: collection.user_id)
end
let(:segment_klass) { create(:segment_klass, :with_ontology_properties_template) }

describe 'GET /api/v1/device_descriptions/' do
before do
Expand Down Expand Up @@ -45,6 +48,40 @@
end
end

describe 'PUT /api/v1/device_descriptions/byontology/:id' do
before do
segment_klass
end

context 'when selecting an ontology' do
let(:params) do
{
id: device_description.id,
ontology: device_description.ontologies.first,
}
end

let(:params2) do
{
id: device_description.id,
ontology: device_description.ontologies.last,
}
end

it 'returns segment klass id' do
put "/api/v1/device_descriptions/byontology/#{device_description.id}", params: params

expect(parsed_json_response).to eql([{ 'segment_klass_id' => segment_klass.id }])
end

it 'returns empty array' do
put "/api/v1/device_descriptions/byontology/#{device_description.id}", params: params2

expect(parsed_json_response).to eql([])
end
end
end

describe 'PUT /api/v1/device_descriptions/:id' do
context 'when updating an device description' do
let(:params) do
Expand Down
84 changes: 83 additions & 1 deletion spec/factories/device_descriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,93 @@
FactoryBot.define do
factory :device_description do
sequence(:name) { |i| "Device description #{i}" }
sequence(:short_label) { |i| "CU1-DD#{i}" }
sequence(:short_label) { |i| "CU1-Dev#{i}" }
serial_number { '123abc456def' }
collection_id { 1 }
created_by { 1 }

trait :with_ontologies do
ontologies do
[
{
'data' => {
'id' => 'chmo:class:http://purl.obolibrary.org/obo/CHMO_0002231',
'iri' => 'http://purl.obolibrary.org/obo/CHMO_0002231',
'type' => 'class',
'label' => 'purification',
'obo_id' => 'CHMO:0002231',
'short_form' => 'CHMO_0002231',
'description' => [
'Any technique used to physically separate an analyte from byproducts,
reagents or contaminating substances.',
],
'ontology_name' => 'chmo',
'ontology_prefix' => 'CHMO',
},
'paths' => [
{
'iri' => 'http://purl.obolibrary.org/obo/OBI_0000094',
'label' => 'material processing',
'short_form' => 'OBI_0000094',
},
{
'iri' => 'http://purl.obolibrary.org/obo/CHMO_0000999',
'label' => 'separation method',
'short_form' => 'CHMO_0000999',
},
{
'iri' => 'http://purl.obolibrary.org/obo/CHMO_0002231',
'label' => 'purification',
'short_form' => 'CHMO_0002231',
},
],
},
{
'data' => {
'id' => 'chmo:class:http://purl.obolibrary.org/obo/CHMO_0002413',
'iri' => 'http://purl.obolibrary.org/obo/CHMO_0002413',
'type' => 'class',
'label' => 'cryogenic electron microscopy',
'obo_id' => 'CHMO:0002413',
'short_form' => 'CHMO_0002413',
'description' => [
'Microscopy where the specimen, which is cooled in liquid ethane to 180 °C',
],
'ontology_name' => 'chmo',
'ontology_prefix' => 'CHMO',
},
'paths' => [
{
'iri' => 'http://purl.obolibrary.org/obo/OBI_0000070',
'label' => 'assay',
'short_form' => 'OBI_0000070',
},
{
'iri' => 'http://purl.obolibrary.org/obo/OBI_0000185',
'label' => 'imaging assay',
'short_form' => 'OBI_0000185',
},
{
'iri' => 'http://purl.obolibrary.org/obo/CHMO_0000067',
'label' => 'microscopy',
'short_form' => 'CHMO_0000067',
},
{
'iri' => 'http://purl.obolibrary.org/obo/CHMO_0000068',
'label' => 'electron microscopy',
'short_form' => 'CHMO_0000068',
},
{
'iri' => 'http://purl.obolibrary.org/obo/CHMO_0002413',
'label' => 'cryogenic electron microscopy',
'short_form' => 'CHMO_0002413',
},
],
},
]
end
end

callback(:before_create) do |device_description|
device_description.created_by = FactoryBot.build(:user) unless device_description.created_by
device_description.collections << FactoryBot.build(:collection, user_id: device_description.created_by)
Expand Down
64 changes: 64 additions & 0 deletions spec/factories/setment_klasses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,69 @@
factory :segment_klass, class: 'Labimotion::SegmentKlass' do
label { 'segment' }
element_klass { FactoryBot.build(:element_klass) }

trait :with_ontology_properties_template do
properties_template do
{
'pkg' => {
'eln' => { 'version' => '1.9.0', 'base_revision' => 'a714b63f6', 'current_revision' => 0 },
'name' => 'chem-generic-ui',
'version' => '1.1.1',
'labimotion' => '1.1.4',
},
'uuid' => '1e3aa4fa-bbb1-468a-aab3-505c14bdca12',
'klass' => 'SegmentKlass',
'layers' => {
'fields' => {
'wf' => false,
'key' => 'fields',
'cols' => 2,
'color' => 'info',
'label' => 'Fields',
'style' => 'panel_generic_heading',
'fields' => [
{
'type' => 'text',
'field' => 'material',
'label' => 'material',
'default' => '',
'ontology' => {
'id' => 'obi:class:http://purl.obolibrary.org/obo/OBI_0000094',
'iri' => 'http://purl.obolibrary.org/obo/OBI_0000094',
'type' => 'class',
'label' => 'material processing',
'obo_id' => 'OBI:0000094',
'short_form' => 'OBI_0000094',
'description' => [
'A planned process which results in physical changes in a specified input material',
],
'ontology_name' => 'obi',
'ontology_prefix' => 'OBI',
},
'position' => 1,
'sub_fields' => [],
'text_sub_fields' => [],
},
{
'type' => 'text',
'field' => 'weight',
'label' => 'weight',
'default' => '',
'position' => 2,
'sub_fields' => [],
'text_sub_fields' => [],
},
],
'position' => 10,
'timeRecord' => '',
'wf_position' => 0,
},
},
'version' => '2.0',
'identifier' => '',
'select_options' => {},
}
end
end
end
end

0 comments on commit de51b5c

Please sign in to comment.