fix: adds tests for segment

This commit is contained in:
Sebastian Rindom
2021-03-23 11:12:11 +01:00
parent c6a5dffa7b
commit 1b00f967de
2 changed files with 197 additions and 5 deletions
@@ -44,7 +44,7 @@ class SegmentService extends BaseService {
"EUR"
if (fromCurrency === toCurrency) {
return this.totalsService_.rounded(value)
return this.rounded_(value)
}
const exchangeRate = await axios
@@ -55,9 +55,7 @@ class SegmentService extends BaseService {
return data.rates[fromCurrency]
})
// Two decimal places
const num = value / exchangeRate
return Number(Math.round(num + "e2") + "e-2")
return this.rounded_(value / exchangeRate)
}
async buildOrder(order) {
@@ -146,7 +144,9 @@ class SegmentService extends BaseService {
return {
name,
variant,
price: humanizeAmount(lineTotal, curr) / item.quantity,
price: this.rounded_(
humanizeAmount(lineTotal, curr) / item.quantity
),
reporting_revenue: revenue,
product_id: item.variant.product_id,
category: product.collection?.title,
@@ -161,6 +161,10 @@ class SegmentService extends BaseService {
return orderData
}
rounded_(v) {
return Number(Math.round(v + "e2") + "e-2")
}
}
export default SegmentService