This repository was archived by the owner on Jun 2, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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
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,
300277 {
301278 "amount": {},
302279 "unit": "Daily"
280+ },
281+ {
282+ "amount": {
283+ "usd": 649.0
284+ },
285+ "unit": "Daily"
303286 }
304287 ]
305288 }'
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
You can’t perform that action at this time.
0 commit comments