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

Commit a94a075

Browse files
committed
v3 - updated service plan cost
[#172146647](https://www.pivotaltracker.com/story/show/172146647)
1 parent 2d5d621 commit a94a075

2 files changed

Lines changed: 39 additions & 36 deletions

File tree

app/presenters/v3/service_plan_presenter.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ def costs
6363
metadata[:costs].each do |cost|
6464
unit = cost[:unit].to_s
6565
cost[:amount].each do |currency, amount|
66-
unless currency.empty?
67-
cost_result << {
68-
currency: currency.to_s.upcase,
69-
amount: amount.to_f,
70-
unit: unit
71-
}
72-
end
66+
return [] if currency.empty?
67+
68+
cost_result << {
69+
currency: currency.to_s.upcase,
70+
amount: amount.to_f,
71+
unit: unit
72+
}
7373
end
7474
end
7575
end
@@ -142,6 +142,7 @@ def costs_schema
142142
'properties' => {
143143
'amount' => {
144144
'type' => 'object',
145+
'minProperties' => 1,
145146
'additionalProperties' => {
146147
'type' => 'number'
147148
}

spec/unit/presenters/v3/service_plan_presenter_spec.rb

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -211,35 +211,6 @@
211211
expect(result[:costs][0][:currency]).to eq('$')
212212
expect(result[:costs][0][:unit]).to eq('Daily')
213213
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
243214
end
244215

245216
context 'when plan has no cost' do
@@ -285,6 +256,12 @@
285256
['unit is missing',
286257
'{
287258
"costs": [
259+
{
260+
"amount": {
261+
"usd": 649.0
262+
},
263+
"unit": "Daily"
264+
},
288265
{
289266
"amount": {
290267
"usd": 649.0,
@@ -300,6 +277,12 @@
300277
{
301278
"amount": {},
302279
"unit": "Daily"
280+
},
281+
{
282+
"amount": {
283+
"usd": 649.0
284+
},
285+
"unit": "Daily"
303286
}
304287
]
305288
}'
@@ -315,6 +298,25 @@
315298
}
316299
]
317300
}'
301+
],
302+
['currency is empty string',
303+
'{
304+
"costs": [
305+
{
306+
"amount": {
307+
"gpb": 0.06
308+
},
309+
"unit": "Daily"
310+
},
311+
{
312+
"amount": {
313+
"": 0.06,
314+
"usd": 0.10
315+
},
316+
"unit": "Daily"
317+
}
318+
]
319+
}'
318320
]
319321
].each do |scenario, extra|
320322
it "returns empty cost array when #{scenario}" do

0 commit comments

Comments
 (0)