Skip to content

Commit

Permalink
fix: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Nov 20, 2020
1 parent e393561 commit cfa9eef
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

<template v-if="$configBus.get(choice, 'price') !== 0">
<span v-text="$configBus.get(choice, 'price') > 0 ? '+ ' : '– '" />
{{ formatCurrency(choice.price) }}
{{ formatCurrency($configBus.get(choice, 'price')) }}
</template>
</component>
</label>
Expand Down
4 changes: 2 additions & 2 deletions src/delivery-options/data/prices/formatCurrency.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { configBus as realConfigBus } from '@/delivery-options/config/configBus'
* @returns {String}
*/
export function formatCurrency(price, configBus = realConfigBus) {
if (typeof price === 'string') {
price = configBus.get(price, 'price');
if (typeof price !== 'number') {
throw new Error('"price" must be a number.');
}

const formatter = new Intl.NumberFormat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ export function getLowestPriceFromFormConfig(config, carrierName = null, configB
})
.flat();

if (!prices.length) {
throw new Error('"prices" array is empty.');
}

return Math.min(...prices);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ describe('RecursiveForm.vue', () => {
expect(formatCurrency(0)).toBe('€ 0,00');
expect(formatCurrency(100)).toBe('€ 100,00');
expect(formatCurrency(24.50)).toBe('€ 24,50');
expect(formatCurrency(20000)).toBe('€ 20.000,00');
});
});

0 comments on commit cfa9eef

Please sign in to comment.