Commit aa8067bd authored by Mikolaj Wawrzyniak's avatar Mikolaj Wawrzyniak

Add .id method to PrometheusPanel class

parent d6423b73
......@@ -4,7 +4,7 @@ module PerformanceMonitoring
class PrometheusPanel
include ActiveModel::Model
attr_accessor :type, :title, :y_label, :weight, :metrics
attr_accessor :type, :title, :y_label, :weight, :metrics, :y_axis
validates :title, presence: true
validates :metrics, presence: true
......@@ -20,5 +20,9 @@ module PerformanceMonitoring
panel.tap(&:validate!)
end
def id(group_title)
Digest::SHA2.hexdigest([group_title, type, title].join)
end
end
end
......@@ -18,6 +18,16 @@ describe PerformanceMonitoring::PrometheusPanel do
}
end
describe '#new' do
it 'accepts old schema format' do
expect { described_class.new(json_content) }.not_to raise_error
end
it 'accepts new schema format' do
expect { described_class.new(json_content.merge("y_axis" => { "precision" => 0 })) }.not_to raise_error
end
end
describe '.from_json' do
subject { described_class.from_json(json_content) }
......@@ -52,4 +62,15 @@ describe PerformanceMonitoring::PrometheusPanel do
end
end
end
describe '.id' do
it 'returns hexdigest of group_title, type and title as the panel id' do
group_title = 'Business Group'
panel_type = 'area-chart'
panel_title = 'New feature requests made'
expect(Digest::SHA2).to receive(:hexdigest).with("#{group_title}#{panel_type}#{panel_title}").and_return('hexdigest')
expect(described_class.new(title: panel_title, type: panel_type).id(group_title)).to eql 'hexdigest'
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment