Skip to content

Commit 9daaccb

Browse files
author
adambasha0
committed
fix: refactor import & export chemical spec tests and fix robocup warnings
1 parent 5b90ba5 commit 9daaccb

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

lib/export/export_chemicals.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module Export
44
class ExportChemicals
55
CHEMICAL_FIELDS = %w[
66
chemical_sample_id cas status vendor order_number amount volume price person required_date
7-
ordered_date storage_temperature expiration_date required_by pictograms h_statements p_statements safety_sheet_link_merck
8-
safety_sheet_link_thermofischer product_link_merck product_link_thermofischer
7+
ordered_date storage_temperature expiration_date required_by pictograms h_statements p_statements
8+
safety_sheet_link_merck safety_sheet_link_thermofischer product_link_merck product_link_thermofischer
99
host_building host_room host_cabinet host_group owner borrowed_by current_building
1010
current_room current_cabinet current_group disposal_info important_notes
1111
].freeze
@@ -70,8 +70,9 @@ def self.format_chemical_results(result)
7070
end
7171

7272
def self.construct_column_name(column_name, index, columns_index)
73-
format_chemical_column = ['p statements', 'h statements', 'amount', 'volume', 'storage temperature', 'safety sheet link thermofischer',
74-
'safety sheet link merck', 'product link thermofischer', 'product link merck'].freeze
73+
format_chemical_column = ['p statements', 'h statements', 'amount', 'volume', 'storage temperature',
74+
'safety sheet link thermofischer', 'safety sheet link merck', 'product link thermofischer',
75+
'product link merck'].freeze
7576
if column_name.is_a?(String) && CHEMICAL_FIELDS.include?(column_name)
7677
column_name = column_name.tr('_', ' ')
7778
construct_column_name_hash(columns_index, column_name, index) if format_chemical_column.include?(column_name)
@@ -116,7 +117,7 @@ def self.format_row(row, columns_index, indexes_to_delete)
116117
when columns_index['p_statements'], columns_index['h_statements']
117118
value = format_p_and_h_statements(value)
118119
when columns_index['amount'], columns_index['volume'], columns_index['storage_temperature']
119-
value = format_chemical_amount_or_volume(value)
120+
value = format_chemical_fields(value)
120121
when columns_index['safety_sheet_link'][0]
121122
value = format_link(value, row, columns_index['safety_sheet_link'][1], indexes_to_delete)
122123
when columns_index['product_link'][0]
@@ -131,7 +132,7 @@ def self.format_p_and_h_statements(value)
131132
keys.join('-')
132133
end
133134

134-
def self.format_chemical_amount_or_volume(value)
135+
def self.format_chemical_fields(value)
135136
value_unit = JSON.parse(value).values
136137
sorted = value_unit.sort_by { |element| [element.is_a?(Integer) || element.is_a?(Float) ? 0 : 1, element] }
137138
sorted.join(' ')

spec/lib/export/export_chemicals_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
# rubocop: disable Style/OpenStructUse
66

77
describe Export::ExportChemicals do
8-
describe '.format_chemical_amount_or_volume' do
8+
describe '.format_chemical_fields' do
99
it 'formats chemical amount correctly' do
1010
input_value = '{"value": 50, "unit": "mg"}'
11-
formatted_amount = described_class.format_chemical_amount_or_volume(input_value)
11+
formatted_amount = described_class.format_chemical_fields(input_value)
1212
expect(formatted_amount).to eq('50 mg')
1313
end
1414

1515
it 'formats chemical storage temperature correctly' do
1616
input_value = '{"value": 30, "unit": "°C"}'
17-
formatted_amount = described_class.format_chemical_fields_with_unit(input_value)
18-
expect(formatted_amount).to eq('30°C')
17+
formatted_amount = described_class.format_chemical_fields(input_value)
18+
expect(formatted_amount).to eq('30 °C')
1919
end
2020
end
2121

spec/lib/import/import_chemicals_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
let(:chemical) { { 'chemical_data' => [{}] } }
4848

4949
it 'add amount value and unit' do
50-
described_class.set_chemical_amount_or_volume(chemical, 'amount', '10 mg')
50+
described_class.set_amount_or_volume(chemical, 'amount', '10 mg')
5151
expect(chemical['chemical_data'][0]['amount']['value']).to eq(10.0)
5252
expect(chemical['chemical_data'][0]['amount']['unit']).to eq('mg')
5353
end
5454

5555
it 'add volume value and unit' do
56-
described_class.set_chemical_amount_or_volume(chemical, 'volume', '6.4 ml')
56+
described_class.set_amount_or_volume(chemical, 'volume', '6.4 ml')
5757
expect(chemical['chemical_data'][0]['volume']['value']).to eq(6.4)
5858
expect(chemical['chemical_data'][0]['volume']['unit']).to eq('ml')
5959
end

0 commit comments

Comments
 (0)