Handle null/undefined cases for price

This commit is contained in:
Jean-Baptiste Bellet
2021-06-01 11:40:02 +02:00
parent 7f9179193e
commit f73e5c74fb
2 changed files with 9 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
angular.module("admin.utils").filter "unlocalizeCurrency", ()->
# Convert string to number using injected currency configuration.
(price) ->
if (!price)
return null
# used decimal and thousands separators from currency configuration
decimal_separator = I18n.toCurrency(.1, {precision: 1, unit: ''}).substring(1,2)
thousands_separator = I18n.toCurrency(1000, {precision: 1, unit: ''}).substring(1,2)

View File

@@ -89,3 +89,10 @@ describe 'convert string to number with configurated currency', ->
it "handle integer number with no thousands separator", ->
expect(filter("1000")).toEqual 1000
describe "handle null/undefined case", ->
it "null case", ->
expect(filter(null)).toEqual null
it "undefined case ", ->
expect(filter(undefined)).toEqual null