fix: account for non-division currencies in sales credit (#342)
This commit is contained in:
1 parent
d9d84e1353
commit
bd1e115696
4 files changed
+78
-2
No files matched your search
@@ -27,6 +27,7 @@
|
|||||||
"cross-env": "^7.0.2",
|
"cross-env": "^7.0.2",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"jest": "^25.5.2",
|
"jest": "^25.5.2",
|
||||||
|
"medusa-interfaces": "^1.1.21",
|
||||||
"medusa-test-utils": "^1.1.23",
|
"medusa-test-utils": "^1.1.23",
|
||||||
"prettier": "^2.0.5"
|
"prettier": "^2.0.5"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
jest.unmock("axios")
|
jest.unmock("axios")
|
||||||
|
|
||||||
import BrightpearlService from "../brightpearl"
|
import BrightpearlService from "../brightpearl"
|
||||||
import { mockCreateOrder } from "../../utils/brightpearl"
|
import { mockCreateOrder, mockCreateCredit } from "../../utils/brightpearl"
|
||||||
import MockAdapter from "axios-mock-adapter"
|
import MockAdapter from "axios-mock-adapter"
|
||||||
|
|
||||||
jest.mock("../../utils/brightpearl")
|
jest.mock("../../utils/brightpearl")
|
||||||
@@ -47,6 +47,47 @@ const order = {
|
|||||||
email: "test@example.com",
|
email: "test@example.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const krwOrder = {
|
||||||
|
region: {
|
||||||
|
tax_code: "1234",
|
||||||
|
},
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
title: "Test",
|
||||||
|
variant: {
|
||||||
|
sku: "TEST",
|
||||||
|
},
|
||||||
|
unit_price: 1100,
|
||||||
|
quantity: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
shipping_total: 12399,
|
||||||
|
shipping_methods: [
|
||||||
|
{
|
||||||
|
name: "standard",
|
||||||
|
price: 12399,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
payment_method: {
|
||||||
|
id: "123",
|
||||||
|
},
|
||||||
|
tax_rate: 0,
|
||||||
|
currency_code: "KRW",
|
||||||
|
display_id: "1234",
|
||||||
|
id: "12355",
|
||||||
|
discounts: [],
|
||||||
|
shipping_address: {
|
||||||
|
first_name: "Test",
|
||||||
|
last_name: "Testson",
|
||||||
|
address_1: "Test",
|
||||||
|
address_2: "TEst",
|
||||||
|
postal_code: "1234",
|
||||||
|
country_code: "DK",
|
||||||
|
phone: "12345678",
|
||||||
|
},
|
||||||
|
email: "test@example.com",
|
||||||
|
}
|
||||||
|
|
||||||
const roundingOrder = {
|
const roundingOrder = {
|
||||||
region: {
|
region: {
|
||||||
tax_code: "1234",
|
tax_code: "1234",
|
||||||
@@ -398,4 +439,32 @@ describe("BrightpearlService", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("bpnum_", () => {
|
||||||
|
const bpService = new BrightpearlService(
|
||||||
|
{
|
||||||
|
orderService: OrderService,
|
||||||
|
totalsService: TotalsService,
|
||||||
|
oauthService: OAuthService,
|
||||||
|
regionService: RegionService,
|
||||||
|
},
|
||||||
|
{ account: "test" }
|
||||||
|
)
|
||||||
|
|
||||||
|
it("sales credit diff. calc - KRW", async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
const total = 100000
|
||||||
|
const refund_amount = 100000
|
||||||
|
const difference = bpService.bpnum_(refund_amount, "krw") - total
|
||||||
|
expect(difference).toEqual(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("sales credit diff. calc - DKK", async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
const total = 100000
|
||||||
|
const refund_amount = 100000
|
||||||
|
const difference = bpService.bpnum_(refund_amount, "dkk") - total
|
||||||
|
expect(difference).toEqual(-99000)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
@@ -414,7 +414,8 @@ class BrightpearlService extends BaseService {
|
|||||||
return acc + next.net + next.tax
|
return acc + next.net + next.tax
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
const difference = (fromReturn.refund_amount / 100 - total) * 100
|
const difference =
|
||||||
|
this.bpnum_(fromReturn.refund_amount, fromOrder.currency_code) - total
|
||||||
if (difference) {
|
if (difference) {
|
||||||
order.rows.push({
|
order.rows.push({
|
||||||
name: "Difference",
|
name: "Difference",
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ export const mockCreateOrder = jest
|
|||||||
.fn()
|
.fn()
|
||||||
.mockReturnValue(Promise.resolve("1234"))
|
.mockReturnValue(Promise.resolve("1234"))
|
||||||
|
|
||||||
|
export const mockCreateCredit = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue(Promise.resolve("1234"))
|
||||||
|
|
||||||
const mock = jest.fn().mockImplementation(function (options) {
|
const mock = jest.fn().mockImplementation(function (options) {
|
||||||
this.tokenStore_ = options.token_store
|
this.tokenStore_ = options.token_store
|
||||||
this.token_ = options.access_token
|
this.token_ = options.access_token
|
||||||
@@ -65,6 +69,7 @@ const mock = jest.fn().mockImplementation(function (options) {
|
|||||||
}
|
}
|
||||||
this.orders = {
|
this.orders = {
|
||||||
create: mockCreateOrder,
|
create: mockCreateOrder,
|
||||||
|
createCredit: mockCreateCredit,
|
||||||
retrieve: jest.fn().mockReturnValue(Promise.resolve()),
|
retrieve: jest.fn().mockReturnValue(Promise.resolve()),
|
||||||
}
|
}
|
||||||
this.products = {
|
this.products = {
|
||||||
|
|||||||
Reference in new issue
Block a user