fix(order): update order summary when transactions change (#8633)
This commit is contained in:
committed by
GitHub
parent
0f240137e9
commit
be942ff15c
@@ -40,8 +40,7 @@ medusaIntegrationTestRunner({
|
||||
|
||||
describe("GET /admin/users", () => {
|
||||
it("should list users", async () => {
|
||||
const response = await api
|
||||
.get("/admin/users", adminHeaders)
|
||||
const response = await api.get("/admin/users", adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -91,71 +90,6 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
).data.token
|
||||
})
|
||||
|
||||
// BREAKING: V2 users do not require a role
|
||||
// We should probably remove this endpoint?
|
||||
it("should create a user", async () => {
|
||||
const payload = {
|
||||
email: "test@test123.com",
|
||||
}
|
||||
|
||||
// In V2, the flow to create an authenticated user depends on the token or session of a previously created auth user
|
||||
const headers = {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
}
|
||||
|
||||
const response = await api.post("/admin/users", payload, headers)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.user).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.stringMatching(/^user_*/),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
email: "test@test123.com",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
// V2 only test
|
||||
it("should throw, if session/bearer auth is present for existing user", async () => {
|
||||
const emailPassResponse = await api.post("/auth/user/emailpass", {
|
||||
email: "test@test123.com",
|
||||
password: "test123",
|
||||
})
|
||||
|
||||
const token = emailPassResponse.data.token
|
||||
|
||||
const headers = (token) => ({
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
|
||||
const res = await api.post(
|
||||
"/admin/users",
|
||||
{
|
||||
email: "test@test123.com",
|
||||
},
|
||||
headers(token)
|
||||
)
|
||||
|
||||
const authenticated = await api.post("/auth/user/emailpass", {
|
||||
email: "test@test123.com",
|
||||
password: "test123",
|
||||
})
|
||||
|
||||
const payload = {
|
||||
email: "different@email.com",
|
||||
}
|
||||
|
||||
const errorResponse = await api
|
||||
.post("/admin/users", payload, headers(authenticated.data.token))
|
||||
.catch((err) => err.response)
|
||||
|
||||
expect(errorResponse.status).toEqual(400)
|
||||
expect(errorResponse.data.message).toEqual(
|
||||
"Request carries authentication for an existing user"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/users/:id", () => {
|
||||
|
||||
@@ -208,6 +208,15 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
})
|
||||
const created = await service.createOrders(inpCopy)
|
||||
|
||||
expect(created.summary).toEqual(
|
||||
expect.objectContaining({
|
||||
transaction_total: 68,
|
||||
pending_difference: -20.21999000999001,
|
||||
paid_total: 68,
|
||||
refunded_total: 0,
|
||||
})
|
||||
)
|
||||
|
||||
const refund = await service.addTransactions([
|
||||
{
|
||||
order_id: created.id,
|
||||
@@ -226,6 +235,8 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
|
||||
expect(serializedOrder.summary).toEqual(
|
||||
expect.objectContaining({
|
||||
transaction_total: 48,
|
||||
pending_difference: -0.21999000999001,
|
||||
paid_total: 68,
|
||||
refunded_total: 20,
|
||||
})
|
||||
@@ -243,6 +254,8 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
|
||||
expect(serializedOrder2.summary).toEqual(
|
||||
expect.objectContaining({
|
||||
transaction_total: 68,
|
||||
pending_difference: -20.21999000999001,
|
||||
paid_total: 68,
|
||||
refunded_total: 0,
|
||||
})
|
||||
@@ -268,6 +281,8 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
expect.objectContaining({
|
||||
paid_total: 68,
|
||||
refunded_total: 50,
|
||||
transaction_total: 18,
|
||||
pending_difference: 29.78000999000999,
|
||||
})
|
||||
)
|
||||
|
||||
@@ -285,6 +300,8 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
expect.objectContaining({
|
||||
paid_total: 68,
|
||||
refunded_total: 70,
|
||||
transaction_total: -2,
|
||||
pending_difference: 49.78000999000999,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
@@ -2921,7 +2921,18 @@ export default class OrderModuleService<
|
||||
op(summary.totals.refunded_total, MathBN.abs(trx.amount))
|
||||
)
|
||||
}
|
||||
|
||||
summary.totals.transaction_total = new BigNumber(
|
||||
op(summary.totals.transaction_total, trx.amount)
|
||||
)
|
||||
}
|
||||
|
||||
summary.totals.pending_difference = new BigNumber(
|
||||
MathBN.sub(
|
||||
summary.totals.current_order_total,
|
||||
summary.totals.transaction_total
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
createRawPropertiesFromBigNumber(summaries)
|
||||
|
||||
Reference in New Issue
Block a user