Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit c823d47

Browse files
committed
v3-remove service plans cost when currency not set
1 parent 9dadb73 commit c823d47

2 files changed

Lines changed: 53 additions & 7 deletions

File tree

app/presenters/v3/service_plan_presenter.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ def costs
6363
metadata[:costs].each do |cost|
6464
unit = cost[:unit].to_s
6565
cost[:amount].each do |currency, amount|
66-
cost_result << {
67-
currency: currency.to_s.upcase,
68-
amount: amount.to_f,
69-
unit: unit || ''
70-
}
66+
unless currency.empty?
67+
cost_result << {
68+
currency: currency.to_s.upcase,
69+
amount: amount.to_f,
70+
unit: unit
71+
}
72+
end
7173
end
7274
end
7375
end

spec/unit/presenters/v3/service_plan_presenter_spec.rb

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,16 @@
162162
{
163163
"amount": {
164164
"usd": 649.0,
165-
"gbp": 600.015454
165+
"gbp": 500
166166
},
167167
"unit": "MONTHLY"
168+
},
169+
{
170+
"amount": {
171+
"usd": 6.00,
172+
"gbp": 5.05
173+
},
174+
"unit": "daily"
168175
}
169176
]}')
170177

@@ -174,9 +181,17 @@
174181
expect(result[:costs][0][:currency]).to eq('USD')
175182
expect(result[:costs][0][:unit]).to eq('MONTHLY')
176183

177-
expect(result[:costs][1][:amount]).to eq(600.015454)
184+
expect(result[:costs][1][:amount]).to eq(500.0)
178185
expect(result[:costs][1][:currency]).to eq('GBP')
179186
expect(result[:costs][1][:unit]).to eq('MONTHLY')
187+
188+
expect(result[:costs][2][:amount]).to eq(6.00)
189+
expect(result[:costs][2][:currency]).to eq('USD')
190+
expect(result[:costs][2][:unit]).to eq('daily')
191+
192+
expect(result[:costs][3][:amount]).to eq(5.05)
193+
expect(result[:costs][3][:currency]).to eq('GBP')
194+
expect(result[:costs][3][:unit]).to eq('daily')
180195
end
181196

182197
it 'handles currency symbols' do
@@ -196,6 +211,35 @@
196211
expect(result[:costs][0][:currency]).to eq('$')
197212
expect(result[:costs][0][:unit]).to eq('Daily')
198213
end
214+
215+
it 'skips when currency is empty string' do
216+
service_plan =
217+
VCAP::CloudController::ServicePlan.make(extra: '{"costs": [
218+
{
219+
"amount": {
220+
"gpb": 0.06
221+
},
222+
"unit": "Daily"
223+
},
224+
{
225+
"amount": {
226+
"": 0.06,
227+
"usd": 0.10
228+
},
229+
"unit": "Daily"
230+
}
231+
]}')
232+
233+
result = described_class.new(service_plan).to_hash.deep_symbolize_keys
234+
235+
expect(result[:costs][0][:amount]).to eq(0.06)
236+
expect(result[:costs][0][:currency]).to eq('GPB')
237+
expect(result[:costs][0][:unit]).to eq('Daily')
238+
239+
expect(result[:costs][1][:amount]).to eq(0.10)
240+
expect(result[:costs][1][:currency]).to eq('USD')
241+
expect(result[:costs][1][:unit]).to eq('Daily')
242+
end
199243
end
200244

201245
context 'when plan has no cost' do

0 commit comments

Comments
 (0)